Lưu ý
Tôi sử dụng các tệp sau:
install-amd64-minimal-20220123T170538Z.iso
stage3-amd64-desktop-systemd-20220116T170534Z.tar.xz
Thông tin cấu hình:
CPU: Intel i5-8300H (8) @ 4.000GHz
GPU: NVIDIA GeForce GTX 1060 Mobile 6GB
Host: OMEN by HP Laptop 15-dc0xxx
Mục tiêu cài đặt: amd64/UEFI/systemd/gnome/gentoo để sử dụng hàng ngày
Định dạng đĩa
fdisk /dev/nvme0n1
Thực hiện các bước sau:
- g - tạo phân vùng mới
- n - tạo phân vùng chính
- 1 - chọn phân vùng 1
- +256M - kích thước 256MB
- n - tạo phân vùng chính tiếp theo
- 2 - chọn phân vùng 2
- +16G - kích thước 16GB
- n - tạo phân vùng chính tiếp theo
- 3 - chọn phân vùng 3
- Chấp nhận mặc định cho phần còn lại
Kết quả sẽ tương tự:
/dev/nvme0n1p1 2048 526335 524288 256M Hệ thống EFI
/dev/nvme0n1p2 526336 34080767 33554432 16G Linux swap
/dev/nvme0n1p3 34080768 250069646 215988879 103G Linux hệ thống tệp
Định dạng các phân vùng:
mkfs.ext4 /dev/nvme0n1p3
mkfs.vfat /dev/nvme0n1p1
mkswap /dev/nvme0n1p2
swapon /dev/nvme0n1p2
Mount phân vùng hệ thống:
mount /dev/nvme0n1p3 /mnt/gentoo
Kết nối mạng
net-setup
SSID: Tên điểm phát WiFi của bạn, có thể dùng chia sẻ mạng từ điện thoại qua USB để tiện hơn
Mật khẩu: Mật khẩu WiFi
Đồng bộ giờ NTP (Bắt buộc!)
ntpd -q -g
Tải xuống stage3
links mirrors.tuna.tsinghua.edu.cn
Giải nén stage3
cd /mnt/gentoo
tar xpvf stage3-*.tar.bz2 --xattrs-include='*.*' --numeric-owner
Cấu hình tùy chọn biên dịch
nano -w /mnt/gentoo/etc/portage/make.conf
// Biên dịch song song với 8 nhân (tùy thuộc vào số nhân CPU của bạn)
MAKEOPTS="-j8"
// Chấp nhận tất cả giấy phép phần mềm
ACCEPT_LICENSE="*"
// Chỉ cài đặt phần mềm nhánh stable cho AMD64
ACCEPT_KEYWORDS="amd64"
Đồng bộ mirror
Chọn mirror:
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
Chỉ chọn mirror của Alibaba Cloud và Đại học Thanh Hoa
Kho ebuild Gentoo
mkdir --parents /mnt/gentoo/etc/portage/repos.conf
cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
Cần chỉnh sửa:
vi /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
sync-uri = rsync://rsyncl.cn.gentoo.org/gentoo-portage
Sao chép thông tin DNS
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
Mount các hệ thống tệp cần thiết
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
mount --bind /run /mnt/gentoo/run
mount --make-slave /mnt/gentoo/run
Chuyển vào môi trường mới
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"
Mount boot partition
mount /dev/nvme0n1p1 /boot
Chọn cấu hình profile phù hợp
eselect profile list
Kết quả:
Available profile symlink targets:
[1] default/linux/amd64/17.1 *
[2] default/linux/amd64/17.1/desktop
[3] default/linux/amd64/17.1/desktop/gnome
[4] default/linux/amd64/17.1/desktop/kde
Chọn cấu hình profile tương ứng
eselect profile set 3
Cập nhật hệ thống
emerge --ask --verbose --update --deep --newuse @world
Cài đặt phần mềm cần thiết
emerge --ask linux-firmware genkernel gentoo-sources networkmanager
Cấu hình múi giờ
ln -sf ../usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Cấu hình ngôn ngữ
vim /etc/locale.gen
en_US ISO-8859-1
en_US.UTF-8 UTF-8
zh_CN GBK
zh_CN.UTF-8 UTF-8
eselect locale list
eselect locale set 1
Chọn en_US.UTF-8
Tải lại môi trường:
env-update && source /etc/profile && export PS1="(chroot) ${PS1}"
Cài đặt kernel
Tạo symlink:
ln -s /usr/src/gentoo-linux /usr/src/linux
Sao chép file config của genkernel:
cp /usr/share/genkernel/arch/x86_64/generated-config /usr/src/linux/.config
cd /usr/src/linux
make menuconfig
Xóa openrc, bật linux config next
Biên dịch kernel:
make -j8 && make modules_install -j8 && make install
Tạo initramfs:
genkernel --install initramfs
Phương pháp kernel 2 (Khuyến nghị) (Tự động tạo initramfs)
genkernel all
File fstab
vim /etc/fstab
Mount tất cả các ổ đĩa, ví dụ:
/dev/sda1 /boot ext2 defaults,noatime 0 2
/dev/sda2 none swap sw 0 0
/dev/sda3 / ext4 noatime 0 1
Cấu hình mạng
emerge --ask net-misc/dhcpcd
systemctl enable --now dhcpcd
Quản lý mạng bằng systemd-networkd
Để cấu hình systemd-networkd, tạo file tại /etc/systemd/network/50-dhcp.network:
[Match]
Name=en*
[Network]
DHCP=yes
systemctl enable systemd-networkd.service
systemctl start systemd-networkd.service
systemd-networkd không tự động cập nhật resolv.conf, cần quản lý DNS bằng systemd:
ln -snf /run/systemd/resolve/resolv.conf /etc/resolv.conf
systemctl enable systemd-resolved.service
systemctl start systemd-resolved.service
systemctl enable --now NetworkManager
Thay đổi mật khẩu
passwd
GRUB UEFI
echo 'GRUB_PLATFORMS="efi-64"' >> /etc/portage/make.conf
emerge --ask sys-boot/grub:2
Thêm dòng này vào /etc/default/grub:
GRUB_CMDLINE_LINUX="init=/lib/systemd/systemd"
grub-install --target=x86_64-efi --efi-directory=/boot
grub-mkconfig -o /boot/grub/grub.cfg
Cấu hình khởi động
systemd-firstboot --prompt --setup-machine-id
systemctl preset-all
Thêm người dùng thông thường
Ví dụ, tạo người dùng tên "user1" thuộc các wheel, users và audio:
useradd -m -G users,wheel,audio -s /bin/bash user1
passwd user1
Khởi động lại hệ thống
exit
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
reboot
Hỗ trợ tiếng Trung
emerge media-fonts/wqy-zenhei wqy-bitmapfont wqy-microhei wqy-unibit
eselect fontconfig list
eselect fontconfig enable wqy-zenhei wqy-bitmapfont wqy-microhei wqy-unibit
IBus bộ gõ tiếng Trung
emerge app-i18n/ibus ibus-libpinyin
Thêm vào ~/.xprofile hoặc ~/.xinitrc:
export XMODIFIERS=@im=ibus
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
ibus-daemon -drx
Trong GNOME, tìm kiếm "ibus" để thay đổi cài đặt, Super+Space để chuyển bộ gõ
Layman kho bên thứ ba
emerge layman
layman -L
layman -a gentoo-zh
layman -a deepin
layman -s ALL
Flatpak kho bên thứ ba
Cài đặt Flatpak:
echo 'sys-apps/flatpak ~amd64\nacct-user/flatpak ~amd64\nacct-group/flatpak ~amd64\ndev-util/ostree ~amd64' >> /etc/portage/accept_keywords/flatpak
emerge sys-apps/flatpak
Thêm kho Flathub:
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
Mirror Flathub tại Thượng Hải:
flatpak remote-modify flathub --url=https://mirror.sjtu.edu.cn/flathub
Cài đặt phần mềm
emerge gnome xorg-drivers xorg-servers nvidia-drivers
Driver NVIDIA
Để tự động tải module khi khởi động, tạo file /etc/modules-load.d/video.conf và thêm:
nvidia
Tải module:
modprobe nvidia
Cấp quyền cho người dùng:
gpasswd -a username video
Kích hoạt NetworkManager và GDM:
systemctl enable NetworkManager && systemctl enable gdm
Vấn đề âm thanh
emerge alsa-utils
gpasswd -a username audio
Kiểm tra âm thanh với alsamixer:
alsamixer
Test âm thanh:
speaker-test -t wav -c 2
ALSA và PulseAudio
emerge media-plugins/alsa-plugin
systemctl --global enable pulseaudio.service pulseaudio.socket
Neovim configuration
options.lua:
local opt = vim.opt
-- Số dòng
opt.relativenumber = true
opt.number = true
-- Thụt lề
opt.tabstop = 2
opt.shiftwidth = 2
opt.expandtab = true
opt.autoindent = true
-- Ngăn ngắt dòng
opt.wrap = false
-- Dòng hiện tại
opt.cursorline = true
-- Kích hoạt chuột
opt.mouse:append("a")
-- Clipboard hệ thống
opt.clipboard:append("unnamedplus")
-- Cửa sổ mới mặc định bên phải và dưới
opt.splitright = true
opt.splitbelow = true
-- Tìm kiếm
opt.ignorecase = true
opt.smartcase = true
-- Giao diện
opt.termguicolors = true
opt.signcolumn = "yes"
vim.cmd[[colorscheme tokyonight-moon]]
init.lua:
require("core.options")
require("core.keymaps")
-- Plugin
require("plugins.lualine")
require("plugins.nvim-tree")
require("plugins.treesitter")
require("plugins.lsp")
require("plugins.cmp")
require("plugins.comment")
require("plugins.autopairs")
require("plugins.bufferline")
require("plugins.gitsigns")
require("plugins.telescope")
Alacritty terminal
alacritty.yml:
font:
normal:
family: Hack Nerd Font
style: Light
bold:
family: Iosevka
style: Medium
italic:
family: Iosevka
style: "Light Italic"
size: 12.0
window:
opacity: 0.9
colors:
primary:
foreground: '0x4d4d4c'
cursor:
text: '0xffffff'
cursor: '0x4d4d4c'
normal:
blackA: '0xffffff'
red: '0xc82829'
green: '0x718c00'
yellow: '0xeab700'
blue: '0x4271ae'
magenta: '0x8959a8'
cyan: '0x3e999f'
white: '0x4d4d4c'
bright:
black: '0x8e908c'
red: '0xf5871f'
green: '0xe0e0e0'
yellow: '0xd6d6d6'
blue: '0x969896'
magenta: '0x282a2e'
cyan: '0xa3685a'
white: '0x1d1f21'
import:
- ~/.config/alacritty/themes/themes/blood_moon.yaml
Material Shell
Extension GNOME để cải thiện trải nghiệm desktop
Gnome Looks
Theme Sweet, cần đặt vào:
- /usr/share/icons
- /usr/share/themes
- /usr/share/cursors
Nerd Font
Các font icon cho terminal và editor, đặt vào /usr/share/fonts
zlib
Thư viện nén dữ liệu
Tài liệu tham khảo
- Quy trình cài đặt Gentoo (bước by step)
- Hướng dẫn cài đặt Gentoo dual boot
- Hướng dẫn cài đặt Gentoo với systemd
- Wiki Gentoo IBus
- Hướng dẫn cài đặt GNOME 3 trên EFI
- Handbook Gentoo AMD64
- Wiki Gentoo GDM
- Wiki Gentoo NVIDIA drivers
- Wiki Gentoo Layman
- Wiki Gentoo PulseAudio