******************************************************************************** *** BUILD SCRIPT FOR RASPBERRY PI 64-BIT LINUX GENTOO (full) *** *** Allan's Workshop *** *** https://www.drassal.net/wp/raspberry-pi-64-bit-linux-gentoo-install *** *** Revised 2025-01-30 *** *** *** *** Based on the (no longer maintained) GenPi64 project by Sakaki at *** *** https://github.com/sakaki-/gentoo-on-rpi-64bit *** *** and the now continuation of the GenPi64 project at *** *** https://github.com/GenPi64/gentoo-on-rpi-64bit *** ******************************************************************************** *** set sdcard device SDCARD=/dev/sdc *** create working directory mkdir -p /var/datadisk/raspberrypi_gentoo_rpi64/build_attempt_20250129_remote *** change to working directory cd /var/datadisk/raspberrypi_gentoo_rpi64/build_attempt_20250129_remote *** download stage3 tarball wget https://dev.drassal.net/genpi64/stage3-arm64-openrc-splitusr-20250112T234833Z.tar.xz wget https://dev.drassal.net/genpi64/stage3-arm64-openrc-splitusr-20250112T234833Z.tar.xz.DIGESTS *** original file https://distfiles.gentoo.org/releases/arm64/autobuilds *** check sha512 hash *** the output of the two below lines *should* match sha512sum "stage3-arm64-openrc-splitusr-20250112T234833Z.tar.xz" | cut -f 1 -d' ' sed -n '/SHA512 HASH/{n;p;}' "stage3-arm64-openrc-splitusr-20250112T234833Z.tar.xz.DIGESTS" | grep "stage3-arm64-openrc-splitusr-20250112T234833Z.tar.xz"'$' | tail -n 1 | cut -f 1 -d' ' *** download bootfs tarball *** original https://github.com/raspberrypi/firmware wget https://dev.drassal.net/genpi64/bootfs_20250128.tar.bz2 *** download kernel modules *** original https://github.com/raspberrypi/linux wget https://dev.drassal.net/genpi64/rootfs_modules_20250128.tar.bz2 *** download firmware-nonfree *** original https://github.com/RPi-Distro/firmware-nonfree.git wget https://dev.drassal.net/genpi64/rootfs_firmware-nonfree_20250128.tar.bz2 *** download firmware-bluez *** original https://github.com/RPi-Distro/bluez-firmware.git wget https://dev.drassal.net/genpi64/rootfs_firmware-bluez_20250128.tar.bz2 *** downlaod kernel sources *** original https://github.com/raspberrypi/linux wget https://dev.drassal.net/genpi64/linux-6.6.74-raspberrypi_20250128.tar.bz2 *** downlaod binary packages (optional) *** provided if needed but normally necessary packages will be automatically *** downloaded during emerge *** WARNING, VERY BIG DOWNLOAD 2.3G !!! wget https://dev.drassal.net/genpi64/binpkgs_202501210142.tar.bz2 *** downlaod sources (optional) *** WARNING, VERY BIG DOWNLOAD 7.7G !!! *** provided if needed but everything should be a binary emerge wget https://dev.drassal.net/genpi64/distfiles_202501210142.tar.bz2 *** verify we have the below files ls -l -rw-r--r-- 1 user user 33389459 1月 29 22:14 bootfs_20250128.tar.bz2 -rw-r--r-- 1 user user 582929975 1月 29 22:16 linux-6.6.74-raspberrypi_20250128.tar.bz2 -rw-r--r-- 1 user user 157652 1月 29 22:15 rootfs_firmware-bluez_20250128.tar.bz2 -rw-r--r-- 1 user user 1514076 1月 29 22:15 rootfs_firmware-nonfree_20250128.tar.bz2 -rw-r--r-- 1 user user 39917774 1月 29 22:17 rootfs_modules_20250128.tar.bz2 -rw-r--r-- 1 user user 216210408 1月 22 14:08 stage3-arm64-openrc-splitusr-20250112T234833Z.tar.xz -rw-r--r-- 1 user user 1351 1月 22 14:08 stage3-arm64-openrc-splitusr-20250112T234833Z.tar.xz.DIGESTS *** unmount existing file system if mounted sudo umount ${SDCARD}1 sudo umount ${SDCARD}2 *** create the partition structure on the sd card sudo parted --script ${SDCARD} \ mklabel msdos \ mkpart primary fat32 1MiB 512MiB \ \ mkpart primary ext4 512MiB \ 100% \ set 1 boot on \ set 1 lba on *** set the partuuid sudo fdisk "${SDCARD}" < /dev/null p x i 0x6c586e13 r p w EOF *** format the partitions sudo mkfs.vfat -F 32 -n bootfs ${SDCARD}1 sudo mkfs.btrfs ${SDCARD}2 -L rootfs -f *** create mount points mkdir -p bootfs mkdir -p rootfs *** mount the partitions sudo mount -o,rw,nosuid,nodev,relatime,uid=0,gid=0 ${SDCARD}1 bootfs sudo mount -o,noatime,compress=zstd:15,ssd,discard,x-systemd.growfs ${SDCARD}2 rootfs *** copy the boot files sudo tar xjfp bootfs_20250128.tar.bz2 -C bootfs *** copy in the stage3 tarball *** extract to the sdcard (Raspberry64) sudo tar xfp stage3-arm64-openrc-splitusr-20250112T234833Z.tar.xz -C rootfs *** extract the current kernel modules to the sdcard sudo mkdir -p rootfs/lib/modules sudo tar xpjf rootfs_modules_20250128.tar.bz2 -C rootfs/lib/modules/. *** extract the nonfree firmware to the sdcard sudo mkdir -p rootfs/lib/firmware sudo tar xpjf rootfs_firmware-nonfree_20250128.tar.bz2 -C rootfs/lib/firmware/. *** extract the bluez firmware to the sdcard sudo mkdir -p rootfs/lib/firmware sudo tar xpjf rootfs_firmware-bluez_20250128.tar.bz2 -C rootfs/lib/firmware/. *** extract the kernel source to the rootfs sudo mkdir -p rootfs/usr/src/linux-6.6.74-raspberrypi_20250128 sudo tar xpjf linux-6.6.74-raspberrypi_20250128.tar.bz2 -C rootfs/usr/src/linux-6.6.74-raspberrypi_20250128/. *** create the symbolic link to linux sources cd rootfs/usr/src ls -l sudo ln -s linux-6.6.74-raspberrypi_20250128 linux ls -l cd ../../.. *** set the root password *** the below lines will set it auto-magically *** change the ROOT_PASSWORD variable to change it ROOT_PASSWORD="root" ROOT_PASSWORD_SALT=$(openssl rand -base64 12) ROOT_PASSWORD_HASHED=$(openssl passwd -6 -salt "${ROOT_PASSWORD_SALT}" "${ROOT_PASSWORD}") echo "password hash = ${ROOT_PASSWORD_HASHED}" *** to automatically do a search replace USER="root" sudo sed -Ei 's/^('"${USER}"':)([^:]+)(..+)$/\1'${ROOT_PASSWORD_HASHED//\//\\/}'\3/g' rootfs/etc/shadow *** to do it by hand sudo vi rootfs/etc/shadow *** edit the line for root to the following root:$6$LgsV7MZIY4lRScdT$B8jsNQXovzUitTPQUiOIPAnGgetQn2kJnWNbNa/CF27yiTom54WCHriMiWKy1f/ij8sDjEgi7Qif7dGrbeA3e1:10770:0::::: *** fix keyboard layout *** keyboard list available from ls -l rootfs/usr/share/keymaps/i386/qwerty *** check sub directories in rootfs/usr/share/keymaps/i386 for other desired layouts ls -l rootfs/usr/share/keymaps/i386 *** set the desired keyboard map sudo vi rootfs/etc/conf.d/keymaps KEYMAP="us" *** add symbolic link for ethernet adapater net.eth0 cd rootfs/etc/init.d sudo ln -s net.lo net.end0 ls -l cd ../../.. *** setup hostname to pi64 *** hostname setting is required for xfce4, it will break lots of things if not *** but it shouldn't break anything *** problem is that if hostname is set to "localhost" then dhcpcd will set it to *** the retrieved hostname from the DHCP server... while xorg is running... bad sudo sh -c "echo 'pi64' > rootfs/etc/hostname" *** setup the local portage tree sudo mkdir -p rootfs/etc/portage/repos.conf sudo vi rootfs/etc/portage/repos.conf/gentoo.conf *** BEGIN file data [DEFAULT] main-repo = gentoo [gentoo] location = /var/db/repos/gentoo sync-type = rsync #sync-uri = rsync://rsync.gentoo.org/gentoo-portage sync-uri = rsync://dev.drassal.net/gentoo-portage_20250115 auto-sync = yes sync-rsync-verify-jobs = 1 sync-rsync-verify-metamanifest = yes sync-rsync-verify-max-age = 24 sync-openpgp-key-path = /usr/share/openpgp-keys/gentoo-release.asc sync-openpgp-key-refresh-retry-count = 40 sync-openpgp-key-refresh-retry-overall-timeout = 1200 sync-openpgp-key-refresh-retry-delay-exp-base = 2 sync-openpgp-key-refresh-retry-delay-max = 60 sync-openpgp-key-refresh-retry-delay-mult = 4 *** END file data sudo mkdir -p rootfs/etc/portage/repos.conf sudo vi rootfs/etc/portage/repos.conf/genpi64.conf *** BEGIN file data [DEFAULT] main-repo = gentoo [genpi64] # Overlay for 64-bit Gentoo on the RPi3 and RPi4 SBCs # Maintainer: sakaki (sakaki@deciban.com) location = /var/db/repos/genpi64 sync-type = rsync sync-uri = rsync://dev.drassal.net/genpi64-portage_20250115 priority = 100 auto-sync = yes *** END file data *** add the following to the portage make.conf file sudo vi rootfs/etc/portage/make.conf *** BEGIN file data # global USE flag overrides USE="" # override default build parallelism by changing the following # two lines, and modifying the values as required # Pi3 users (or Pi4 users with a 1GiB variant) should be # less aggressive here MAKEOPTS="-j5 -l4" EMERGE_DEFAULT_OPTS="--jobs=5 --load-average=4" # caution! many parallel threads and / or emerge jobs may cause your # RPi3/4 to run out of memory during large builds, or genup runs # per https://wiki.gentoo.org/wiki/Raspberry_Pi_VC4 VIDEO_CARDS="fbdev vc4 v3d" INPUT_DEVICES="evdev synaptics" # uncomment to build binary packages as a byproduct of each emerge #FEATURES="${FEATURES} buildpkg" # uncomment to use binary packages from PORTAGE_BINHOST, where available, # (and build normally, where not) FEATURES="${FEATURES} getbinpkg" PORTAGE_BINHOST="https://dev.drassal.net/genpi64/pi64pie_20250115_binpkgs" # set gentoo sources mirror GENTOO_MIRRORS="https://mirrors.evowise.com/gentoo/ https://mirrors.lug.mtu.edu/gentoo/ http://distfiles.gentoo.org" PKGDIR=/var/cache/binpkgs DISTDIR=/var/cache/distfiles PYTHON_TARGETS="python3_11 python3_12 python3_13" *** END file data *** allow root to login with ssh sudo vi rootfs/etc/ssh/sshd_config *** change the below line from this #PermitRootLogin prohibit-password *** to this PermitRootLogin yes *** fix annoying f0 respawn error *** this is specific to raspberry pi sudo vi rootfs/etc/inittab *** comment out the below line (near the bottom of the file) f0:12345:respawn:/sbin/agetty 9600 ttyAMA0 vt100 *** change to the below #f0:12345:respawn:/sbin/agetty 9600 ttyAMA0 vt100 *** fixup fstab to mount the bootfs sudo vi rootfs/etc/fstab *** add the following line at the bottom of the file *** remember to match the PARTUUID of the sd card PARTUUID=6c586e13-01 /boot vfat defaults,auto,noatime,umask=0022,uid=0,gid=100 0 0 *** change cmdline.txt to point to the correct root partition *** change rootdelay to zero (only needed for external spinning hard disk) sudo vi bootfs/cmdline.txt console=serial0,115200 console=tty1 dwc_otg.lpm_enable=0 root=PARTUUID=6c586e13-02 rootfstype=btrfs rootdelay=0 fsck.repair=yes rootwait *** copy in binpkgs if desired *** should not be normally needed (automatcally downloaded during emerge) *** if downloaded above #mkdir -p rootfs/var/cache/binpkgs #sudo tar xjfp binpkgs_202501210142.tar.bz2 -C rootfs/var/cache/binpkgs *** copy in distfiles if desired *** should not be normally needed *** if download above #mkdir -p rootfs/var/cache/distfiles #sudo tar xjfp distfiles_202501210142.tar.bz2 -C rootfs/var/cache/distfiles *** unmount the partitions sudo umount ${SDCARD}1 sudo umount ${SDCARD}2 *** remove the mount points rmdir bootfs rmdir rootfs *** if can't unmount, see what is using it #sudo fuser -mv ${MOUNT_ROOTFS} *** boot up the raspberry pi *** it should come up to a login prompt *** ON THE RASPBERRY PI KEYBOARD *** startup the ethernet /etc/init.d/net.end0 start *** startup sshd /etc/init.d/net.sshd start *** FROM NOW SSH INTO THE RASPBERRY PI FROM ANOTHER LINUX OR MACOS PC *** this will be easier to copy/paste commands *** at this point can ssh into the raspberry pi *** preferable for ease of copy/paste *** ssh to raspberry pi *** password was as set above, or "root" if not changed ssh root@192.168.3.105 *** setup sshd to autostart rc-update add sshd default *** we will not ne adding net.end0 to autostart as NetworkManager *** will handle this for us soon *** setup the swclock rc-update del hwclock boot rc-update add swclock boot *** stop hwclock and start swclock *** will need to set date time again /etc/init.d/hwclock stop /etc/init.d/swclock start *** set timezone first if desired to assist with setting datetime correctly *** available timezones can be seen here ls -l /usr/share/zoneinfo ls -l /usr/share/zoneinfo/US ln -sf /usr/share/zoneinfo/US/Pacific /etc/localtime *** reload profile to get new timezone settings env-update && source /etc/profile *** set datetime *** To set the system clock, e.g. 21:51 January 30, 2025: *** emerges will fail if date is set wrong date 013021512025 *** restart swclock to save new datetime /etc/init.d/swclock restart *** NOW GET INTO THE REAL SETUP *** download the portage tree emerge --sync *** check available profiles if desired eselect profile list *** set the profile *** must use this one to get everything installed correctly eselect profile set genpi64:default/linux/arm64/23.0/split-usr/desktop/genpi64 *** double check the profile was selected eselect profile list *** copy the package.use file in *** this is required to set the meta package dev-embedded/rpi-64bit-meta options *** the selected options will result in a full emerge with Xorg and all applications nano /etc/portage/package.use/rpi-64bit-meta *** BEGIN file data # Enable/disable any metapackage USE flags you want here, and then # re-emerge dev-embedded/rpi-64bit-meta to have the effect taken up # e.g. you might set (uncommented): # # dev-embedded/rpi-64bit-meta -weekly-genup # # to disable the automated weekly genup (package update) # run. # # Unless you override them, the default metapackage flags are used. # At the time of writing, those are (default flag status shown as + or -): # # + boot-fw : pull in the /boot firmware, configs and bootloader # + kernel-bin : pull in the binary kernel package # - porthash : pull in repo signature checker, for isshoni.org rsync # + weekly-genup: pull in cron.weekly script, to run genup automatically # + innercore: pull in essential system packages for image (RPi initscripts etc.) # + core: pull in main packages for image (clang etc.) (requires innercore) # + xfce: pull in packages for baseline Xfce4 system (requires core) # - pitop: pull in Pi-Top support packages (NB most users will NOT want this; # the Pi-Top is a DIY laptop kit based around the RPi3) (requires xfce) # - apps: pull in baseline desktop apps (libreoffice etc.) (requires xfce) # # NB the main point of the core, xfce, pitop and apps USE flags is just to let # you reduce what is in your @world set (/var/lib/portage/world). dev-embedded/rpi-64bit-meta apps -weekly-genup *** END file data *** the following license keywords need to be added mkdir -p /etc/portage/package.license cd /etc/portage/package.license echo "media-fonts/ipamonafont grass-ipafonts" > ipamonafont cd *** see what the emerge will do *** 731 packages will be emerged (all binary) *** dev-embedded/rpi-64bit-meta might not be binary but that is ok *** binary packages will be downloaded then installed, no compiling emerge --ask -j5 --keep-going rpi-64bit-meta *** all 731 packages should have emerged without error *** run etc-update and discard changes to /etc/portage/package.use/rpi-64bit-meta etc-update 1) /etc/portage/package.use/rpi-64bit-meta (1) *** q to exit the file display 2) Delete update, keeping original as is ******************************* *** INITIAL EMERGE DONE *** ******************************* ********************************** *** FINISH REMAINING SETUP *** ********************************** *** set vim as default editor eselect editor list eselect editor set "vim" env-update && source /etc/profile *** emerge ntp emerge -j5 --ask net-misc/ntp *** update the system clock with nptd /etc/init.d/ntpd stop ntpd -gq /etc/init.d/ntpd start *** add ntpd to autostart rc-update add ntpd default *** enable passwordless sudo visudo *** change the following 2 lines ## Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL *** to the two lines below ## Same thing without a password %wheel ALL=(ALL) NOPASSWD: ALL *** create user account useradd demouser passwd demouser *** add user to wheel group (for sudo) usermod -aG wheel demouser *** disable root account login *** replace root password hash with * vi /etc/shadow root:*:10770:0::::: *** disable root with ssh sudo vi /etc/ssh/sshd_config *** change the below line from this PermitRootLogin yes *** to this #PermitRootLogin prohibit-password *** add display-manager (and other necessities) to the default run level rc-update add dbus default rc-update add NetworkManager default rc-update add display-manager default *** set lightdm to the default display manager vi /etc/conf.d/display-manager DISPLAY_MANAGER="lightdm" *** disable display of the user's personal wallpaper *** add the following to the greeter settings file vi /etc/lightdm/lightdm-gtk-greeter.conf user-background=false *** example of file contents below after change [greeter] background=/usr/share/lightdm/backgrounds/gentoo-bg_65.jpg theme-name=Adwaita icon-name=gnome cursor-name=gnome font-name=Cantarell 11 xft-antialias=true xft-dpi=96 xft-hintstyle=hintslight xft-rgba=rgb indicators=~host;~spacer;~clock;~spacer;~session;~language;~a11y;~power;~ user-background=false *** Most display managers can automatically start the Xfce session by adding XSESSION="Xfce4" to /etc/env.d/90xsession: *** Otherwise, it will read the value of the XSESSION variable from the /etc/env.d/90xsession file and execute the relevant session accordingly. *** Values for XSESSION are available in /etc/X11/Sessions/. To set a system wide default session run: echo XSESSION="Xfce4" > /etc/env.d/90xsession env-update && source /etc/profile *** remove XSession entry for the display manager *** this will cause it to default to xfce *** maybe if the above 90xsession worked correctly we could leave it rm /usr/share/xsessions/Xsession.desktop *** fix an issue with xfce *** fix an option to show the "Icons" under "Appearance" correctly for selection vi /usr/share/icons/Adwaita/index.theme *** change the below line from this Hidden=true *** to this Hidden=false *** example of file contents after change [Icon Theme] Name=Adwaita Comment=The Only One Example=folder Inherits=AdwaitaLegacy,hicolor Hidden=false *** fix keyboard layout in Xorg *** change the layout to a desired value *** only need to create this file to alter the keyboard layout *** example provided for a jp106 keyboard layout *** add the below file with the below contents mkdir -p /etc/X11/xorg.conf.d vi /etc/X11/xorg.conf.d/99-keyboard-layout.conf *** BEGIN file contents Section "InputClass" Identifier "system-keyboard" MatchIsKeyboard "on" Option "XkbLayout" "jp,us" Option "XkbModel" "jp106" Option "XkbOptions" "grp:alt_shift_toggle" EndSection *** END file contents *** setup video in Xorg *** raspberry pi requirement mkdir -p /etc/X11/xorg.conf.d vi /etc/X11/xorg.conf.d/99-video.conf *** BEGIN file contents Section "OutputClass" Identifier "vc4" MatchDriver "vc4" Driver "modesetting" Option "PrimaryGPU" "true" Option "Accel" "true" Option "RenderAccel" "true" Option "HWCursor" "true" Option "AddARGBGLXVisuals" "true" Option "TripleBuffer" "true" Option "DPI" "144" Option "IndirectMemoryAccess" "true" Option "UseSysmemPixmapAccel" "true" EndSection Section "Device" Identifier "kms" Driver "modesetting" Option "AccelMethod" "msdri3" Option "UseGammaLUT" "off" EndSection *** END file contents *** restart to check if the display manager starts correctly shutdown -r now