Gentoo installation tutorial
1. Introduction and features of Gentoo
Gentoo is a free operating system based on Linux, which can automatically optimize and customize for almost any application or requirement. It is almost highly liberalized and personalized, builds its own characteristic operating system, and has high flexibility. But because it is an operating system that downloads the source code and then compiles it, many people are discouraged. Portage is the core and feature of Gentoo. Gentoo can get the latest Portage tree from the server and then synchronize it. Since the Portage system installer will use the network to download the source code, when the system or software is installed, not only a connection at any time is required, but also sufficient transmission speed is required. During the compilation process, the operator needs to understand a certain knowledge of the underlying Linux, and the compilation time is longer, which is some of its shortcomings. In addition, Gentoo also has many derivative systems, such as Funtoo, Pentoo (hacker network penetration tool system). This article describes how to install and use Gentoo, and the installation methods of Funtoo and Pentoo are similar.
2. Gentoo basic system framework installation
The installation of Gentoo operating system is divided into the following steps: network connection, partition operation, source code download, kernel compilation, system configuration, system launcher installation.
2.1 Internet connection
First, the installation of the system requires a network connection so that the Portage system can connect to the server to synchronize file information. If it is a wired connection, you can directly install the network cable (the author's condition). If it is a wireless connection, you need to perform the following operations.
First check the information of the available network card
ifconfig
It can display the wireless network card wlp2s0 and wired network card enp3s0. Different computer names are different. The installation environment needs to include the wpa_supplicant tool to connect to the wireless network. Enter the following command
wpa_passphrase 网络名称 密码 >./wpa.conf
wpa_supplicant -i wlp2s0 -c ./wpa.conf -D wext -B # 用于启动wifi连接
Use DHCP protocol to obtain dynamic IP address for connection operation
dhcpcd
Then you can connect to the Internet. You can use the following command to check whether the Internet is connected:
ping www.baidu.com
2.2 Partition operation
Use fdisk, gparted, and cfdisk to perform partition operations. For ease of use, I use cfdisk for partitioning operations, or use diskgenius tools to perform partitioning and formatting operations in advance under windows.
View partition status
fdisk -l
Format partition
mkfs.fat /dev/sda1 # 用于EFI启动的分区
mkfs.ext4 /dev/sda2 # 用于安装系统文件的位置
mkswap /dev/sda3 #用于交换分区的位置
swapon /dev/sda3 # 激活交换分区
Here the author allocated 40GB as the Gentoo operating system area, 2GB as the swap partition, and 300MB as the EFI partition.
Mount partition
mount /dev/sda2 /mnt/gentoo
mkdir -p /mnt/gentoo/boot/efi
mount /dev/sda1 /mnt/gentoo/boot/efi
2.3 Source code download and file system installation
Since we are using the minimal installation image, we need to download the installation stage3 file to download. You can download it from the Tsinghua mirror source, or download it from the 163 mirror source. The author uses the 163 mirror source to download:
links http://mirrors.163.com/gentoo/releases/amd64/autobuilds/current-stage3-amd64/
Save the stage3-amd64-20200819T214503Z.tar.xz file to the /mnt/gentoo file directory. The next step is to decompress
tar xvf stage3-amd64-20200819T214503Z.tar.xz
Mount the file system
Here you need to mount the following file systems
mount -t proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
Copy configuration file
cp /etc/resolv.conf /mnt/gentoo/etc/
Change root directory
chroot /mnt/gentoo /bin/bash
env-update && source /etc/profile
export PS1="(chroot) $PS1"
Synchronize the portage source tree
This step is used to synchronize the Portage tree with the Gentoo source code on the server to the computer
mkdir /usr/portage
Because the download speed of foreign websites is relatively slow, it is stated in the manual that you can choose your own mirror address by using the mirrorselect tool. Since we have changed the root, here we manually add the mirror list. Edit file
nano /etc/portage/make.conf
And add the following
GENTOO_MIRRORS="http://mirrors.163.com/gentoo/"
SYNC="rsync://rsync.cn.gentoo.org/gentoo-portage
It is recommended to modify the MAKEOPTS variable according to the number of cores of your computer's CPU. The method of viewing is as follows
cat /proc/cpuinfo |grep processor
The author here shows 8 cores, so add the last line in the file make.conf as
MAKEOPTS="-j8"
File system installation
Update portage tree
emerge-webrsync
This step takes about 10 minutes, and some source code package files are downloaded in the process.
Configuring the system
This step refers to selecting the system profile, and checking which system profiles can be selected
eselect profile list
I chose the KDE Plasma desktop here, so I chose
eselect profile set default/linux/amd64/17.1/desktop/plasma
Note that the profile selection in this step is more important and is related to the later kernel compilation process.
Set the time zone
There is nothing to say in this step, set the Shanghai time zone
cp /usr/share/zoneinfo/Asia/Shanghai/etc/localtime
echo " Shanghai " > /etc/timezone
Edit the file locale.gen
nano /etc/locale.gen
Uncomment the following
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
Generate the corresponding configuration file
locale.gen
Set the system language (English is recommended)
echo LANG=en_US.UTF-8 > /etc/locale.conf
Update configuration file
env-update && source /etc/profile
Install the source code
This step is the core step, you need to download the source code file for later compilation of the kernel
emerge gentoo-sources
This step takes about 10-15 minutes. After the installation is complete, you can check if there is a linux symbolic link pointing to your kernel source code
ls -l /usr/src/linux
Compiling the kernel To
compile the kernel file, you need to install a small part of the following content. The compilation of the kernel depends on the following files
emerge app-arch/cpio
emerge sys-devel/autoconf-archive
Then update the environment
etc-update -3
Download kernel compilation tools
emerge --ask genkernel
Download the kernel tool when compiling, also download linux-firmware, linux kernel, and then compile the kernel
time genkernel all
Time is to calculate the length of time to compile the kernel file. Of course, the choice of the kernel can be selective compilation, here for the convenience of using all characters to indicate all compilation. You can use graphical selection to compile:
genkernel --menuconfig all
It takes about 30-40 minutes to compile here, which takes a long time.
2.4 System environment configuration
Modify the fstab file The
fstab file specifies the location where the file system is started and the mounted partition of the file system. Edit file
nano /etc/fstab
And write your own system installation mount partition according to the example
/dev/sda1 /boot/efi vfat defaults 0 2
/dev/sda2 / ext4 noatime 0 1
/dev/sda3 none swap sw 0 0
Save the file
Edit the domain name and host name
Edit the file
nano /etc/conf.d/hostname
Modify the file to your own name
hostname="myhostname"
Edit file
nano /etc/hosts
Modify the following to your own network hostname
127.0.0.1 myhostname
::1 myhostname
Network and other files
add dhcpcd, add DHCP protocol
emerge dhcpcd
Add as boot
rc-update add dhcpcd default
添加 syslog-ng, ssh, cronie,
emerge syslog-ng
emerge virtual/ssh
emerge cronie
Set to boot
rc-update add syslog-ng default
rc-update add sshd default
rc-update add cronie default
Add user and set password
Add user
useradd -m -g users -G wheel -s /bin/bash myusername
set password
passwd root
passwd myusername
Configure sudo, download sudo
emerge sudo
Edit file
nano /etc/sudoers
Add myusername to sudo
myusername ALL=(ALL) ALL
Add operating system startup items
Download grub and install
emerge sys-boot/grub
Install startup files
grub-install --target=x86_64-efi --efi-directory=/boot/efi --recheck
Generate the corresponding menu selection file
grub-mkconfig -o /boot/grub/grub.cfg
This is done, and then exit the chroot, uninstall
umount /mnt/gentoo/dev
umount /mnt/gentoo/proc
umount /mnt/gentoo/boot/efi
umount /mnt/gentoo/
Restarting the operating system completes the basic installation.
2.5 Follow-up
After the operating system was installed, it was found that there was no wireless network card driver, so the following operations were performed:
first install openssl, openssh
emerge net/misc/openssh
emerge net/misc/openssl
Then install iw, wpa_supplicant, dialog components, etc.
emerge iw dialog wpa_supplicant
At this point, the basic system has been installed. The following author describes the installation process of the desktop environment.
3. The installation process of the desktop environment
First install the xorg service, which is the lowest service component of the desktop environment.
sudo emerge --ask --quiet x11-base/xorg-drivers
sudo emerge --quiet --ask x11-base/xorg-server
sudo env-update
Install sddm login manager, of course, you can also choose other login managers to install, here I chose sddm login manager.
sudo emerge --ask --quiet sddm
Here you need to download a package cpuid2cpuflags for cpu flag management:
sudo emerge --ask --quiet cpuid2cpuflags
Then write the register flag of the cpu to the file
cpuid2cpuflags >> /etc/portage/make.conf
Then install the desktop
```bash
sudo emerge --ask --quiet kde-frameworks/plasma
sudo emerge --ask --quiet kde-plasma/plasma-meta
sudo emerge --ask --quiet xterm
Modify the configuration file of the login manager
sudo nano /etc/conf.d/xdm
Amended to the following
DISPLAYMANAGER="sddm"
Add sddm as boot
sudo rc-update add sddm default
Then after restarting the system, you can log in to the desktop environment
reference
[1] Gentoo installation process
[2] Gentoo official documentation