Gentoo Linux quick installation record

Posted by thangappan on Thu, 03 Feb 2022 08:53:12 +0100


Last updated: February 2, 2022

Write before:

Why should I use gentoo
It's not because of suffering philosophy. It's not difficult to install Gentoo. It just takes time
When I first came into contact with Linux, I chose Gentoo. At first, it was because of the inexplicable pleasure of full screen code scrolling during compilation~
People have a habit
At first, I thought that Gentoo's compilation and installation from the source code would improve the performance. This seems to be a misunderstanding. In fact, it can't. Even if there is a little improvement, I can't feel it
The best way is to have a powerful computer 😃
The main reason for using Gentoo is limited options
For example, I don't like systemd. I can use openrc
Customization can be carried out to a certain extent through USE control (this is a long-term work, which can not be solved in one installation)
Maybe this is the fundamental reason why I use Gentoo. It can satisfy a little desire for control~

Preparation before installation

Choose first stage3
 Problems that need to be considered in advance:
	systemd or openrc
	no-multilib or multilib
	File system selection:ext4,xfs,btrfs wait
 Then there is the installation environment,Is it a pure character interface or a graphical interface
 Personal recommendation with graphical interface livecd,It can be installed and viewed at the same time wiki,Although the character interface can also be seen..But that kind of typesetting really hurts
This installation:
init : openrc
profile : no-multilib
filesystem: xfs

This time with SystemRescue9.0 + Rufus 3.17 Making LiveUSB

SystemRescue used to be a distribution based on gentoo, but now it is based on Arch, which does not affect the installation of gentoo. Theoretically, gentoo can be installed on any existing Linux system
Why use SystemRescue
1. There is a graphical interface. You can copy commands from gentoo handbook or other tutorials during installation
2. Based on Arch Linux, you can use genfstab to generate fstab files
3. The arch chroot command can automatically mount proc sys dev without manual input 😃
4. It is convenient to roll back the terminal. The only regret is that you can't input Chinese

After making liveusb, restart it with U SB flash disk
Enter: startx to enter the graphical interface and open gentoo handbook with a browser
Open the terminal and start the installation

Wired connection generally, the network has been automatically configured
For wireless, please refer to gentoo handbook... I don't have a wireless network card

Hard disk partition

lsblk			#Check the hard disk number to determine which hard disk to install Gentoo on. Here is the SD
sgdisk --zap-all /dev/sdd      # Empty the hard disk. If there are other systems or important files on the hard disk, be careful
cfdisk -z /dev/sdd
# Select gpt
# Because there is an EFI partition of WIN10 (/ dev/sdb1) on my other hard disk, I don't need to divide another EFI partition, but directly divide the whole hard disk into one partition
# cfdisk operation is relatively simple
# New -- > new partition
# type  ---> linux-root(x86-64)
# Write -- > write to hard disk
# Quit -- > Exit
partitionsizefile systemMount pointSupplementary notes
/dev/sdb1300Mfat32/boot/EFIShare esp partition with win10
/dev/sdd1allxfs/
  • format
mkfs.xfs -f /dev/sdd1
# If ext4 is used
# Use the appropriate command mkfs ext4

Mount partition

# Mount root
# Since it is not the official livecd of gentoo, you need to create a directory. The name of this directory is optional, but you are used to using / mnt/gentoo
mkdir -v /mnt/gentoo
mount -t xfs /dev/sdd1 /mnt/gentoo 
# Mount EFI partition
mkdir -pv /mnt/gentoo/boot/efi
mount -t vfat /dev/sdb1 /mnt/gentoo/boot/efi
df -hT			# Start installation after inspection

Start installation

The installation part can be skipped... It is not different from gentoo wiki, mainly make Conf and kernel compilation are different from wiki
I want to make it convenient for me to copy commands during installation

ping -c 3 www.baidu.com       # Test network
ntpd -q -g	# Adjust the current system time

stage3

cd /mnt/gentoo
# Usually, non gentoo based livecd s do not have links command
# The SystemRescueCd used this time can use elinks, which is very similar to links
elinks https://mirrors.ustc.edu.cn/gentoo
# Enter directory 
/releases/amd64/autobuilds/current-stage3-amd64/
# Select the file with the direction key and press the d key to download:
stage3-amd64-nomultilib-YYYYMMDDhhmmssZ.tar.xz
stage3-amd64-nomultilib-YYYYMMDDhhmmssZ.tar.xz.DIGESTS	
				# The generation time of stage3 is subject to what you see during the actual installation
				# The no multilib profile I chose is a pure 64 bit system
				# Select the stage3 you want to use. It's best not to switch the profile during installation
				# It seems that no multilib and multilib cannot switch to each other in the later stage
# It is strongly recommended to check it				
sha512sum -c --ignore-missing stage3-amd64-nomultilib-YYYYMMDDhhmmssZ.tar.xz.DIGESTS
tar xpf stage3-amd64-*.tar.xz --xattrs-include='*.*' --numeric-owner
ls -la /mnt/gentoo	#Check after decompression
# Delete stage3. You can also delete stage3 after installation and restart
rm stage3-*.tar.xz*

SWAP create SWAP file

fallocate -l 16GiB /mnt/gentoo/.swapfile_16G
dd if=/dev/zero of=/mnt/gentoo/.swapfile_16G bs=1M count=16384 status=progress       # Exchange file size can be adjusted by itself
chmod 600 /mnt/gentoo/.swapfile_16G
mkswap /mnt/gentoo/.swapfile_16G
swapon /mnt/gentoo/.swapfile_16G

Replicate DNS

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

Configure fstab

genfstab -U /mnt/gentoo >> /mnt/gentoo/etc/fstab

Configure compilation options (make.conf)

vim /mnt/gentoo/etc/portage/make.conf
# When installing the system, only the following items can be added. Other things can be added after installation
# Makeopts: number of CPU cores + 1, that is, the output of the command nporc + 1
# Or memory size / 2
CHOST="x86_64-pc-linux-gnu"
COMMON_FLAGS="-march=ivybridge -O3 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
#  Ivbridge only, don't copy
CPU_FLAGS_X86="aes avx f16c mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3"

MAKEOPTS="-j8"
# ACCEPT_KEYWORDS="amd64"        # For beginners, it is recommended to use
ACCEPT_KEYWORDS="~amd64" 
ACCEPT_LICENSE="*"

GRUB_PLATFORMS="efi-64"
MICROCODE_SIGNATURES="-S"
AUTOCLEAN="yes"

EMERGE_DEFAULT_OPTS="--jobs=8 --load-average=7.2 --ask --verbose --quiet-build --keep-going --with-bdeps=y"
PORTAGE_ELOG_CLASSES="info warn error log qa"
PORTAGE_ELOG_SYSTEM="echo save"
FEATURES="userfetch parallel-fetch candy clean-logs split-log split-elog news"
#FEATURES="${FEATURES} -userpriv -usersandbox -sandbox"

GENTOO_MIRRORS="https://mirrors.tuna.tsinghua.edu.cn/gentoo/"
USE=""

chroot

arch-chroot /mnt/gentoo /bin/bash
source /etc/profile

Gentoo ebuild software warehouse

mkdir -p -v /etc/portage/repos.conf
cp -v /usr/share/portage/config/repos.conf /etc/portage/repos.conf/gentoo.conf
nano -w /etc/portage/repos.conf/gentoo.conf

#sync-uri = rsync://rsync.gentoo.org/gentoo-portage
sync-uri = rsync://mirrors.tuna.tsinghua.edu.cn/gentoo-portage 	# The sync image is changed to domestic, which is Tsinghua University
#perhaps
#sync-uri = rsync://mirrors.163.com/gentoo-portage 					// Netease		
#sync-uri = rsync://rsync.mirrors.ustc.edu.cn/gentoo-portage/ 		// China University of science and technology
#sync-uri = rsync://mirrors.yun-idc.com/gentoo-portage/ 				// Capital Online Technology Co., Ltd

Install ebuild database snapshot and update

emerge-websync
# Optional
emerge --sync
#If it cannot be updated, / etc / portage / repos conf/gentoo. In conf
#Sync Rsync verify metamafest = yes change to
#sync-rsync-verify-metamanifest = no
# If make FEATURES="userfetch" is set in conf
# You need to change the permissions of the / var/db/repos/gentoo directory 
chown --recursive --verbose portage:portage /var/db/repos/gentoo

Select the correct profile

#It is not recommended to change the profile here and keep it consistent with stage3 that you started downloading, or you will have to compile a lot of packages
# Therefore, it is necessary to determine no multilib or multilib before installation. It seems that these two cannot be switched casually, and there will be errors in compilation
# The Desktop profile can be switched after the basic system is installed, but it can not be switched. In make Set USE in conf to control and keep the system clean
# Moreover, no multilib has no profile of desktop to switch
# For setting up your own profile, please refer to gentoo wiki
eselect profile list
[26]  default/linux/amd64/17.1/no-multilib (stable) *

Install some necessary tools

emerge -av  linux-firmware gentoo-kernel-bin grub os-prober dosfstools gentoolkit neovim syslog-ng dhcpcd acpid cpuid2cpuflags xfsprogs
#If prompted to update
etc-update	# Enter - 3 enter yes enter
rc-update add syslog-ng default
rc-update add dhcpcd default
rc-update add acpid default
eselect vi list
  [1]	nvim
eselect vi set 1
eselect editor list
  [1]   nano
  [2]   ex
  [3]   vi
  [ ]   (free form)
eselect editor set 3
cpuid2cpuflags >> /etc/portage/make.conf

vi /etc/portage/make.conf
CPU_FLAGS_X86:aes avx f16c mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3
 Change to:
CPU_FLAGS_X86="aes avx f16c mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3"

GRUB

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Gentoo
echo 'GRUB_DISABLE_OS_PROBER=false' >> /etc/default/grub    # If there is a win system
grub-mkconfig -o /boot/grub/grub.cfg

Other settings

host name

vi /etc/conf.d/hostname
	hostname="GentoO"
	
#vi /etc/issue
##Delete \O

vi /etc/hosts
	127.0.0.1		GentoO
	127.0.0.1     	localhost
	::1				localhost

configure network

ifconfig	#Look at the name of the network card interface. Here is enp3s0
echo 'config_enp3s0="dhcp"' > /etc/conf.d/net

cd /etc/init.d
ln -s net.lo net.enp3s0
rc-update add net.enp3s0 default

Restart and enter the new system

OK, the basic system installation is completed

passwd	#Set the root password first
exit
cd
umount -lR /mnt/gentoo
reboot

Time zone, time, locale

echo 'Asia/Shanghai' > /etc/timezone
emerge --config sys-libs/timezone-data

echo "en_US.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8" >> /etc/locale.gen
#echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
eselect locale list	
#Make sure a region is set, otherwise the system will display warnings and errors when compiling and deploying other software in the kernel installed later.
#Do not set to zh, the terminal will have garbled code
#Reload environment
env-update && source /etc/profile

Update @ world collection

My make Conf backup
Warning: do not copy, according to your own machine settings

# 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.
# C, C++ and FORTRAN options for GCC.

# CPU: E3-1240 v2
# -fstack-protector-strong    	// stack smashing protector
# -Wl,-z,relro					// read-only segments after relocation
# -Wl,-z,now					// disable lazy binding
# -fexceptions					// enable table-based thread cancellation

# The compilation fails all the time during installation. You can't find the reason by looking at the prompt in the Log
# Finally I stared at the screen It was found that the reason why it could not be compiled was- March = ivhybrid is written as - March ivhybrid
# So be careful when entering manually

# CFLAGS: in fact, you don't need to write this line yourself. First keep the default, and then use resolve March native - A after chroot to copy the output
# COMMON_FLAGS="-march=native -O2 -pipe"
# COMMON_FLAGS="-march=native -maes -O2 -pipe -fstack-protector-strong" 
#COMMON_FLAGS="-march=native -O2 -pipe -fstack-protector-strong -fno-math-errno -fno-trapping-math -fforce-addr -finline-functions -freorder-functions -fexpensive-optimizations -falign-functions -falign-labels -falign-loops -falign-jumps -frename-registers -fweb -funit-at-a-time -fbranch-target-load-optimize -fbranch-target-load-optimize2 -Wl,-z,relro -Wl,-z,now"

# NTHREADS="auto"
# 
# GCC[lto,pgo,graphite] PASS
# COMMON_FLAGS="-march=native -O2 -pipe -fstack-protector-strong -fforce-addr -finline-functions -freorder-functions -fexpensive-optimizations -falign-functions -falign-labels -falign-loops -falign-jumps -frename-registers -fweb -funit-at-a-time: -fbranch-target-load-optimize -fbranch-target-load-optimize2"
COMMON_FLAGS="-march=ivybridge -O3 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
#LDFLAGS="${LDFLAGS} -Wl,--sort-common -Wl,--strip-all -Wl,-zcombreloc -Wl,-zrelro -Wl-znow"
#RUSTFLAGS="-C opt-level=3 -C target-cpu=ivybridge"
# NOTE: This stage was built with the bindist Use flag enabled
PORTDIR="/var/db/repos/gentoo"
DISTDIR="/var/cache/distfiles"
PKGDIR="/var/cache/binpkgs"
# PORTAGE_TMPDIR="/tmp"

# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C
LLVM_TARGETS="X86 AMDGPU"    # N card users change AMDGPU to NVPTX

#####################################################################################################
###                                                                                               ###
###                                         Custom section                                        ###
###                                                                                               ###
#####################################################################################################
# Makeopts: number of CPU cores + 1, that is, the output of the command nporc + 1
# Or memory size / 2
MAKEOPTS="-j8 -l8"
CHOST="x86_64-pc-linux-gnu"
ACCEPT_KEYWORDS="~amd64"
ACCEPT_LICENSE="*"
CPU_FLAGS_X86="aes avx f16c mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3"

GRUB_PLATFORMS="efi-64"
MICROCODE_SIGNATURES="-S"
AUTOCLEAN="yes"

# The list of L10N values that can be used is / var / db / repos / Gentoo / profiles / desc / L10N Desc
# grep -i china /var/db/repos/gentoo/profiles/desc/l10n.desc
L10N="zh-CN zh"
LINGUAS="zh_CN zh"
# Emergedefaulttops: the default option for emergency
# Both jobs and load average speed up compilation: jobs = nproc + 1 and load average = nproc ×  0.9. 
EMERGE_DEFAULT_OPTS="--jobs=8 --load-average=7.2 --ask --verbose --quiet-build --keep-going --with-bdeps=y"
PORTAGE_ELOG_CLASSES="info warn error log qa"
PORTAGE_ELOG_SYSTEM="echo save"
FEATURES="userfetch parallel-fetch candy clean-logs split-log split-elog news"

#FEATURES="${FEATURES} -userpriv -usersandbox -sandbox"

###################################
###            Hardware         ###
###################################

VIDEO_CARDS="amdgpu radeonsi"
ALSA_CARDS="hda-intel"
INPUT_DEVICES="libinput"

###################################
###            mirrors          ###
###################################

NETEASE="https://mirrors.163.com/gentoo/"
NEUSOFT="https://mirrors.neusoft.edu.cn/gentoo/"
TSINGHUA="https://mirrors.tuna.tsinghua.edu.cn/gentoo/"
CDS="http://mirrors.yun-idc.com/gentoo/"
ALI="https://mirrors.aliyun.com/gentoo/"
BIT="https://mirror.bit.edu.cn/gentoo/"
USTC="https://mirrors.ustc.edu.cn/gentoo/"

GENTOO_MIRRORS="${TSINGHUA}"

###################################
###     distfiles download      ###
###################################
#FETCHCOMMAND="wget --timeout=5 --passive-ftp --no-check-certificate -O \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
#RESUMECOMMAND="${FETCHCOMMAND}"

###################################
###     Global USE settings     ###
###################################
# profile no-multilib
# Because I'm not going to cut the profile, I need to manually add the USE required by the desktop
# Global USE should be set less
# The specific adjustment is in / etc / portage / package In USE /, set the USE of each package separately
# It can be commented out during installation, and the comment can be cancelled after the basic system is installed
#
USE="-bindist -passwdqc -xinerama -wayland -systemd"     # I only use these five when I install the system
# USE="${USE} graphite lto pgo"
# USE="${USE} udev zstd lzma zlib elogind policykit dbus udisks vdpau vulkan"
# USE="${USE} cairo fontconfig icu pango pie python savedconfig xml"
# USE="${USE} X cjk opengl infinality truetype nftables"
# USE="${USE} aac alsa ffmpeg flac mng mp3 mp4 mpeg vorbis x264 xv xvid"
# USE="${USE} exif gif jpeg jpeg2k png svg tiff"
# USE="${USE} -bluetooth -cdr -cups -debug -doc -dvdr -emboss -joystick -gnome -gnome-keyring -gtk -gtk3 -kde -plasma -ppds -sdl -static-libs-geoip -geolocation -networkmanager -jit -ldap -upower -gpm -modemmanager -gstreamer -flash -consolekit -pulseaudio -introspection -ipv6 -mono -accessibility -mms -webkit -oss -iptables"
# If make Set accept in conf_ Keywords = "~amd64", then the process will be very long
# There will probably be more than 100 packages (depending on the USE setting) that need to be compiled
# And there may be mistakes in the middle, so make Emerge is set in conf_ DEFAULT_ Opts = "-- keep going", automatically skip packages with compilation errors
# Once I opened ~ amd64 during installation, but forgot to use the time command. The whole process takes about 2-3 hours. Fortunately, everything goes well without compilation errors
# Now it's much easier to install gentoo, but the compilation time is a little longer
#
#  If there are compilation errors
#  Try making Add FEATURES="${FEATURES} -userpriv -usersandbox -sandbox" to conf, and note that this sentence will be commented out after @ world
emerge --ask --verbose --update --deep --newuse @world

Intel microcode
warning
This method is only applicable to 64 bit kernel

#Modify make conf
vi /etc/portage/make.conf
MICROCODE_SIGNATURES="-S"
emerge --ask sys-firmware/intel-microcode sys-apps/iucode_tool
#Identify the processor signature and look for the corresponding file name
#The following is copied from gentoo wiki. Select the file based on the actual signature value of CPU
iucode_tool -S -l /lib/firmware/intel-ucode/*					
	iucode_tool: system has processor(s) with signature 0x000306c3
	[...]
	microcode bundle 49: /lib/firmware/intel-ucode/06-3c-03
	[...]
	selected microcodes:
  	049/001: sig 0x000306c3, pf_mask 0x32, 2017-01-27, rev 0x0022, size 22528
#The file name is / lib / firmware / Intel ucode / 06-3c-03

#Necessary options and settings in the kernel
Processor type and features  --->
    <*> CPU microcode loading support
    [*]   Intel microcode loading support			#Note that it cannot be a module

Device Drivers  --->
  Generic Driver Options  --->
    Firmware Loader  --->
      -*-   Firmware loading facility 
      (intel-ucode/06-3c-03) Build named firmware blobs into the kernel binary 	#Program files into the kernel
      (/lib/firmware) Firmware blobs root directory (NEW)

Some settings of the new system

#Create a new user
useradd -m -G users,wheel,audio,video,portage,usb -s /bin/bash user name
passwd user name
#Solve the background color problem of eix command
emerge eix
eix-update
vi /etc/eixrc/00-eixrc

COLOR_INST_VERSION="white,1;blue|33,1;%{BG1}|black;green|30,1;%{BG3}"
BG0=none;
BG1=none;
BG2=none;
BG3=none;
COLORSCHEME0=0;
COLORSCHEME1=0;
COLORSCHEME2=0;
COLORSCHEME3=0;

If you encounter problems with the installation, you can tg group Ask the boss~

Topics: Linux