Stage4

Gentoo 的安装一向比较费时,如果你有一堆机器该怎么办?每一台手工编译,岂不是要累死。 受 Chymeric Tutorials的mkstage4 - Stage 4 Tarballs Made Easy 文章启发 , 这里我们来讲个简单的办法:

    CFLAGS="-march=ivybridge -mtune=native -O2 -pipe"
    CXXFLAGS="${CFLAGS}"

例如

    liuk@localhost ~/proj/mkstage4 $ sudo ./mkstage4.sh -l -s -k -e /dataA -e /home/liuk/dataZ1/ /dataB/gentoo-stage4-20180511 --exclude=/dataB/* --exclude=/ssd/*
    Are you sure that you want to make a stage 4 tarball of the system
    located under the following directory?
    /

    WARNING: since all data is saved by default the user should exclude all
    security- or privacy-related files and directories, which are not
    already excluded by mkstage4 options (such as -c), manually per cmdline.
    example: $ mkstage4.sh -s /my-backup --exclude=/etc/ssh/ssh_host*

    COMMAND LINE PREVIEW:
    tar -cjpP --ignore-failed-read --exclude=/home/*/.bash_history --exclude=/dev/* --exclude=/var/tmp/* --exclude=/media/* --exclude=/mnt/*/* --exclude=/proc/* --exclude=/run/* --exclude=/sys/* --exclude=/tmp/* --exclude=/usr/portage/* --exclude=/var/lock/* --exclude=/var/log/* --exclude=/var/run/* --exclude=/dataA --exclude=/home/liuk/dataZ1/ --exclude=/usr/src/*  --exclude=/lib64/modules/*  --exclude=dataB/gentoo-stage4-20180511.tar.bz2 --exclude=lost+found --exclude=/dataB/* --exclude=/ssd/* -f /dataB/gentoo-stage4-20180511.tar.bz2 /*

    tar -cjpP --ignore-failed-read -f /dataB/gentoo-stage4-20180511.tar.bz2.ksrc /usr/src/linux-4.16.6-gentoo*

    tar -cjpP --ignore-failed-read -f /dataB/gentoo-stage4-20180511.tar.bz2.kmod /lib64/modules/4.16.6-gentoo*

    Type "yes" to continue or anything else to quit: yes
tar xvjpf archive_name.tar.bz2

Configuring the kernel 步骤,可以直接替换成

    tar xvjpf archive_name.tar.bz2.kmod
    tar xvjpf archive_name.tar.bz2.ksrc

然后chroot进入新系统

mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"

似乎最好在chroot之后再挂载boot及efi分区,这点还没有完全确定。

#if use intel cpu
iucode_tool -S --write-earlyfw=/boot/early_ucode.cpio /lib/firmware/intel-ucode/*
##if use efi
mount -o remount,rw /sys/firmware/efi/efivars
grub-install --target=x86_64-efi --efi-directory=/boot/efi #[--removable]

然后,一定记得修改 /etc/fstab 中磁盘分区设置,之后在chroot中环境生成 initramfs

dracut --force --kver 4.14.76-gentoo #4.14.76-gentoo 按照你安装的kernel version string来
grub-mkconfig -o /boot/grub/grub.cfg
reboot

有必要的话,进入UEFI设置一下启动顺序。

emerge --usepkg

如果多台机器使用相同的 /etc/portage/ 目录,则可以通过nfs挂载 /usr/portage/packages ,然后使用 emerge --usepkg 来安装新的包,配置文件中唯一可以根据每台机器不同情况修改估计只有 MAKEOPTS="-j6"。