Gentoo 简明安装指南

Gentoo安装手册

参考配置文件

ArchWiki

Debian手册

准备另一个Linux环境

安装 arch-install-scripts,我们需要使用的有 genfstabarch-chroot

准备 cpuid2cpuflags ,可以在 https://github.com/gentoo/cpuid2cpuflags 找到

对硬盘进行分区

分区参考

  • /dev/nvme1n1p1 /efi 作为引导分区
  • /dev/nvme1n1p2 / 作为根分区

然后格式化,挂载磁盘

1
2
3
4
mkfs.xfs -L gentoo /dev/nvme1n1p2
mkfs.vfat -F 32 /dev/nvme1n1p1
mount --mkdir /dev/nvme1n1p2 /mnt/gentoo
mount --mkdir /dev/nvme1n1p1 /mnt/gentoo/efi

准备stage3

https://get.gentoo.org/ 下载 desktop profile | systemd 的 stage3 文件

解压文件

1
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner -C /mnt/gentoo

复制DNS信息

1
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/

进入chroot

1
arch-chroot /mnt/gentoo

为了方便,可以用原系统的文本编辑器编辑各种文件,如 make.confpackage.use
配置文件参考 gentoo-systemd

同步并启用gentoo-zh/guru仓库

1
2
3
4
5
6
7
8
9
emerge-webrsync
emerge -av1 dev-vcs/git -j16
# 安装完后
rm -rf /var/db/repos/gentoo/
cp -r /path/to/repos.conf /etc/portage/repos.conf
cp -r /path/to/binrepos.conf /etc/portage/binrepos.conf # 二进制仓库,优先级9999
emerge --sync
getuto
emerge -av bash-completion

调整 make.conf

修改文件 /etc/portage/make.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.

# These warnings indicate likely runtime problems with LTO, so promote them
# to errors. If a package fails to build with these, LTO should not be used there.
WARNING_FLAGS="-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing"

COMMON_FLAGS="-O2 -pipe -march=native -flto ${WARNING_FLAGS}"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
LDFLAGS="${COMMON_FLAGS} ${LDFLAGS}"

RUSTFLAGS="${RUSTFLAGS} -C target-cpu=native"

MAKEOPTS="-j16 -l18"

ACCEPT_LICENSE="*"
ACCEPT_KEYWORDS="~amd64" # 如果要装稳定版的包,请将此改为 `amd64`

GENTOO_MIRRORS="http://distfiles.gentoo.org"

# Appending getbinpkg to the list of values within the FEATURES variable
FEATURES="${FEATURES} getbinpkg"
# Require signatures
FEATURES="${FEATURES} binpkg-request-signature"

# emerge
# EMERGE_DEFAULT_OPTS="--keep-going --with-bdeps=y --jobs=8 --load-average=10"
EMERGE_DEFAULT_OPTS="--keep-going --with-bdeps=y"

# use

# Compress
USE="${USE} lz4 zstd"

# Optimize
USE="${USE} clang lto pgo"

# Kernel
USE="${USE} caps dist-kernel io-uring"

ABI_X86="64"

# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C.utf8

选择profile

这里选择 gnome

1
2
eselect profile set default/linux/amd64/23.0/desktop/gnome/systemd
eselect profile list | grep gnome | grep systemd | grep "\*"

调整package.use

1
nano /etc/portage/package.use/use

内容如下

1
2
3
*/* CPU_FLAGS_X86: aes avx avx2 avx_vnni bmi1 bmi2 f16c fma3 mmx mmxext pclmul popcnt rdrand sha sse sse2 sse3 sse4_1 sse4_2 ssse3 vpclmulqdq
*/* VIDEO_CARDS: -* nvidia intel
*/* L10N: zh-CN en-US zh en

其中,CPU_FLAGS_X86cpuid2cpuflags生成的,VIDEO_CARDS是你有的显卡,L10N 是需要的语言包

配置locale

1
2
3
4
5
ln -vsf ../usr/share/zoneinfo/Asia/Shanghai /etc/localtime
nano /etc/locale.gen # 添加 en_US.utf8 和 zh_CN.utf8
locale-gen
eselect locale set en_US.utf8
cp /path/to/64-language-selector-prefer.conf /mnt/gentoo/etc/fonts/conf.d/64-language-selector-prefer.conf

更新系统

1
2
emerge --ask --verbose --update --deep --newuse --getbinpkg @world -j16
emerge --ask --depclean # 完成后清理

安装内核

修改 /etc/portage/package.use/use

  • 如果你使用systemd-boot和UKI:

    1
    2
    3
    # systemd-boot
    sys-apps/systemd boot
    sys-kernel/installkernel systemd-boot dracut uki
  • 如果你使用grub:

    1
    2
    sys-boot/grub mount
    sys-kernel/installkernel grub dracut

开始安装

1
2
emerge --ask sys-kernel/linux-firmware sys-firmware/sof-firmware sys-firmware/intel-microcode sys-kernel/installkernel gentoo-kernel-bin efibootmgr -j16
# systemctl enable systemd-boot-update.service # 如果使用systemd-boot

安装完成后,使用 bootctl install 或者 grub-install --efi-directory=/efi 安装引导程序,grub需要 grub-mkconfig -o /boot/grub/grub.cfg

准备fstab

1
2
# 在主机上而不是ach-chroot中运行
genfstab -U /mnt/gentoo > /mnt/gentoo/etc/fstab

打开检查,确保只有两行,一行根分区,一行esp

配置网络

1
2
emerge -av networkmanager
systemctl enable NetworkManager

设置root密码

1
passwd

systemd首次设置

1
2
3
systemd-machine-id-setup
systemd-firstboot --prompt # 设置主机名
systemctl preset-all --preset-mode=enable-only

时间服务器

1
2
emerge -av chrony
systemctl enable chronyd

安装一些包

1
emerge -av mlocate xfsprogs io-scheduler-udev-rules

创建用户

1
2
3
4
5
6
7
groupadd libvirt 
groupadd pipewire
groupadd docker
useradd -m -G wheel,audio,video,kvm,libvirt,users,locate,plugdev,pipewire,docker -s /bin/bash yoimiya
passwd yoimiya
emerge -av sudo
visudo # wheel组

清理

可以删掉stage3文件

安装后指南

zswap

1
2
3
4
5
6
7
fallocate -l 16GiB /swapfile
chmod 600 /swapfile
mkswap /swapfile
echo "/swapfile none swap defaults 0 0" >> /etc/fstab
echo '''GRUB_CMDLINE_LINUX="zswap.enabled=1 zswap.compressor=lz4 intel_iommu=on"''' >> /etc/default/grub
echo "GRUB_DISABLE_OS_PROBER=false" >> /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg

LTO优化安装rust版本的fish

增加文件 /etc/portage/env/llvm-lto.conf

内容可以是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# These warnings indicate likely runtime problems with LTO, so promote them
# to errors. If a package fails to build with these, LTO should not be used there.
#
# As of 2024-11-11, Clang has a pull request for -Wstrict-aliasing as a real
# warning (noop for now):
# https://github.com/llvm/llvm-project/pull/74155
#
# As of 2024-11-11, Clang lacks -Wlto-type-mismatch:
# https://github.com/llvm/llvm-project/issues/56487
WARNING_FLAGS="-Werror=odr -Werror=strict-aliasing"
COMMON_FLAGS="-march=native -O2 -flto=thin -pipe ${WARNING_FLAGS}"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"

RUSTFLAGS="-C target-cpu=native -C strip=debuginfo -C opt-level=3 \
-Clinker=clang -Clinker-plugin-lto -Clink-arg=-fuse-ld=lld"

LDFLAGS="${COMMON_FLAGS} ${LDFLAGS} -fuse-ld=lld"
CC="clang"
CXX="clang++"
CPP="clang-cpp"
AR="llvm-ar"
NM="llvm-nm"
RANLIB="llvm-ranlib"

USE="lto"

然后增加 /etc/portage/package.env/env

1
2
dev-util/cargo-c llvm-lto.conf
app-shells/fish llvm-lto.conf

开始安装

1
emerge -av app-shells/fish

声音服务器

增加 media-video/pipewire extra sound-server/etc/portage/package.use/use

1
2
3
# 用户模式
sudo emerge -av media-video/pipewire
systemctl --user enable pipewire.socket pipewire-pulse.socket wireplumber.service pipewire.service

NVIDIA显卡

增加 x11-drivers/nvidia-drivers kernel-open powerd/etc/portage/package.use/use

1
sudo emerge -av x11-drivers/nvidia-drivers

完成 make.conf

完整的 make.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.

# These warnings indicate likely runtime problems with LTO, so promote them
# to errors. If a package fails to build with these, LTO should not be used there.
WARNING_FLAGS="-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing"

COMMON_FLAGS="-O2 -pipe -march=native -flto ${WARNING_FLAGS}"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
LDFLAGS="${COMMON_FLAGS} ${LDFLAGS}"

RUSTFLAGS="${RUSTFLAGS} -C target-cpu=native"

MAKEOPTS="-j16 -l18"

ACCEPT_LICENSE="*"
ACCEPT_KEYWORDS="~amd64"

GENTOO_MIRRORS="http://distfiles.gentoo.org"

# Appending getbinpkg to the list of values within the FEATURES variable
FEATURES="${FEATURES} getbinpkg"
# Require signatures
FEATURES="${FEATURES} binpkg-request-signature"

# emerge
# EMERGE_DEFAULT_OPTS="--keep-going --with-bdeps=y --jobs=8 --load-average=10"
EMERGE_DEFAULT_OPTS="--keep-going --with-bdeps=y"

# use

# KDE
USE="${USE} policykit"

# Compress
USE="${USE} lz4 zstd"

# Optimize
USE="${USE} clang lto pgo"

# NVIDIA
USE="${USE} cuda nvenc nvidia"

# Kernel
USE="${USE} caps dist-kernel io-uring"

# Media
USE="${USE} ffmpeg pipewire screencast vaapi vdpau"

ABI_X86="64"

# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C.utf8

然后更新系统

1
emerge --sync && emerge -auvDN @world -j16

配置USE

示例配置 /etc/portage/package.use/use

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
*/* CPU_FLAGS_X86: aes avx avx2 avx_vnni bmi1 bmi2 f16c fma3 mmx mmxext pclmul popcnt rdrand sha sse sse2 sse3 sse4_1 sse4_2 ssse3 vpclmulqdq
*/* VIDEO_CARDS: -* nvidia intel
*/* L10N: zh-CN en-US zh en

# */* PYTHON_TARGETS: python3_14
# */* PYTHON_SINGLE_TARGET: -* python3_14

# qemu
app-emulation/qemu spice usbredir virgl virtfs
net-libs/gnutls tools pkcs11
net-misc/spice-gtk usbredir

media-fonts/nerd-fonts adwaitamono cascadiacode cascadiamono codenewroman comicshannsmono firacode hack jetbrainsmono liberationmono ubuntu ubuntumono ubuntusans

net-im/wechat fcitx

dev-lang/rust-bin clippy rust-analyzer rustfmt rust-src

# systemd-boot
sys-apps/systemd boot
sys-kernel/installkernel systemd-boot dracut uki

# pipewire
media-video/pipewire extra sound-server

dev-libs/weston xwayland

x11-drivers/nvidia-drivers kernel-open powerd

安装常用软件

1
sudo emerge -av -j16 --noreplace eclean-kernel sudo unzip zip nano vim vscode virt-manager fcitx fcitx-chinese-addons fcitx-configtool fcitx-gtk fastfetch jq tmux command-not-found eix gentookit cpuid2cpuflags pfl portage-utils starship tree openjdk-bin weston nvchecker pkgdev dev-vcs/git lld nerd-fonts noto-cjk noto-emoji libva-intel-media-driver nvidia-vaapi-driver libva-utils mpv smplayer tencent-qq wechat flatpak kmscon ntfs3g gentoo-sourcees upower nvtop firefox-bin google-chrome mesa-progs xwininfo vdpauinfo kitty papirus-icon-theme tela-icon-theme

安装Gnome

1
2
sudo emerge -av -j16 gnome-base/gnome-light ptyxis gnome-tweaks dconf-editor
sudo systemctl enable gdm

To be continued


Gentoo 简明安装指南
https://rukkhadevata123.github.io/2025/10/17/gentoo/
作者
Dawn Chirps
发布于
2025年10月17日
许可协议