Gentoo Installation#
Preparation#
# Format USB drive
sudo mkfs.vfat /dev/sdb -I
# Burn LiveCD
sudo dd if=install-amd64-minimal-20210829T170531Z.iso of=/dev/sdb
# Insert into the computer to be installed, reboot to livecd
# Check network card
ifconfig
# Use Ethernet or WIFI
## If using Ethernet jump to sshd configuration
# ----------------Connect to WIFI-------------------
## If using WIFI
wpa_supplicant -B -i network_card -C /var/run/wpa_supplicant
wpa_cli -i network_card
# Scan
> scan
# View scan results
> scan_result
# Usually returns 0
> add_network
> set_network 0 ssid "WIFI name to connect"
> set_network 0 psk "WIFI password to connect"
# Connect to wifi
> enable_network 0
# Exit
> quit
# Check network
ifconfig
# ----------------sshd-------------------
# Generate key
# ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
# Run
/usr/sbin/sshd
# Change livecd root password
passwd
## Then connect to the machine to be installed via ssh from another machine in the local area network
Prepare Disk#
# Partition
# If the disk label type is not GPT, you need to change the disk label to GPT
# First install parted to change the disk label type
# sudo emerge -av sys-block/parted
# sudo parted
# mklabel gpt
# quit # This completes, then use cfdisk for partitioning
#sudo su
cfdisk /dev/sda
#sda1 ---/boot--->vfat >=200M # Note to set flags for esp
#sda2 ---/--->ext4,btrfs,xfs,jfs.etc >=20G # Suggested size at least 20G
#sda3 ---swap---> >=2G # Unless you have 16G memory
After writing, exit and enter sudo fdisk -l
to check if the partition was successful. Next, format:
# If mkfs.vfat command is not available, it needs to be installed
emerge -av sys-fs/dosfstools
mkfs.vfat /dev/sda1
mkfs.ext4 /dev/sda2
mkswap /dev/sda3
Install Basic Files#
China Mirror Sites:
Name | Protocol | IPv4/v6 | URL |
---|---|---|---|
Alibaba Cloud Computing | http | IPv4 only | https://mirrors.aliyun.com/gentoo/ |
Netease.com, Inc. | http | IPv4 only | https://mirrors.163.com/gentoo/ |
Tsinghua University | http | IPv4 + IPv6 | https://mirrors.tuna.tsinghua.edu.cn/gentoo |
Download image stage3-amd64-systemd-20210630T214504Z.tar.xz
Be sure to choose the appropriate image, for example, if you want to install a desktop environment, choose an image with desktop.
# Create directory
# mkdir /mnt/gentoo
# Mount
mount -v /dev/sda2 /mnt/gentoo
cd /mnt/gentoo
# Replace the following URL with the latest URL above
wget https://mirrors.ustc.edu.cn/gentoo/releases/amd64/autobuilds/current-stage3-amd64-systemd/stage3-amd64-systemd-20220417T171236Z.tar.xz
# Copy
# cp stage3-amd64-systemd-*.tar.xz /mnt/gentoo
# Extract
xz -d /mnt/gentoo/stage3-amd64-*.tar.xz
tar -xvf /mnt/gentoo/stage3-amd64-*.tar
# Delete
rm /mnt/gentoo/stage3-amd64-*.tar
Configure make.conf#
# Directly copy the current configuration
sudo cp /etc/portage/make.conf /mnt/gentoo/etc/portage/make.conf
# Content
# 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.
# GCC
COMMON_FLAGS="-march=native -O3 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
CHOST="x86_64-pc-linux-gnu"
CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3"
MAKEOPTS="-j8"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
# 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
# Language
L10N="en-US zh-CN en zh"
LINGUAS="en_US zh_CN en zh"
# Else
#VIDEO_CARDS="intel i965 nvidia"
VIDEO_CARDS="intel i965"
QEMU_SOFTMMU_TARGETS="alpha aarch64 arm i386 mips mips64 mips64el mipsel ppc ppc64 s390x sh4 sh4eb sparc sparc64 x86_64"
QEMU_USER_TARGETS="alpha aarch64 arm armeb i386 mips mipsel ppc ppc64 ppc64abi32 s390x sh4 sh4eb sparc sparc32plus sparc64"
USE="-bindist bluetooth"
GENTOO_MIRRORS="https://mirrors.ustc.edu.cn/gentoo/"
EMERGE_DEFAULT_OPTS="--keep-going --with-bdeps=y"
ACCEPT_KEYWORDS="~amd64"
ACCEPT_LICENSE="*"
GRUB_PLATFORMS="efi-64"
Configure Repository#
cd /mnt/gentoo
mkdir /mnt/gentoo/etc/portage/repos.conf
nano /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
# Content is
[gentoo]
location = /var/db/repos/gentoo
sync-type = rsync
#sync-uri = rsync://mirrors.tuna.tsinghua.edu.cn/gentoo-portage/
sync-uri = rsync://rsync.mirrors.ustc.edu.cn/gentoo-portage/
auto-sync = yes
Enter chroot#
Copy DNS
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
Mount
mount -t 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
If it is a Debian distribution, you also need to
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm
Enter chroot
chroot /mnt/gentoo /bin/bash
source /etc/profile
Remember to mount boot
mount /dev/sda1 /boot
Choose Profile and Update System#
# Use snapshot to update Portage:
emerge-webrsync
# List profiles:
eselect profile list
Here I directly chose: 15
# systemd without desktop system environment
eselect profile set 15
# Then comes the long update
date && emerge -auvDN --with-bdeps=y @world && date
# If you encounter unmet xxx or other prompts:
emerge -auvDN --with-bdeps=y --autounmask-write @world
# Enter update configuration, ensure no files are available for update when running again
etc-update --automode -3
emerge -auvDN --with-bdeps=y @world
# If the above still cannot solve the problem, enter the /etc/portage directory and delete package.use, package.mask, and package.unmask files or directories and try again
# At this point, you can go watch a movie...
# Wait for it to finish, don't rush, run these commands:
emerge @preserved-rebuild
perl-cleaner --all
emerge -auvDN --with-bdeps=y @world
# Ensure no updates before continuing, otherwise check output and try running again
# 2021-07-02 15:05 - 2021-07-02 16:46
# 2021-08-18 12:00 - 2021-08-18 13:47
# 2021-12-04 11:27 - 2021-12-04 12:30
Configure Timezone and Locale#
echo "Asia/Shanghai" > /etc/timezone
emerge --config sys-libs/timezone-data
echo "en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
eselect locale list
eselect locale set X # Replace X with the number displayed by the above command
Configure fstab#
# View UUID
blkid
nano /etc/fstab
# Content
UUID=4BB8-C88F /boot vfat defaults 0 0
UUID=8240d786-8908-4cdd-a00c-e3d265515a1e / ext4 defaults 0 0
UUID=02e6ac33-adfe-4fee-94ff-09141e1b809a none swap defaults 0 0
Install NetworkManager#
emerge -av networkmanager
If it says there are unmet xxxx or other prompts:
emerge --autounmask-write networkmanager
# Enter yes
etc-update --automode -3
emerge networkmanager
systemd add boot service:
systemctl enable NetworkManager
Modify hostname in /etc/conf.d/hostname, for example:
echo hostname=\"intent-gentoo\" > /etc/conf.d/hostname
Install Some Necessary Tools and Configure#
emerge app-admin/sysklogd sys-process/cronie sudo layman grub
sed -i 's/\# \%wheel ALL=(ALL:ALL) ALL/\%wheel ALL=(ALL:ALL) ALL/g' /etc/sudoers
# Or manually edit /etc/sudoers file
passwd # It's time to set the root password
# Gentoo's default password rules must mix uppercase and lowercase
# You can edit the following file to modify
nano /etc/security/passwdqc.conf
# Content as follows
min=8,7,6,5,4
max=72
passphrase=3
match=4
similar=deny
random=47
enforce=everyone
retry=20
If you are using systemd:
sed -i 's/\# GRUB_CMDLINE_LINUX=\"init=\/usr\/lib\/systemd\/systemd\"/GRUB_CMDLINE_LINUX=\"init=\/usr\/lib\/systemd\/systemd\"/g' /etc/default/grub
ln -sf /proc/self/mounts /etc/mtab
systemd-machine-id-setup
Configure and Install Kernel#
When compiling the kernel, be sure to check the vfat module!!!
# If you are currently running a normal Linux:
sudo cp -r /usr/src/linux* /mnt/gentoo/usr/src
# Or
scp /usr/src/linux/.config root@192.168.110.7:/mnt/gentoo/usr/src/linux
# You can also use xanmod
# First install app-eselect/eselect-repository
emerge -av app-eselect/eselect-repository
# Then select the mirror
# eselect repository list | grep src_prepare-overlay
# Choose the src_prepare-overlay source
# eselect repository enable 320
sudo eselect repository enable src_prepare-overlay
emerge -av dev-vcs/git
# Update source
emerge --sync
# Then search for xanmod
emerge -s xanmod-sources
# Install, may need to bypass firewall
emerge -av xanmod-sources
ln -s linux-* linux
# You can also install the official Gentoo source
emerge -av sys-kernel/gentoo-sources
# You can also choose the official Gentoo compiled image
emerge -av sys-kernel/gentoo-kernel
make localyesconfig # Or make menuconfig
# If prompted for missing bc
emerge -av sys-devel/bc
# If asked for new options, just press enter all the way, 23333
make -j8
make modules_install
make install
emerge -av sys-kernel/genkernel
genkernel --install initramfs
Install GRUB and Create User#
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Gentoo
grub-mkconfig -o /boot/grub/grub.cfg
# Create EFI BOOT folder
mkdir /boot/EFI/BOOT
cp /boot/EFI/Gentoo/grubx64.efi /boot/EFI/BOOT/BOOTx64.efi
Create an administrator and set a password:
useradd -m -G users,wheel,portage,usb,video intent
passwd intent
Graphics Driver#
See: https://wiki.gentoo.org/wiki/Intel
Intel Single Graphics Card:
emerge -av x11-drivers/xf86-video-intel
# If it says there are unmet xxxx or other prompts:
# Enter yes
etc-update --automode -3
emerge -av x11-drivers/xf86-video-intel
Install Desktop#
emerge -av xorg-server
GNOME#
emerge -av gnome-shell gdm gnome-terminal
systemctl enable gdm
If you encounter the need to update the configuration, run etc-update --automode -3 and run the command again.