Gentoo 配置手册

本文最后更新于:2023年3月18日 上午

1 准备工作

1.1 下载

  • 下载最小化安装镜像, 名称为: install-amd64-minimal-{日期}.iso

  • 下载合适的stage3,以日期为路径: 20220703T170542Z/stage3-amd64-desktop-systemd-20220703T170542Z.tar.xz

1.2 网络

基操忽略

1.3 分区挂载

基操忽略

1.4 ssh连接最小化安装系统

编辑 sshd 服务配置文件 /etc/ssh/sshd_config, 重启服务 rc-server sshd restart

1
2
PermitRootLogin yes
PasswordAuthentication yes

2 安装

2.1 解压基本系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
livecd ~ # blkid
/dev/sdb: UUID="e09609d8-0b90-4f34-aad1-8e5b37495f52" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sr0: BLOCK_SIZE="2048" UUID="2022-07-03-19-01-40-00" LABEL="Gentoo amd64 20220703T170542Z" TYPE="iso9660" PTUUID="5e426e6b" PTTYPE="dos"
loop0: TYPE="squashfs"
/dev/sda2: UUID="14077ead-3683-4354-95eb-a106c52350e9" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="4af31142-0ead-0644-b34c-c01b7c0944e1"
/dev/sda1: UUID="831A-6EDD" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="733a54ad-b3d7-3842-8cc8-21b15d29e82d"
livecd ~ # mount /dev/sda2 /mnt/gentoo/
livecd ~ # mkdir /mnt/gentoo/boot
livecd ~ # mount /dev/sda1 /mnt/gentoo/boot
livecd ~ # cd /mnt/gentoo/
livecd /mnt/gentoo # ls
boot lost+found
livecd /mnt/gentoo # wget https://mirrors.bfsu.edu.cn/gentoo/releases/amd64/autobuilds/20220703T170542Z/stage3-amd64-desktop-systemd-20220703T170542Z.tar.xz
--2022-07-05 08:09:54-- https://mirrors.bfsu.edu.cn/gentoo/releases/amd64/autobuilds/20220703T170542Z/stage3-amd64-desktop-systemd-20220703T170542Z.tar.xz
Resolving mirrors.bfsu.edu.cn... 39.155.141.16, 2001:da8:20f:1003::fe55:2840
Connecting to mirrors.bfsu.edu.cn|39.155.141.16|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 516402028 (492M) [application/octet-stream]
Saving to: ‘stage3-amd64-desktop-systemd-20220703T170542Z.tar.xz’
stage3-amd64-desktop-systemd- 100%[=================================================>] 492.48M 11.3MB/s in 46s
2022-07-05 08:10:40 (10.6 MB/s) - ‘stage3-amd64-desktop-systemd-20220703T170542Z.tar.xz’ saved [516402028/516402028]
livecd /mnt/gentoo # tar xpvf stage3-amd64-desktop-systemd-20220703T170542Z.tar.xz --xattrs-include='*.*' --numeric-owner
……

2.2 镜像源与chroot

配置一个速度较快的镜像源服务器地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mirrorselect -i -o >>/mnt/gentoo/etc/portage/make.conf  # 选择163和清华大学源
echo 'GENTOO_MIRRORS="https://mirrors.tuna.tsinghua.edu.cn/gentoo"' >>/mnt/gentoo/etc/portage/make.conf
# chroot 到目标系统
# 复制 DNS 配置到目标系统环境
cp -L /etc/resolv.conf /mnt/gentoo/etc/
# 挂载必要的文件系统
mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
# systemd stage3 额外执行
mount --make-rslave /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/dev
# chroot 到目标系统环境
chroot /mnt/gentoo
# 导入环境信息
. /etc/profile
# 修改提示符以便于区分
PS1=(chroot)$PS1

2.3 portage仓库

1
2
3
4
# 仓库信息打包下载到本地
emerge-webrsync
# 安装 vim
emerge --ask app-editors/vim

2.4 profile选择

1
2
3
(chroot)livecd / # eselect profile list
(chroot)livecd / # eselect profile set 7
(chroot)livecd / # emerge --ask --verbose --update --deep --newuse @world

2.5 安装内核、固件

1
(chroot)livecd / # emerge --ask gentoo-kernel  
1
2
(chroot)livecd / # emerge --ask linux-firmware

2.6 配置引导

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(chroot)livecd / # emerge --ask grub
(chroot)livecd / # grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Gentoo
Installing for x86_64-efi platform.
Installation finished. No error reported.
(chroot)livecd / # grub-install --target=x86_64-efi --efi-directory=/boot --removable
Installing for x86_64-efi platform.
Installation finished. No error reported.
(chroot)livecd / # grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.48-gentoo-dist
Found initrd image: /boot/initramfs-5.15.48-gentoo-dist.img
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done

2.7 时区、字符集配置

1
2
3
4
5
6
7
8
9
10
11
echo 'Asia/Shanghai' > /etc/timezone
rm /etc/localtime
emerge --config sys-libs/timezone-data
vim /etc/locale.gen
locale-gen

dd if=/dev/zero of=/swapfile bs=1M count=8192 status=progress
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap defaults 0 0" >> /etc/fstab

2.8 virtualbox 虚拟机配置

1
2
3
4
5
6
7
8
9
10
# 新建用户
useradd -m -g wheel -G usb,users,audio -s /bin/bash -N miloo

# 如果是虚拟机需要添加到以下两个组
gpasswd -a miloo vboxguest
gpasswd -a miloo vboxsf

# virtualbox 虚拟机安装后操作
emerge --ask app-emulation/virtualbox-guest-additions
systemctl enable --now virtualbox-guest-additions

3 USE

3.1 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
# 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.
COMMON_FLAGS="-march=native -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
MAKEOPTS="-j25"

# NOTE: This stage was built with the bindist Use flag enabled
PORTDIR="/var/db/repos/gentoo"
DISTDIR="/var/cache/distfiles"
PKGDIR="/var/cache/binpkgs"

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

# mirrors
GENTOO_MIRRORS="https://mirrors.ustc.edu.cn/gentoo/"
ACCEPT_LICENSE="*"
ACCEPT_KEYWORDS="amd64"
AUTO_CLEAN="yes"

# aria
FETCHCOMMAND="/usr/bin/aria2c -d \${DISTDIR} -o \${FILE} --allow-overwrite=true --max-tries=5 --max-file-not-found=2 --max-concurrent-downloads=5 --connect-timeout=5 --timeout=5 --split=5 --min-split-size=2M --lowest-speed-limit=20K --max-connection-per-server=9 --uri-selector=feedback \${URI}"
RESUMECOMMAND="${FETCHCOMMAND}"

# ccache
FEATURES="ccache -test"
CCACHE_DIR="/var/cache/ccache"

# GRUB
GRUB_PLATFORMS="efi-64"

# CPUS
ABI_X86="64"
CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sha sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3"

# cards
VIDEO_CARDS="amdgpu radeonsi vmware"

# touchpad
#INPUT_DEVICES="libinput synaptics" ##设置后触摸板配置失效

# language
L10N="en-US zh-CN en zh"
LINGUAS="en-US zh-CN en zh"

# USE

SYSME="-test -doc systemd"
GNOME="-kde -games -help -extras X gtk gnome"
USE="${SYSME} ${GNOME} "

3.2 USE

个人 USE 使用说明:

  • /etc/portage/make.conf 仅添加必要 flag 且尽量仅添加排除项。
    1
    2
    3
    SYSME="-test -doc systemd"
    GNOME="-kde -games -help -extras X gtk gnome"
    USE="${SYSME} ${GNOME} "
  • /etc/portage/package.accept_keywords 文件夹中创建文件,添加需要开启 ~amd(测试) 属性的包
    1
    app-office/wps-office ~*
  • /etc/portage/package.use 文件夹中创建文件,添加与 /etc/portage/make.confUSE 相悖或者仅对该包生效的 flag
    1
    2
    3
    app-emulation/qemu spice QEMU_SOFTMMU_TARGETS: x86_64 QEMU_USER_TARGETS: x86_64
    net-dns/dnsmasq script
    net-misc/spice-gtk usbredir

4 tools

4.1 包管理

4.1.1 app-portage/eix

1
2
3
app-portage/eix
app-portage/gentoolkit
app-portage/layman

4.2 文件系统

4.2.1 sys-fs/lvm2

1
sys-fs/lvm2

4.2.2 ntfs

1
sys-fs/ntfs3g

4.3 DE

4.3.1 gnome

一定要有swap分区,否则编译不会通过
make.conf 中 MAKEOPTS=”-j4” 此条不存在编译也会失败

1
2
3
gnome-base/gnome
gnome-base/gconf
gnome-extra/gnome-tweaks

4.4 vitual

4.4.1 virtualbox

1
2
3
4
5
app-emulation/virtualbox
app-emulation/virtualbox-additions
app-emulation/virtualbox-extpack-oracle
app-emulation/virtualbox-modules
app-emulation/virtualbox-guest-additions # gentoo虚拟机安装

4.4.2 kvm

1
2
3
4
app-emulation/qemu
app-emulation/libvirt
app-emulation/virt-manager
net-misc/bridge-utils
1
2
3
4
usermod -a -G libvirt miloo
usermod -a -G kvm miloo
systemctl enable libvirtd
systemctl enable virtlogd-admin.socket

5 系统迁移

5.1 权限备份与恢复

1
2
getfacl -R ./ > acl.txt
setfacl --restore=acl.txt

5.2 用户组

1
用户id=1001(miloo) 组id=100(users) 组=100(users),10(wheel),11(floppy),18(audio),19(cdrom),27(video),85(usb),78(kvm),272(plugdev),172(pulse-access),304(vboxusers),79(libvirt)

Gentoo 配置手册
https://worisur.github.io/2022/07/04/2022-07-04.gentoo配置手册/
作者
worisur
发布于
2022年7月4日
许可协议