DISK=/dev/disk/by-id/nvme-INTEL_SSDPEKKW512G8_BTHH812205BA512D
MOUNT=/mnt/gentoo
ZPOOL=zroot
STAGE3=[stage3 mirror address]
USTC mirrors
TUNA mirrors
BFSU mirrors
wipefs -af ${DISK}
sgdisk -Zo ${DISK}
parted --script -a optimal ${DISK} \
unit mib \
mklabel gpt \
mkpart esp 1 1025 \
mkpart rootfs 1025 100% \
set 1 boot on
sgdisk -n1:1M:+1G -t1:EF00 ${DISK}
sgdisk -n2:0:0 -t2:BF00 ${DISK}
mkfs.vfat -F32 -n EFI ${DISK}-part1
zpool create -f \
-o ashift=12 \
-o cachefile=/etc/zfs/zpool.cache \
-O normalization=formD \
-O compression=lz4 \
-O acltype=posixacl \
-O relatime=on \
-O atime=off \
-O xattr=sa \
-m none -R ${MOUNT} ${ZPOOL} ${DISK}-part2
zfs create -o mountpoint=none -o canmount=off ${ZPOOL}/ROOT
zfs create -o mountpoint=none -o canmount=off ${ZPOOL}/data
zfs create -o mountpoint=/ ${ZPOOL}/ROOT/default
zfs create -o mountpoint=/home ${ZPOOL}/data/home
zfs create -o mountpoint=/var/db/repos ${ZPOOL}/data/ebuild
zfs create -o mountpoint=/var/cache/distfiles ${ZPOOL}/data/distfiles
zfs create -o mountpoint=/var/cache/ccache ${ZPOOL}/data/ccache
zfs create -V 32G -b 8192 -o logbias=throughput -o sync=always -o primarycache=metadata ${ZPOOL}/SWAP
zpool set bootfs=${ZPOOL}/ROOT/default ${ZPOOL}
mkdir -p ${MOUNT}/boot
mount ${DISK}-part1 ${MOUNT}/boot
mkswap /dev/zvol/${ZPOOL}/SWAP
swapon /dev/zvol/${ZPOOL}/SWAP
mkdir -p ${ZPOOL}/etc/zfs
cp /etc/zfs/zpool.cache ${ZPOOL}/etc/zfs/zpool.cache
zpool import -d ${DISK}-part2 -R ${MOUNT} ${ZPOOL} -N
zfs mount -a
mount ${DISK}-part1 ${MOUNT}/boot/
swapon /dev/zvol/${ZPOOL}/SWAP
mount --types proc /proc ${MOUNT}/proc
mount --rbind /sys ${MOUNT}/sys
mount --rbind /dev ${MOUNT}/dev
mount --bind /run ${MOUNT}/run
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm /run/shm
chroot ${MOUNT} /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"
ntpd -q -g
date
```<Br/>
### 2.2 下载stage3到/mnt/gentoo下
```shell
cd ${MOUNT}
wget ${STAGE3}
tar xvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
mount --types proc /proc ${MOUNT}/proc
mount --rbind /sys ${MOUNT}/sys
mount --rbind /dev ${MOUNT}/dev
mount --bind /run ${MOUNT}/run
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm /run/shm
cp --dereference /etc/resolv.conf ${MOUNT}/etc/
chroot ${MOUNT} /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"
nano -w /etc/portage/make.conf
COMMON_FLAGS="-O2 -march=native -pipe"
CHOST="x86_64-pc-linux-gnu"
CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sha sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3"
MAKEOPTS="-j13"
EMERGE_DEFAULT_OPTS="--keep-going --with-bdeps=y --autounmask-write=y --jobs=2 -l"
AUTO_CLEAN="yes"
GENTOO_MIRRORS="https://mirrors.ustc.edu.cn/gentoo"
#FEATURES="${FEATURES} -userpriv -usersandbox -sandbox"
GRUB_PLATFORMS="efi-64"
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
#USE
MASKU="-wayland -bindist -jumbo-build -mdev -oss -systemd -qtwebengine -webengine -consolekit -bluetooth -networkmanager -ppp -gnome -gnome-shell -gnome-online-accounts -gnome-keyring -nautilus -kde -plymouth -icu"
LIKEU="X xinerama elogind udev blkid efi acpi ccache dbus policykit udisks alsa pulseaudio jack lv2 sf2 grub cjk emoji zsh-completion nvenc"
USE="${MASKU} ${LIKEU}"
#Ccache
#FEATURES="parallel-fetch ccache"
#CCACHE_DIR="/var/cache/ccache"
emerge-webrsync
emerge -av dev-vcs/git dev-util/ccache app-editors/neovim
eselect vi set nvim
eselect editor set vi
export CCACHE_DIR="/var/cache/ccache"
mkdir -p /etc/portage/repos.conf/
vi /etc/portage/repos.conf/gentoo.conf
[DEFAULT]
main-repo = gentoo
[gentoo]
location = /var/db/repos/gentoo
sync-type = git
sync-uri = https://mirrors.ustc.edu.cn/gentoo.git
sync-depth = 1 auto-sync = yes
rm -rf /var/db/repos/gentoo
emerge --sync
eselect profile list
eselect profile set 5
emerge -avuDN @world
echo "sys-kernel/gentoo-kernel-bin -initramfs" > /etc/portage/package.use/gentoo-kernel-bin
echo "sys-fs/zfs dist-kernel" > /etc/portage/package.use/zfs
echo "sys-fs/zfs-kmod dist-kernel" >> /etc/portage/package.use/zfs
echo "sys-boot/grub libzfs" > /etc/portage/package.use/grub
echo "app-text/ghostscript-gpl -l10n_zh-CN" > /etc/portage/package.use/ghostscript-gpl
echo "sys-fs/zfs ~amd64" > /etc/portage/package.accept_keywords/zfs
echo "=sys-fs/zfs-9999 **" >> /etc/portage/package.accept_keywords/zfs
echo "sys-fs/zfs-kmod ~amd64" >> /etc/portage/package.accept_keywords/zfs
echo "=sys-fs/zfs-kmod-9999 **" >> /etc/portage/package.accept_keywords/zfs
echo "options zfs zfs_arc_min=268435456" > /etc/modprobe.d/zfs.conf
echo "options zfs zfs_arc_max=536870912" >> /etc/modprobe.d/zfs.conf
emerge -av sys-kernel/linux-firmware sys-kernel/genkernel sys-kernel/gentoo-kernel-bin zfs zfs-kmod
rm -rf /etc/hostid && zgenhostid
vi /etc/genkernel.conf
genkernel initramfs --compress-initramfs --kernel-config=/usr/src/linux/.config --makeopts=-j`nproc`
echo "Asia/Shanghai" > /etc/timezone
rm -rf /etc/localtime
emerge --config sys-libs/timezone-data
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
eselect locale set en_US.UTF-8
env-update && source /etc/profile && export PS1="(chroot) $PS1"
git clone https://github.com/26hz/install-tools.git
cd install-tools
./genfstab -U -p / >> /etc/fstab
因为zfs能够自行管理dataset,不需要在fstab中指定挂载选项,之后需要删除zfs文件系统的相关段落
vi /etc/conf.d/hostname
vi /etc/conf.d/net
config_enp34s0="null"
bridge_br0="enp34s0 tap1 tap2 tap3"
rc_net_br0_need="net.enp34s0 net.tap1 net.tap2 net.tap3"
config_br0="172.16.26.126/16 fd00::32/64"
routes_br0="default via 172.16.26.2
default via fd00::1"
bridge_forward_delay_br0=0
bridge_hello_time_br0=1000
bridge_stp_state_br0=0
config_tap1="null"
tuntap_tap1="tap"
iproute2_tap1="user root"
config_tap2="null"
tuntap_tap2="tap"
iproute2_tap2="user root"
config_tap3="null"
tuntap_tap3="tap"
iproute2_tap3="user root"
ln -s /etc/init.d/net.lo /etc/init.d/net.br0
ln -s /etc/init.d/net.lo /etc/init.d/net.enp34s0
ln -s /etc/init.d/net.lo /etc/init.d/net.tap1
ln -s /etc/init.d/net.lo /etc/init.d/net.tap2
ln -s /etc/init.d/net.lo /etc/init.d/net.tap3
rc-update add net.br0 default
rc-update add net.enp34s0 default
rc-update add net.tap1 default
rc-update add net.tap2 default
rc-update add net.tap3 default
vi /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 gentoo.localdomain gentoo
vi /etc/conf.d/hwclock
clock="local"
vi /etc/security/passwdqc.conf
passwd
vi /etc/security/limits.conf
@audio - rtprio 95
@audio - memlock unlimited
emerge -av doas cronie eix zsh lsd gentoolkit dosfstools parted neofetch ntfs3g bpytop
rc-update add zfs-import boot
rc-update add zfs-mount boot
rc-update add zfs-share default
rc-update add zfs-zed default
rc-update add elogind boot
rc-update add dbus default
emerge --ask --verbose sys-boot/grub
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Gentoo
vi /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
例如:
GRUB_CMDLINE_LINUX="dozfs=cache quiet amd_iommu=on iommu=pt loglevel=5 nowatchdog"
GRUB_CMDLINE_LINUX_DEFAULT="spectre_v1=off spectre_v2=off spec_store_bypass_disable=off pti=off"
useradd -mG users,wheel,portage,usb,input,audio,video,sys,adm,tty,disk,lp,mem,news,console,cdrom,sshd,kvm,render,lpadmin,cron,crontab -s /bin/zsh jaus
passwd jaus
echo "permit keepenv nopass :wheel" > /etc/doas.conf
zfs snapshot zroot/ROOT/default@install
exit
umount /mnt/gentoo/boot
umount -Rl /mnt/gentoo/{dev,proc,sys,run,}
swapoff /dev/zvol/zroot/SWAP
zfs umount -a
zpool export -f zroot
reboot