# vim:set ft=sh: git clone -b 1.0 --depth=1 --recursive https://github.com/fosslinux/live-bootstrap cd live-bootstrap ./rootfs.py -c --external-sources --cores $(nproc) umount target/dev/shm # double mounted? umount target/dev/shm target/sys target/proc target/tmp # Optional: back up the system env -i chroot target tar --exclude='/external' --sort=name -cf /target.tar / env -i chroot target bzip2 -9v /target.tar # Goal: # install cross compiler in /cross # cross compiled system in /gentoo cd target mount -t proc proc proc mount -t sysfs sysfs sys mount -t devtmpfs devtmpfs dev mount -t devpts devpts dev/pts env -i TERM="$TERM" chroot . source /steps/env cd /tmp cat > portage.patch << 'EOF' +++ b/lib/portage/util/compression_probe.py @@ -1,13 +1,13 @@ # Copyright 2015-2020 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 -import ctypes import errno import re from portage import _encodings, _unicode_encode from portage.exception import FileNotFound, PermissionDenied +from portage.util._ctypes import ctypes _compressors = { "bzip2": { @@ -49,7 +49,7 @@ _compressors = { # if the current architecture can support it, which is true when # sizeof(long) is at least 8 bytes. "decompress": "zstd -d" - + (" --long=31" if ctypes.sizeof(ctypes.c_long) >= 8 else ""), + + (" --long=31" if ctypes and ctypes.sizeof(ctypes.c_long) >= 8 else ""), "package": "app-arch/zstd", }, } EOF curl -LO http://gitweb.gentoo.org/proj/portage.git/snapshot/portage-3.0.65.tar.bz2 curl -LO https://github.com/plougher/squashfs-tools/archive/refs/tags/4.6.1/squashfs-tools-4.6.1.tar.gz curl -LO http://distfiles.gentoo.org/snapshots/squashfs/gentoo-20240801.xz.sqfs tar xf squashfs-tools-4.6.1.tar.gz cd squashfs-tools-4.6.1 make -C squashfs-tools install \ INSTALL_PREFIX=/usr \ XZ_SUPPORT=1 cd .. rm -rf squashfs-tools-4.6.1 unsquashfs gentoo-20240801.xz.sqfs mkdir -p /var/db/repos rm -rf /var/db/repos/gentoo mv squashfs-root /var/db/repos/gentoo tar xf portage-3.0.65.tar.bz2 ln -sf portage-3.0.65 portage # Configure portage echo 'portage:x:250:250:portage:/var/tmp/portage:/bin/false' >> /etc/passwd echo 'portage::250:portage' >> /etc/group mkdir -p /etc/portage/make.profile cat > /etc/portage/make.profile/make.defaults << 'EOF' FEATURES="-news -sandbox -usersandbox -pid-sandbox -parallel-fetch" BINPKG_COMPRESS="bzip2" ARCH="x86" ABI="$ARCH" DEFAULT_ABI="$ARCH" ACCEPT_KEYWORDS="$ARCH" CHOST="i386-unknown-linux-musl" LIBDIR_x86="lib/i386-unknown-linux-musl" PKG_CONFIG_PATH="/usr/lib/i386-unknown-linux-musl/pkgconfig" IUSE_IMPLICIT="kernel_linux elibc_glibc elibc_musl prefix prefix-guest" USE="kernel_linux elibc_musl python_targets_python3_12" EOF cat > /etc/portage/package.use << 'EOF' dev-lang/python -readline -ncurses EOF # Install dependencies to make emerge work nicely FETCHCOMMAND='curl -o "${DISTDIR}/${FILE}" -L "${URI}"' FETCHCOMMAND="$FETCHCOMMAND" MAKEOPTS=-j1 ./portage/bin/emerge -O1 app-arch/lzip FETCHCOMMAND="$FETCHCOMMAND" MAKEOPTS=-j1 ./portage/bin/emerge -O1 dev-build/make FETCHCOMMAND="$FETCHCOMMAND" ./portage/bin/emerge -O1 net-misc/wget # Upgrade python so we can use it to cross-compile later on ./portage/bin/emerge -O1 dev-build/autoconf ./portage/bin/emerge -O1 dev-build/autoconf-wrapper ./portage/bin/emerge -O1 dev-build/automake ./portage/bin/emerge -O1 dev-build/automake-wrapper ./portage/bin/emerge -O1 sys-apps/gentoo-functions ./portage/bin/emerge -O1 app-portage/elt-patches ./portage/bin/emerge -O1 dev-libs/mpdecimal ./portage/bin/emerge -O1 dev-libs/expat mv /bin/bzip2 /bin/bzip2-reference ln -s bzip2-reference /bin/bzip2 ./portage/bin/emerge -O1 app-arch/bzip2 ./portage/bin/emerge -O1 dev-lang/python ./portage/bin/emerge -O1 dev-lang/python-exec # Install the rest of the dependencies for meson ./portage/bin/emerge -O1 dev-python/gpep517 ./portage/bin/emerge -O1 app-arch/unzip ./portage/bin/emerge -O1 dev-python/installer ./portage/bin/emerge -O1 dev-python/flit-core ./portage/bin/emerge -O1 dev-python/packaging ./portage/bin/emerge -O1 dev-python/more-itertools ./portage/bin/emerge -O1 dev-python/ordered-set ./portage/bin/emerge -O1 dev-python/jaraco-text ./portage/bin/emerge -O1 dev-python/jaraco-functools ./portage/bin/emerge -O1 dev-python/jaraco-context ./portage/bin/emerge -O1 dev-python/wheel ./portage/bin/emerge -O1 dev-python/setuptools ./portage/bin/emerge -O1 dev-build/meson ./portage/bin/emerge -O1 dev-build/ninja # Finally install portage itself ./portage/bin/emerge -O1 sys-apps/portage # Install pax-utils to allow stripping binaries emerge -O1 dev-build/meson-format-array emerge -O1 app-misc/pax-utils # Fix "find" warnings in emerge emerge -O1 sys-apps/findutils # Install additional BDEPENDs emerge -O1 sys-devel/binutils-config # sys-devel/binutils emerge -O1 sys-devel/gcc-config # sys-devel/gcc emerge -O1 net-misc/rsync # sys-kernel/linux-headers emerge -O1 dev-util/pkgconf # dev-lang/python requires --keep-system-libs option when cross compiling # Add cross compiler to PATH cat > /etc/env.d/50baselayout << 'EOF' PATH=/cross/usr/bin:/usr/bin EOF env-update # Set up cross compiler mkdir -p /cross/etc/portage ln -sf /etc/portage/make.profile /cross/etc/portage/make.profile cat > /cross/etc/portage/make.conf << 'EOF' USE="prefix multilib" CTARGET="x86_64-bootstrap-linux-gnu" LIBDIR_x86="lib" LIBDIR_amd64="lib64" DEFAULT_ABI="amd64" MULTILIB_ABIS="amd64 x86" EOF cat > /cross/etc/portage/package.use << 'EOF' sys-devel/gcc -sanitize -fortran EOF mkdir -p /cross/etc/portage/env/sys-devel cat > /cross/etc/portage/env/sys-devel/gcc << 'EOF' EXTRA_ECONF='--with-sysroot=$EPREFIX/usr/$CTARGET' EOF # TODO: Build sys-libs/glibc in /gentoo instead, to avoid extra rebuilding PORTAGE_CONFIGROOT=/cross EPREFIX=/cross emerge -O1 sys-devel/binutils PORTAGE_CONFIGROOT=/cross EPREFIX=/cross USE='headers-only' emerge -O1 sys-kernel/linux-headers PORTAGE_CONFIGROOT=/cross EPREFIX=/cross USE='headers-only -multilib' emerge -O1 sys-libs/glibc PORTAGE_CONFIGROOT=/cross EPREFIX=/cross USE='-cxx -openmp' emerge -O1 sys-devel/gcc PORTAGE_CONFIGROOT=/cross EPREFIX=/cross emerge -O1 sys-kernel/linux-headers PORTAGE_CONFIGROOT=/cross EPREFIX=/cross emerge -O1 sys-libs/glibc PORTAGE_CONFIGROOT=/cross EPREFIX=/cross emerge -O1 sys-devel/gcc # Reconfigure cross toolchain for final system cat > /cross/usr/lib/gcc/x86_64-bootstrap-linux-gnu/specs << 'EOF' *link: + %{!shared:%{!static:%{!static-pie:-dynamic-linker %{m32:/lib/ld-linux.so.2;:/lib64/ld-linux-x86-64.so.2}}}} EOF for tool in gcc g++; do rm -f /cross/usr/bin/x86_64-bootstrap-linux-gnu-$tool cat > /cross/usr/bin/x86_64-bootstrap-linux-gnu-$tool << EOF #!/bin/sh exec /cross/usr/i386-unknown-linux-musl/x86_64-bootstrap-linux-gnu/gcc-bin/*/x86_64-bootstrap-linux-gnu-$tool --sysroot=/gentoo "\$@" EOF chmod +x /cross/usr/bin/x86_64-bootstrap-linux-gnu-$tool done cat > /cross/usr/bin/x86_64-bootstrap-linux-gnu-pkg-config << 'EOF' #!/bin/sh export PKG_CONFIG_SYSROOT_DIR=/gentoo export PKG_CONFIG_LIBDIR=/gentoo/usr/lib64/pkgconfig export PKG_CONFIG_PATH=/gentoo/usr/share/pkgconfig export PKG_CONFIG_SYSTEM_INCLUDE_PATH=/gentoo/usr/include export PKG_CONFIG_SYSTEM_LIBRARY_PATH=/gentoo/lib64:/gentoo/usr/lib64 exec pkg-config "$@" EOF chmod +x /cross/usr/bin/x86_64-bootstrap-linux-gnu-pkg-config # Compile final system (hopefully) mkdir -p /gentoo.cfg/etc/portage ln -sf ../../../var/db/repos/gentoo/profiles/default/linux/amd64/23.0 /gentoo.cfg/etc/portage/make.profile cat > /gentoo.cfg/etc/portage/make.conf << 'EOF' FEATURES="-news -sandbox -usersandbox -pid-sandbox -parallel-fetch" BINPKG_COMPRESS="bzip2" CBUILD="i386-unknown-linux-musl" CHOST="x86_64-bootstrap-linux-gnu" CFLAGS_x86="$CFLAGS_x86 -msse" # bug 937637 USE="-* build openmp python_targets_python3_12" CONFIG_SITE="$PORTAGE_CONFIGROOT/etc/portage/config.site" EOF cat > /gentoo.cfg/etc/portage/config.site << 'EOF' if [ "${CBUILD:-${CHOST}}" != "${CHOST}" ]; then # Settings grabbed from crossdev ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no fi EOF PORTAGE_CONFIGROOT=/gentoo.cfg ROOT=/gentoo SYSROOT=/gentoo emerge -O1n \ sys-apps/baselayout \ sys-kernel/linux-headers \ sys-libs/glibc \ sys-libs/zlib \ sys-devel/binutils \ dev-libs/gmp \ dev-libs/mpfr \ dev-libs/mpc \ sys-devel/gcc \ \ app-arch/bzip2 \ app-arch/xz-utils \ dev-libs/expat \ dev-libs/libffi \ dev-libs/mpdecimal \ sys-apps/util-linux \ sys-libs/libxcrypt \ dev-lang/python:3.12 \ \ dev-lang/python-exec \ sys-apps/portage \ \ sys-libs/ncurses \ sys-libs/readline \ app-shells/bash \ \ sys-apps/coreutils \ sys-apps/findutils \ sys-apps/sed \ sys-apps/grep \ sys-apps/gawk \ sys-devel/patch \ app-arch/tar \ app-arch/gzip \ dev-build/make # TODO: Un-hardcode python 3.12 # TODO: Avoid gzip? # Set up final system mkdir -p /gentoo/etc/portage ln -sf ../../var/db/repos/gentoo/profiles/default/linux/amd64/23.0 /gentoo/etc/portage/make.profile rsync -aP /var/db/repos/ /gentoo/var/db/repos echo 'nameserver 1.1.1.1' > /gentoo/etc/resolv.conf echo 'C.UTF8 UTF-8' > /gentoo/etc/locale.gen # Fetch some extra source code DISTDIR=/gentoo/var/cache/distfiles \ PORTAGE_CONFIGROOT=/gentoo ROOT=/gentoo SYSROOT=/gentoo emerge -O1f \ dev-util/pkgconf \ dev-lang/perl \ dev-libs/openssl \ net-misc/wget \ app-misc/ca-certificates # From here you just chroot into /gentoo, clean /etc/portage (leaving only make.profile), install wget, and run "emerge -DN @world", untangling dependencies until it works # This is an example: # TODO: Avoid weird gcc rebuild... # This part can be improved a lot by cross-compiling more stuff emerge -O1 dev-util/pkgconf USE=-gdbm emerge -O1 dev-lang/perl emerge -O1 dev-libs/openssl MAKEINFO=true emerge -O1 net-misc/wget emerge -O1 app-misc/ca-certificates emerge -O1 dev-build/ninja emerge -O1 app-alternatives/ninja emerge -O1 sys-apps/gentoo-functions emerge -O1 app-portage/elt-patches emerge -O1 sys-devel/m4 MAKEINFO=true emerge -O1 sys-devel/flex emerge -O1 sys-apps/diffutils emerge -O1 sys-devel/gcc-config USE='-* openmp' EXTRA_ECONF=--disable-bootstrap emerge -O1 sys-devel/gcc emerge -O1 dev-build/ninja # avoid segfault emerge -O1 sys-devel/bison USE='-* cet' emerge -O1 sys-libs/glibc emerge -O1 app-alternatives/yacc emerge -O1 app-alternatives/lex rm -f /var/run/bootstrap-progress && USE=-nls /var/db/repos/gentoo/scripts/bootstrap.sh USE='-* openmp' EXTRA_ECONF=--disable-bootstrap emerge -O1 sys-devel/gcc # enable openmp again... USE='-nls -pam -su -http2' emerge -1 net-misc/rsync USE='-nls -pam -su -http2' emerge -e @system emerge -DN @system emerge -c