You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
183 lines
7.0 KiB
183 lines
7.0 KiB
4 years ago
|
Based on portage-3.0.8 and gentoo-20201029
|
||
|
|
||
|
The specifics of this document (software versions and whatnot) are subject to
|
||
|
change as gentoo evolves, but I hope the big lines of it won't change too
|
||
|
much.
|
||
|
|
||
|
This guide starts off with a system built from build_cross.sh, built for
|
||
|
x86_64 with i686 multilib.
|
||
|
It might be possible to adapt both that script, and this guide for other
|
||
|
architectures, but this guide won't go into detail.
|
||
|
|
||
|
You should be running a system with a x86_64 kernel (with i686 support).
|
||
|
Install the required sources (outlined in gentoo.wget-list) into /sources.
|
||
|
|
||
|
To enter the bootstrap system as a chroot, use the following commands to set
|
||
|
up the filesystems and entering:
|
||
|
mkdir -p proc sys dev tmp
|
||
|
mount -t proc proc proc
|
||
|
mount -t sysfs sysfs sys
|
||
|
mount -t devtmpfs devtmpfs dev
|
||
|
mount -t devpts devpts dev/pts
|
||
|
mount -t tmpfs tmpfs dev/shm
|
||
|
mkdir -p etc
|
||
|
touch etc/resolv.conf
|
||
|
mount --bind /etc/resolv.conf etc/resolv.conf
|
||
|
./bootstrap/bin/chroot . /bootstrap/bin/env -i PATH=/bin:/sbin:/usr/bin:/usr/sbin:/bootstrap/bin:/bootstrap/sbin HOME=/root /bootstrap/bin/sh -l
|
||
|
|
||
|
To install all the prerequisite tools, place the sources (listed in
|
||
|
gentoo.wget-list) under /sources, then run the gentoo_tools.sh script.
|
||
|
|
||
|
Install ebuild repository:
|
||
|
tar xf gentoo-*.tar.xz
|
||
|
mkdir -p /var/db/repos/
|
||
|
mv gentoo-*/ /var/db/repos/gentoo
|
||
|
|
||
|
Configure portage:
|
||
|
echo "root:x:0:0:root:/root:/bin/bash" > /etc/passwd
|
||
|
echo "root:x:0:root" > /etc/group
|
||
|
echo "portage:x:250:250:portage:/var/tmp/portage:/bin/false" >> /etc/passwd
|
||
|
echo "portage::250:portage" >> /etc/group
|
||
|
mkdir -p /tmp /root
|
||
|
chown root.root /tmp /root
|
||
|
chmod 1777 /tmp
|
||
|
chmod 0700 /root
|
||
|
ln -sf ../../var/db/repos/gentoo/profiles/default/linux/amd64/17.1/ /etc/portage/make.profile
|
||
|
cat > /etc/portage/make.conf << 'EOF'
|
||
|
FEATURES=-pid-sandbox
|
||
|
ROOTPATH=/bootstrap/bin:/bootstrap/sbin
|
||
|
EOF
|
||
|
|
||
|
Install some prerequisites:
|
||
|
emerge -O1 sys-apps/gentoo-functions # Used by elt-patches and a ton of other things
|
||
|
emerge -O1 app-portage/elt-patches # required by elibtoolize(libtool.eclass), used to install any library
|
||
|
|
||
|
TODO: Doing this is *BAAAAD*, since we're linking the compiler and libraries
|
||
|
with a potentially incompatible version of glibc in /tools, and upgrading it
|
||
|
afterwards. Glibc should always be installed first into a new prefix!
|
||
|
I just can't be assed to discuss the manual upgrade of binutils+gcc and their
|
||
|
dependency tools.
|
||
|
|
||
|
TODO: Consider installing sys-devel/gnuconfig for the config.sub and
|
||
|
config.guess scripts.
|
||
|
|
||
|
Bootstrap GCC:
|
||
|
# Install linker at final location,
|
||
|
# so programs built with the new compiler can run...
|
||
|
mkdir -p /lib64 /lib
|
||
|
ln -sf /bootstrap/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
|
||
|
ln -sf /bootstrap/lib32/ld-linux.so.2 /lib/ld-linux.so.2
|
||
|
# Target compiler expects target limits.h to be available in target prefix...
|
||
|
mkdir -p /usr/include
|
||
|
ln -sf /bootstrap/include/limits.h /usr/include/limits.h
|
||
|
# GCC errors out at the first incompatible startfile in LIBRARY_PATH,
|
||
|
# so multilib paths need to be fixed to match the final compiler...
|
||
|
mkdir -p /usr/lib64 /usr/lib
|
||
|
ln -sf /bootstrap/lib/crti.o /bootstrap/lib/crtn.o /bootstrap/lib/Scrt1.o /usr/lib64/
|
||
|
ln -sf /bootstrap/lib32/crti.o /bootstrap/lib32/crtn.o /bootstrap/lib32/Scrt1.o /usr/lib/
|
||
|
# Reconfigure GCC to match the config of the final compiler as much as possible.
|
||
|
cat > /etc/portage/gcc.specs << 'EOF'
|
||
|
*multilib:
|
||
|
. !m64 !m32;64:../lib64 m64 !m32;32:../lib !m64 m32;
|
||
|
|
||
|
*startfile_prefix_spec:
|
||
|
/usr/lib/
|
||
|
|
||
|
*link:
|
||
|
+ %{!shared:%{!static:-dynamic-linker %{m32:/lib/ld-linux.so.2;:/lib64/ld-linux-x86-64.so.2}}}
|
||
|
|
||
|
*cpp:
|
||
|
+ -isystem /usr/include
|
||
|
EOF
|
||
|
cat > /etc/portage/bashrc << 'EOF'
|
||
|
export C_INCLUDE_PATH=/usr/include:/bootstrap/include
|
||
|
export CPLUS_INCLUDE_PATH=/usr/include:/bootstrap/include
|
||
|
export LIBRARY_PATH=/usr/lib64:/usr/lib:/bootstrap/lib:/bootstrap/lib32
|
||
|
export LD_LIBRARY_PATH=/usr/lib64:/usr/lib:/bootstrap/lib:/bootstrap/lib32
|
||
|
export CC='gcc -specs=/etc/portage/gcc.specs'
|
||
|
export CXX='g++ -specs=/etc/portage/gcc.specs'
|
||
|
EOF
|
||
|
emerge -O1 sys-libs/zlib dev-libs/gmp dev-libs/mpfr dev-libs/mpc
|
||
|
emerge -O1 sys-devel/binutils-config sys-devel/binutils
|
||
|
emerge -O1 sys-devel/gcc-config sys-devel/gcc
|
||
|
/usr/bin/gcc-config 1 # Not automatic unlike binutils-config
|
||
|
|
||
|
Make portage forget about everything it's just installed, so it's all rebuilt
|
||
|
first thing when running bootstrap.sh/emerge later:
|
||
|
rm -rf /var/db/pkg
|
||
|
|
||
|
Install initial glibc:
|
||
|
CC=gcc emerge -O1 sys-kernel/linux-headers
|
||
|
mkdir -p /usr/bin/
|
||
|
ln -sf /bootstrap/bin/python3 /usr/bin/python3tmp
|
||
|
PYTHON_COMPAT_OVERRIDE=python3tmp emerge -O1 sys-libs/glibc
|
||
|
rm -f /usr/bin/python3tmp
|
||
|
|
||
|
This compiler and dynamic linker will now pick up everything correctly under
|
||
|
/usr instead of /bootstrap:
|
||
|
rm -f /etc/portage/bashrc /etc/portage/gcc.specs
|
||
|
|
||
|
Build the remainder of bootstrap utilities:
|
||
|
cd /var/db/repos/gentoo/scripts
|
||
|
rm -f /etc/profile.env
|
||
|
mkdir -p /var/run
|
||
|
USE=-nls ./bootstrap.sh
|
||
|
|
||
|
You'll get tons of LD_PRELOAD libsandbox.so errors from programs still linked
|
||
|
against /bootstrap. This is fine to ignore, and will gradually disappear as
|
||
|
programs are rebuilt.
|
||
|
|
||
|
It'd be nice to remove the bootstrap tools now, but among wget/openssl, gawk,
|
||
|
gzip, grep, and other tools, they're still required for some reason.
|
||
|
|
||
|
From this point onward, you're pretty much on your own to beat portage into
|
||
|
performing an `emerge -e @system` and fixing any unspecified dependencies you
|
||
|
encounter along the way. This can be done in a whole number of ways, and will
|
||
|
differ on any given day, since this is painfully unsupported by gentoo devs.
|
||
|
Because the order in which you install everything can differ wildly, and
|
||
|
consequently affect the output of your build, it is advised to do a second
|
||
|
`emerge -e @system` afterwards, for sanity. Below I detail my most recent
|
||
|
procedure, which, I can't stress enough, may or may not work at the time
|
||
|
you're reading this.
|
||
|
|
||
|
Fix circular dependencies:
|
||
|
USE=-filecaps emerge -O1 sys-libs/pam
|
||
|
USE='-acl -xattr' emerge -O1 sys-apps/shadow # required by acct-group/acct-user
|
||
|
|
||
|
Verify there's no circular deps left, for sanity:
|
||
|
emerge -fe @system
|
||
|
|
||
|
Build everything:
|
||
|
emerge -be @system
|
||
|
|
||
|
Clean up bootstrap tools/configs:
|
||
|
rm -rf /bootstrap /sources
|
||
|
rm -f /etc/portage/make.conf
|
||
|
|
||
|
Reinitialize environment:
|
||
|
env-update
|
||
|
exec bash -l
|
||
|
|
||
|
Consider rebuilding everything again without /bootstrap, as surely a lot
|
||
|
errors popped up during the first emerge -be @system, can't be sure enough.
|
||
|
|
||
|
To install everything into a clean root:
|
||
|
ROOT=/final emerge -K @system
|
||
|
|
||
|
Prepare files for catalyst:
|
||
|
mkdir -p /var/tmp/catalyst/snapshots
|
||
|
wget -O gentoo-latest.tar.xz http://distfiles.gentoo.org/snapshots/gentoo-latest.tar.xz
|
||
|
mkdir -p /var/tmp/catalyst/builds/default
|
||
|
cd /var/tmp/catalyst/builds/default
|
||
|
tar -C /final -cf stage3-amd64-latest.tar .
|
||
|
xz -9v stage3-amd64-latest.tar
|
||
|
rm -rf /final
|
||
|
wget -O stage1.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage1.spec"
|
||
|
wget -O stage2.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage2.spec"
|
||
|
wget -O stage3.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage3.spec"
|
||
|
sed -i -e 's/@TIMESTAMP@/latest/' -e '/^portage_confdir: /d' *.spec
|
||
|
|
||
|
Build the stage3:
|
||
|
emerge catalyst
|
||
|
catalyst -f stage1.spec
|