GW1: Install

Posted on Tue 24 September 2019 in linux

G W 1


  • Device: TP X1 Carbon 2015 3rd gen
  • Storage: SSD in GPT partition + f2fs OR xfs rootfs
  • Bootloader: on-board EFI firmware (no initramfs)
  • System init/rc: sysvinit + openrc, or s6 + s6-rc
  • Profile: linux/amd64/17.1/(no-)multilib/desktop

Walk through

Bootstrap environment

Make a bootable USB with Gentoo minimal: dd if=iso of=/dev/sdX. Since mid 2018, the minimal iso has been made to supported UEFI boot. (ls /sys/firmware/efi/efivars)

OR from a running host: xinput list; xinput float 15


net-setup is helpful.

In the mininal environment, cabled network is rather easy to set up.

If only wifi available, there's iw for open wifi and wpa_supplicant for WPA wifi. To manually run dhcpcd, edit grub item of gentoo and add nodhcp; otherwise dhcpcd is started automatically.

SOLVED ALREADY! Note that the official ebuilds set net-wireless/crda as hard dep of wpa_supplicant, which has been abandoned since linux kernel 4.15 onward, and Gentoo bugzilla is aware of the issue. A simple template to rid crda dep can been seen here. Or even curter, add crda into /etc/portage/profile/package.provided. Use net-wireless/wireless-regdb instead.

Check dhcpcd/busybox udhcpc and /etc/resolv.conf when necessary.

Disk partition

SSD Memory cell clearing - follow arch guide: boot (arch) usb so that SSD is not mounted and suspend-then-wakeup-to-unfreeze should work.

[MISINFO sorry] (Gentoo Handbook says there should be sda1 for BIOS boot and sda2 for Boot. Guess that's for sake of Grub.)

fdisk /dev/sda ; g ; n ; (p;) t (L) 1(EFI) ; n ; (p;) w

For EFI firmware bootloader, just a /boot is needed. So the first partition should be a small sda1, about whose size recommendations vary from 128MB to 200+MB. Actual space usage is about tens of MB. Do mkfs.vfat -F 32 /dev/sda1 later (no more mkdosfs).

Next, all remaining space is partitioned sda2, and formatted f2fs, then mounted /mnt/gentoo (mkdir in case).

ALTERNATIVE: mkfs.xfs -m bigtime=1 /dev/sda2 ; mount default has nodiscard and relatime

(fdisk) new partition created ~ new PARTUUID ; (mkfs) partition formatted ~ new UUID, old PARTUUID

Prepare stage3

nomultilib tarball: tar xpf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

In make.conf, set COMMON_FLAGS="-march=broadwell" or native , MAKEOPTS="-j5 -l5", CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3 " or aes avx f16c mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3 , mirror addr, sample USEX pulseaudio libinput zsh-completion -consolekit -elogind -policykit -cdr -dvd -dvdr, VIDEO_CARDS, INPUT_DEVICES, ACCEPT_LICENSE, and PORTAGE_TMPDIR="/tmp/". Mount /tmp on tmpfs.

note: wayland

If emerge --sync via rsync, disable sync-rsync-verify-metamanifest and sync-allow-hardlinks in etc/portage/repos.conf/gentoo.conf. Discussion here

Mount pseudo-fs:

mount --types proc /proc /mnt/gentoo/proc # -t
mount --rbind /sys /mnt/gentoo/sys # -R
mount --rbind /dev /mnt/gentoo/dev # -R
mount --bind /run /mnt/gentoo/run # -B
# mount -o mode=1777,nosuid,nodev -t tmpfs tmpfs /mnt/gentoo/tmp
# slave for systemd; no harm for non-systemd
#mount --make-rslave /mnt/gentoo/sys
#mount --make-rslave /mnt/gentoo/dev
#mount --make-slave /mnt/gentoo/run
# mount in master -> propagate to slave; mount in slave X_X no effect on master

Chroot and mount /boot.

Use another disk for portage stuff: (host) mount -B diskY /mnt/gentoo/mnt ; (chroot) mkdir /mnt/g ; in etc/portage/repos.conf/gentoo.conf set location to /mnt/g/repos/gentoo ; change ln of etc/portage/make.profile ; change in etc/portage/make.conf PORTDIR to /mnt/g/repos/gentoo , PKGDIR to /mnt/g/p , DISTDIR to /mnt/g/d , PORTAGE_TMPDIR to /mnt/g/t (1777, plus mkdir -m775 t/portage - portage:portage ) see this check: portageq envvar XYZ

interrupt-resume : /etc/resolv.conf PLUS mount PLUS chroot

Issue emerge --sync (millions of small files). Set up custom profile.

Then, as Handbook , eselect profile list,eselect profile set 1

binpkg:(Update GCC first) getuto once; mirror in /etc/portage/binrepos.conf/gentoobinhost.conf ; FEATURES="${FEATURES} getbinpkg binpkg-request-signature" in make.conf ; emerge flags

emerge -uDN world (binpkg-respect-use default on, binpkg diff than local USE will not be pulled, KEEP IT enabled, dangerous to disable it)

echo "Asia/Dubai" > /etc/timezone ; emerge --config sys-libs/timezone-data

/etc/locale.gen , locale-gen , eselect locale list, eselect locale set 1

env-update && source /etc/profile


ebuild kernel compile, sneak to work/, conf (.config , make oldconfig) revcode, hostname and make, (space less than 2G), INSTALL_MOD_PATH, INSTALL_PATH, (DESTDIR) can be used. add pkg-ver to package.provided

old config to .config ; then make oldconfig

Graphics stuff:

Audio stuff:

another Audio: (NOTE permission of C devices in /dev/snd/, grant group access) (XDG, dbus-launch, perm, launcher, wpctl)

Built-in examples: IRQPOLL, fs, keyboard, microcode updated firmware in cmdline

Modules examples: e1000e, iwlmvm, snd-hda, psmouse

Optional examples: useless drivers, IA32 emulation, virtualization

Firmware (in /lib/firmware): iwlwifi-7265D-29.ucode [1] (from sys-kernel/linux-firmware), /lib/firmware/intel-ucode/06-3d-04 (from sys-firmware/intel-microcode), regulatory.db (from net-wireless/wireless-regdb), among which microcode must be built into kernel.

Fine tuning

  • Mainly Handbook again.
  • net-misc/chrony chronyd -q
  • sys-block/io-scheduler-udev-rules
  • wpa_supplicant wpa_passphrase name 9assw0rd | wpa_supplicant -iwlan0 -c/dev/stdin
  • (sway:) sys-auth/seatd USE server , rc-update add seatd boot
  • Check gentoo's and arch's wiki about efibootmgr.
    • efibootmgr -c -d /dev/sda -p 1 -L 'Gt' -l /EFI/Gentoo/boot.efi -u 'root=PARTUUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX rw'
    • *nix path style is okay for -l, the path is in /dev/sda1 (/boot) ; so -l vmX is just /boot/vmX ; note the leading slash
    • /dev/nvme0n1p1 break down to /dev/nvme0n1 as disk and 1 as partition
    • to rebuild/upgrade kernel later, mount /boot and copy the vmlinux file to efi

systemd-boot example where EFI partition mountpoint = /boot :

  • note that bootctl install OVERWRITES /boot/EFI/Boot/bootx64.efi
  • /boot/loader/loader.conf : default a.conf↙timeout 9↙console-mode max
  • /boot/loader/entries/a.conf : title A1↙linux /vmlinuz↙initrd /intel-ucode.img↙initrd /initramfs.img↙options root=PARTUUID=abc-123 rw
  • the above vmlinuz and img are under /boot

grub example with mbr, bios :

  • grub-install --target=i386-pc /dev/sda (not partition but disk)
  • grub-mkconfig -o /boot/grub/grub.cfg
  • in cfg, for win, duplicate menuentry and mod: insmod part_msdos↙insmod ntfs↙insmod ntldr↙(search UUID of lsblk --fs)↙ntldr /bootmgr


  • Emerge app-admin/syslog-ng, app-admin/logrotate, sys-process/cronie
  • For syslog-ng, copy wanted rules from /usr/share/doc/syslog-ng-*/syslog-ng.conf.gentoo.hardened.bz2 into /etc/syslog-ng/syslog-ng.conf
  • For logrotate, move /etc/cron.daily/logrotate to /etc/cron.weekly/ for a weekly rotation of logs
  • Add the services to appropriate runlevel
  • Be careful when modifying the conf file, e.g. a wrong @version item might cause boot hanging. Use syslog-ng -Fevd to debug.

RNG daemon

Startup can sometimes hang for a while at a line of "syslog" or "wpa_supplicant", but they are just superficial symptoms.

The real culprit is famine of RNG entropy.

Emerge sys-apps/rng-tools and test it out. If it's working well, then rc-update add rngd boot.


app-shells zsh,zsh-completions,gentoo-zsh-completions ; dev-vcs/git

Reboot to see the new system.

Add /dev/sdb1 /media auto user,noauto,noatime 0 0 in /etc/fstab to allow non-root usb mounting.

Larger console font example: terminus font