archlinux-installation-standard
My standards of install Arch Linux.
Pre-installation
-
Update the system clock
1
timedatectl set-ntp true
-
Preparing the partitions
Partition layout:
1
2
3
4
5
6
7
8
9
10+-----------------------+------------------------+
| Boot partition | LUKS2 encrypted system |
| | partition |
| | |
| /boot | / |
| | |
| | /dev/mapper/cryptroot |
|-----------------------|------------------------|
| /dev/sda1 | /dev/sda2 |
+-----------------------+------------------------+Preparing non-boot partitions
1
2
3
4
5cryptsetup -y -v --pbkdf-memory=114514 luksFormat /dev/sda2
cryptsetup open /dev/sda2 cryptroot
cryptsetup --allow-discards --perf-no_read_workqueue --perf-no_write_workqueue --persistent refresh cryptroot
mkfs.btrfs -L arch_os /dev/mapper/cryptroot
mount /dev/mapper/cryptroot /mntYou can set the filesystem label later by using
btrfs filesystem label /dev/mapper/cryptroot "arch_os"
Preparing the boot partition
1
mkfs.fat -F32 /dev/sda1
Btrfs subvolumes
- Create top-level subvolumes
1
2
3
4btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@snapshots
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@var_log - Mount top-level subvolumes
Unmount the system partition at /mnt.Now mount the newly created subvolumes by using the1
umount /mnt
subvol=
mount option (with enabled compresszstd
).1
2
3
4
5
6mount -o compress=zstd,subvol=@,discard=async /dev/mapper/cryptroot /mnt
mkdir -p /mnt/{boot,home,.snapshots,var/log}
mount -o discard /dev/sda1 /mnt/boot
mount -o compress=zstd,subvol=@home,discard=async /dev/mapper/cryptroot /mnt/home
mount -o compress=zstd,subvol=@snapshots,discard=async /dev/mapper/cryptroot /mnt/.snapshots
mount -o compress=zstd,subvol=@var_log,discard=async /dev/mapper/cryptroot /mnt/var/log - Create nested subvolumes
Create any nested subvolumes you do not want to have snapshots when taking a snapshot of/
.
Every nested subvolume will be an empty directory inside the snapshot.1
2
3mkdir -p /mnt/var/cache/pacman
btrfs subvolume create /mnt/var/cache/pacman/pkg
btrfs subvolume create /mnt/var/tmp
Installation
- Select mirrors
1
sed -i '1iServer = https://mirrors.cloud.tencent.com/archlinux/$repo/os/$arch' /etc/pacman.d/mirrorlist
- Install essential packages
1
2
3
4
5
6
7
8
9
10pacstrap -K /mnt base linux linux-firmware \
rng-tools openssh zram-generator bluez bluez-utils iwd zerotier-one \
btrfs-progs tmux bash-completion udisks2 btop man rsync tealdeer \
zsh{,-autosuggestions,-syntax-highlighting,-history-substring-search} \
pipewire wireplumber pipewire-alsa pipewire-pulse \
base-devel git gvim ripgrep fzf ctags \
vulkan-tools libva-utils hyfetch \
xorg-server bspwm sxhkd ly polybar xdo xorg-xrdb picom rofi redshift flameshot alacritty feh \
noto-fonts{,-cjk,-emoji} \
fcitx5-im fcitx5-chinese-addons
Configure the system
1 | genfstab -U /mnt >> /mnt/etc/fstab |
Installing the EFI boot manager
1 | bootctl install |
Configuring the boot loader
1 | default arch.conf |
1 | title Arch Linux |
1 | title Arch Linux (fallback) |
AUR helper paru.
- [Optional] Create makepkg wrapper
makepkg-shallow
to make makepkg do shallow clone/usr/bin/makepkg-shallow 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16!/bin/bash
git() {
if [[ $# -gt 1 && $1 == 'clone' && $2 != '-s' ]]; then
/bin/git "$@" --depth=1 --no-single-branch
elif [[ $# -gt 1 && $1 == 'fetch' ]]; then
/bin/git fetch --depth=3 -p
elif [[ $# -gt 1 && [$1 == 'describe' || $1 == 'rev-list'] ]]; then
/bin/git fetch --unshallow -p
/bin/git "$@"
else
/bin/git "$@"
fi
}
source /bin/makepkg "$@" - Build & Install paru
1
2
3
4
5
6
7
8
9
10chmod 755 /usr/bin/makepkg-shallow
mkdir /build
chown -R <Username>:<Username> /build
cd /build
sudo -u <Username> git clone --depth=1 https://aur.archlinux.org/paru.git
cd paru
sudo -u <Username> makepkg-shallow --noconfirm -si
pacman -Qtdq | xargs -r pacman --noconfirm -Rcns
rm -rf /home/<Username>/.cache
rm -rf /build
Reboot to installed system to ensure that systemd is running.
Post-installation
Enable daemons
1 | systemctl enable --now iwd.service |
Enroll TPM key
list installed TPMs and the driver in use:
1 | systemd-cryptenroll --tpm2-device=list |
If you encounter messages such as “TPM2 support is not installed”, try install
tpm2-tss
.
Binds the key to PCRs 0 and 7 (System firmware and Secure Boot state):
1 | systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=0+7 /dev/sda2 |
Regenerate the initramfs:
1 | mkinitcpio -P |
To remove a key enrolled, run:
1 systemd-cryptenroll /dev/sdX --wipe-slot=slot_numberwhere
slot_number
is the numeric LUKS slot number in which your TPM key is stored.
Alternatively, run:
1 systemd-cryptenroll /dev/sdX --wipe-slot=tpm2to remove all TPM-associated keys from your LUKS volume.
Swapfile in a btrfs filesystem and enable hibernation (support dm-crypt)
-
Swap file creation
1
2btrfs filesystem mkswapfile --size 32g --uuid clear /.snapshots/swapfile
swapon /.snapshots/swapfileAdd appropriate entry in
fstab
:/etc/fstab 1
2...
/.snapshots/swapfile none swap defaults 0 0 -
Setting the required kernel parameters
1
2btrfs inspect-internal map-swapfile -r /swap/swapfile
198122980Finally, edit the bootloader’s configuration:
/boot/loader/entries/arch.conf 1
2...
options ... resume=/dev/mapper/cryptroot resume_offset=198122980
Secure Boot by using a signed boot loader (shim)
Install shim-signed
[AUR], sbsigntools
and efibootmgr
1 | paru -S shim-signed sbsigntools efibootmgr |
As shim tries to launch grubx64.efi
, rename systemd boot loader to it.
1 | cp /boot/EFI/systemd/systemd-bootx64.efi /boot/EFI/BOOT/grubx64.efi |
Copy shim and MokManager to boot loader directory:
1 | cp /usr/share/shim-signed/shimx64.efi /boot/EFI/BOOT/BOOTx64.EFI |
(Optional) create a new NVRAM entry to boot BOOTx64.EFI
:
1 | efibootmgr --verbose --disk /dev/sda --part 1 --create --label "Shim" --loader /EFI/BOOT/BOOTx64.EFI |
Generate a Machine Owner Key:
1 | openssl req -newkey rsa:4096 -nodes -keyout MOK.key -new -x509 -sha256 -days 3650 -subj "/CN=my Machine Owner Key/" -out MOK.crt |
Sign boot loader (named grubx64.efi
) and kernel:
1 | sbsign --key MOK.key --cert MOK.crt --output /boot/vmlinuz-linux /boot/vmlinuz-linux |
Copy MOK.cer
to a FAT formatted file system (Here I use EFI system partition).
1 | cp MOK.cer /boot/ |
Reboot and enable Secure Boot. If shim does not find the certificate grubx64.efi
is signed with in MokList it will launch MokManager (mmx64.efi
).
In MokManager select Enroll key from disk, find MOK.cer
and add it to MokList. When done select Continue boot and your boot loader will launch and it will be capable launching any binary signed with your Machine Owner Key.
NVIDIA & NVIDIA Optimus
Using PRIME render offload
which was official method supported by NVIDIA
- The nvidia-prime package provides a script that can be used to run programs on the NVIDIA card.To run a program on the NVIDIA card you can use the prime-run command:
1
pacman -S nvidia nvidia-prime
1
2prime-run glxinfo | grep "OpenGL renderer"
prime-run vulkaninfo - Dynamic power management of the dGPU
-
Enable runtime power management for each PCI function
1
2echo auto > /sys/bus/pci/devices/<Domain>:<Bus>:<Device>.<Function>/power/control
modprobe nvidia "NVreg_DynamicPowerManagement=0x02" -
The automated ways to perform the manual steps mentioned above so that this feature works seamlessly after boot:
- Create a file named
80-nvidia-pm.rules
in/lib/udev/rules.d/
directory/lib/udev/rules.d/80-nvidia-pm.rules 1
2
3
4
5
6
7
8# Remove NVIDIA Audio devices, if present
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{remove}="1"
# Enable runtime PM for NVIDIA VGA/3D controller devices on driver bind
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="auto"
# Disable runtime PM for NVIDIA VGA/3D controller devices on driver unbind
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="on"You can use
udevadm info --attribute-walk --path=/sys/bus/pci/devices/<Domain>\:<Bus>\:<Slot>.<Function>
to get a PCI device’s attribution - Set the driver option via the kernel module configuration files
/etc/modprobe.d/nvidia.conf 1
options nvidia "NVreg_DynamicPowerManagement=0x02"
- Reboot the system
- Create a file named
-
Tips
-
Run
fc-cache -fv
to rebuild font information cache files. -
Use
blkid
orlsblk -f
to see the persistent block device naming -
Use
ip link
to show network interface names -
Configure memory pressure killing (Here I set it slice wide to make it observable in
oomctl
):shell 1
systemctl edit user.slice
Having this in your editor:
1
2
3[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50% -
Configure swap-based killing:
1
systemctl edit --force -- -.slice
With this in your edior:
1
2[Slice]
ManagedOOMSwap=kill(Optional) See also oomd.conf(5):
/etc/systemd/oomd.conf 1
2
3[OOM]
SwapUsedLimit=80%
DefaultMemoryPressureDurationSec=20sFurthmore, you can set
OOMPolicy=kill
to a service unit, which says if one of the process belong to this service is being killed by systemd-oomd, the whole service will also get killed (this option sets service’s cgroupmemory.oom.group
to1
, which means all tasks belonging to this cgroup were killed together).
1 | [AUR] fcitx5-pinyin-zhwiki |
archlinux-installation-standard
http://blog.ndoskrnl.net/zh-cn/computer/2020/archlinux-installation-standard/