posts-go/posts/2022-12-25-archlinux.md

502 lines
11 KiB
Markdown
Raw Normal View History

2022-12-25 08:38:53 +00:00
# Install Arch Linux
2023-08-05 18:56:25 +00:00
Install Arch Linux is thing I always want to do for my laptop/PC since I had my
laptop in ninth grade.
2022-12-25 08:38:53 +00:00
2023-08-05 18:56:25 +00:00
This is not a guide for everyone, this is just save for myself in a future and
for anyone who want to walk in my shoes.
2022-12-25 08:38:53 +00:00
## [Installation guide](https://wiki.archlinux.org/index.php/Installation_guide)
### Pre-installation
Check disks carefully:
```sh
lsblk
```
[USB flash installation medium](https://wiki.archlinux.org/index.php/USB_flash_installation_medium)
#### Verify the boot mode
Check UEFI mode:
```sh
2024-07-22 19:43:33 +00:00
cat /sys/firmware/efi/fw_platform_size
# 64 or 32 is UEFI
# File not found is BIOS
2022-12-25 08:38:53 +00:00
```
#### Connect to the internet
For wifi, use [iwd](https://wiki.archlinux.org/index.php/Iwd).
#### Partition the disks
[GPT fdisk](https://wiki.archlinux.org/index.php/GPT_fdisk):
```sh
cgdisk /dev/sdx
```
2024-07-22 19:43:33 +00:00
- [Partition scheme](https://wiki.archlinux.org/index.php/Partitioning#Partition_scheme)
- [EFI system partition](https://wiki.archlinux.org/title/EFI_system_partition)
2022-12-25 08:38:53 +00:00
UEFI/GPT layout:
2024-07-22 19:43:33 +00:00
| Mount point | Partition | Partition type | Suggested size | gdisk code |
| ----------- | ------------------------------------- | ----------------------------------------- | -------------- | ---------- |
| `/mnt/efi` | `/dev/efi_system_partition` | EFI System Partition | 512 MiB | EF00 |
| `/mnt/boot` | `/dev/extended_boot_loader_partition` | Extended Boot Loader Partition (XBOOTLDR) | 1 GiB | EA00 |
| `/mnt` | `/dev/root_partition` | Root Partition | | 8300 |
2022-12-25 08:38:53 +00:00
2023-08-05 18:56:25 +00:00
Why not `/boot/efi`? See
[Lennart Poettering comment](https://github.com/systemd/systemd/pull/3757#issuecomment-234290236).
2023-05-06 07:11:26 +00:00
2022-12-25 08:38:53 +00:00
BIOS/GPT layout:
2024-07-22 19:43:33 +00:00
| Mount point | Partition | Partition type | Suggested size | gdisk code |
| ----------- | --------------------- | ------------------- | -------------- | ---------- |
| | | BIOS boot partition | 1 MiB | EF02 |
| `/mnt` | `/dev/root_partition` | Root Partition | | 8300 |
2022-12-25 08:38:53 +00:00
2024-07-22 19:43:33 +00:00
LVM (optional):
2022-12-25 08:38:53 +00:00
```sh
# Create physical volumes
pvcreate /dev/sdaX
# Create volume groups
vgcreate RootGroup /dev/sdaX /dev/sdaY
# Create logical volumes
lvcreate -l +100%FREE RootGroup -n rootvol
```
Format:
```sh
# efi
mkfs.fat -F32 /dev/efi_system_partition
# boot
mkfs.fat -F32 /dev/extended_boot_loader_partition
# root
mkfs.ext4 -L ROOT /dev/root_partition
2024-07-22 19:43:33 +00:00
# root with btrfs (optional)
2022-12-25 08:38:53 +00:00
mkfs.btrfs -L ROOT /dev/root_partition
2024-07-22 19:43:33 +00:00
# root on lvm (optional)
2022-12-25 08:38:53 +00:00
mkfs.ext4 /dev/RootGroup/rootvol
```
Mount:
```sh
# root
mount /dev/root_partition /mnt
2024-07-22 19:43:33 +00:00
# root with btrfs (optional)
2022-12-25 08:38:53 +00:00
mount -o compress=zstd /dev/root_partition /mnt
2024-07-22 19:43:33 +00:00
# root on lvm (optional)
2022-12-25 08:38:53 +00:00
mount /dev/RootGroup/rootvol /mnt
# efi
mount --mkdir /dev/efi_system_partition /mnt/efi
# boot
mount --mkdir /dev/extended_boot_loader_partition /mnt/boot
```
### Installation
2024-07-22 19:43:33 +00:00
Please check [Mirrors](https://wiki.archlinux.org/title/Mirrors) if you have
slow Internet.
2022-12-25 08:38:53 +00:00
```sh
pacstrap -K /mnt base linux linux-firmware
2024-07-22 19:43:33 +00:00
# AMD (optional)
2022-12-25 08:38:53 +00:00
pacstrap -K /mnt amd-ucode
2024-07-22 19:43:33 +00:00
# Intel (optional)
2022-12-25 08:38:53 +00:00
pacstrap -K /mnt intel-ucode
2024-07-22 19:43:33 +00:00
# Btrfs (optional)
2022-12-25 08:38:53 +00:00
pacstrap -K /mnt btrfs-progs
2024-07-22 19:43:33 +00:00
# LVM (optional)
2022-12-25 08:38:53 +00:00
pacstrap -K /mnt lvm2
2024-07-22 19:48:45 +00:00
# zsh (optional)
pacstrap -K /mnt zsh
2022-12-25 08:38:53 +00:00
# Text editor
pacstrap -K /mnt neovim
```
### Configure
#### [fstab](https://wiki.archlinux.org/index.php/Fstab)
```sh
genfstab -U /mnt >> /mnt/etc/fstab
```
#### Chroot
```sh
arch-chroot /mnt
```
#### Time zone
```sh
2024-07-22 19:43:33 +00:00
# Change Region/City to your location
2022-12-25 08:38:53 +00:00
ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
hwclock --systohc
```
#### Localization:
2024-07-22 19:43:33 +00:00
Edit `/etc/locale.gen` then uncomment `# en_US.UTF-8 UTF-8` by removing `#` at
the beginning.
2022-12-25 08:38:53 +00:00
Generate locales:
```sh
locale-gen
```
Edit `/etc/locale.conf`:
```txt
LANG=en_US.UTF-8
```
#### Network configuration
Edit `/etc/hostname`:
```txt
myhostname
```
#### Initramfs
Edit `/etc/mkinitcpio.conf`:
```txt
# https://wiki.archlinux.org/title/mkinitcpio#Common_hooks
# Replace udev with systemd
2024-08-03 20:30:18 +00:00
#
# LVM (optional)
# https://wiki.archlinux.org/title/Install_Arch_Linux_on_LVM#Adding_mkinitcpio_hooks
2024-07-22 19:43:33 +00:00
# Add lvm2 between block and filesystems
2024-08-03 20:30:18 +00:00
#
2024-07-22 19:43:33 +00:00
HOOKS=(base systemd ... block lvm2 filesystems)
2022-12-25 08:38:53 +00:00
```
```sh
mkinitcpio -P
```
#### Root password
```sh
passwd
```
2024-07-22 19:43:33 +00:00
#### [NetworkManager](https://wiki.archlinux.org/title/NetworkManager)
2023-01-07 16:57:51 +00:00
2022-12-25 08:38:53 +00:00
```sh
2023-01-07 16:57:51 +00:00
pacman -Syu networkmanager dhcpcd iwd
2022-12-25 08:38:53 +00:00
systemctl enable NetworkManager.service
2023-01-07 16:57:51 +00:00
systemctl enable systemd-resolved.service
```
Edit `/etc/NetworkManager/conf.d/wifi_backend.conf`:
```txt
[device]
wifi.backend=iwd
```
2024-08-03 20:30:18 +00:00
Edit `/etc/NetworkManager/conf.d/wifi_rand_mac.conf`:
```txt
[device-mac-randomization]
wifi.scan-rand-mac-address=yes
[connection-mac-randomization]
ethernet.cloned-mac-address=stable
wifi.cloned-mac-address=stable
```
2024-07-22 19:43:33 +00:00
#### [Bluetooth](https://wiki.archlinux.org/title/Bluetooth)
2022-12-25 08:38:53 +00:00
2023-01-07 16:57:51 +00:00
```sh
2022-12-25 08:38:53 +00:00
pacman -Syu bluez
systemctl enable bluetooth.service
2023-01-07 16:57:51 +00:00
```
2024-07-22 19:43:33 +00:00
#### Clock
Use [systemd-timesyncd](https://wiki.archlinux.org/title/Systemd-timesyncd)
2022-12-25 08:38:53 +00:00
2023-01-07 16:57:51 +00:00
```sh
2022-12-25 08:38:53 +00:00
timedatectl set-ntp true
2024-07-22 19:43:33 +00:00
timedatectl status
2022-12-25 08:38:53 +00:00
```
#### Boot loader
2024-07-22 19:43:33 +00:00
Use [systemd-boot](https://wiki.archlinux.org/index.php/Systemd-boot)
2022-12-25 08:38:53 +00:00
2023-01-07 16:57:51 +00:00
Install using XBOOTLDR:
```sh
bootctl --esp-path=/efi --boot-path=/boot install
systemctl enable systemd-boot-update.service
```
[Label partition](https://wiki.archlinux.org/index.php/persistent_block_device_naming#by-label)
Edit `/efi/loader/loader.conf`:
```txt
default archlinux.conf
timeout 4
editor no
console-mode max
```
Edit `/boot/loader/entries/archlinux.conf`:
```txt
title Arch Linux
linux /vmlinuz-linux
2024-07-22 19:43:33 +00:00
# Intel (optional)
2023-01-07 16:57:51 +00:00
initrd /intel-ucode.img
2024-07-22 19:43:33 +00:00
# AMD (optional)
2023-01-07 16:57:51 +00:00
initrd /amd-ucode.img
initrd /initramfs-linux.img
2024-07-22 19:43:33 +00:00
# Kernel parameters (optional)
2023-01-07 16:57:51 +00:00
#
# Acer Nitro AN515-45
# https://wiki.archlinux.org/title/backlight#Kernel_command-line_options
# acpi_backlight=vendor
#
# NVIDIA
# https://wiki.archlinux.org/title/NVIDIA#DRM_kernel_mode_setting
# nvidia-drm.modeset=1
2024-08-03 20:30:18 +00:00
#
options root="LABEL=ROOT" rw quiet loglevel=3 nowatchdog module_blacklist=iTCO_wdt,sp5100_tco ipv6.disable=1 init_on_alloc=1 init_on_free=1 page_alloc.shuffle=1
2023-01-07 16:57:51 +00:00
```
2022-12-25 08:38:53 +00:00
## [General recommendations](https://wiki.archlinux.org/index.php/General_recommendations)
Always remember to check **dependencies** when install packages.
### System administration
[Sudo](https://wiki.archlinux.org/index.php/sudo):
```sh
pacman -Syu sudo
EDITOR=nvim visudo
2024-07-22 19:43:33 +00:00
# Uncomment group wheel by removing % at the beginning of %wheel ...
2022-12-25 08:38:53 +00:00
# Add user if don't want to use systemd-homed
useradd -m -G wheel -c "The Joker" joker
2024-07-22 19:43:33 +00:00
# Or using zsh (optional)
2022-12-25 08:38:53 +00:00
useradd -m -G wheel -s /usr/bin/zsh -c "The Joker" joker
# Set password
passwd joker
```
2024-07-22 19:48:45 +00:00
- [systemd-homed (optional if no useradd before)](https://wiki.archlinux.org/index.php/Systemd-homed):
- [Home Directories](https://systemd.io/HOME_DIRECTORY/)
2022-12-25 08:38:53 +00:00
```sh
systemctl enable systemd-homed.service
homectl create joker --real-name="The Joker" --member-of=wheel
2024-07-22 19:43:33 +00:00
# Using zsh (optional)
2022-12-25 08:38:53 +00:00
homectl update joker --shell=/usr/bin/zsh
```
2023-08-05 18:56:25 +00:00
**Note**: Can not run `homectl` when install Arch Linux. Should run on the first
boot.
2022-12-25 08:38:53 +00:00
### Desktop Environment
Install [Xorg](https://wiki.archlinux.org/index.php/Xorg):
```sh
pacman -Syu xorg-server
2024-08-03 20:30:18 +00:00
# Remember to install GPU driver
2022-12-25 08:38:53 +00:00
```
2024-08-03 20:30:18 +00:00
#### [KDE](https://wiki.archlinux.org/title/KDE)
See
[KDE Distributions/Packaging Recommendations](https://community.kde.org/Distributions/Packaging_Recommendations)
2022-12-25 08:38:53 +00:00
```sh
2024-08-03 20:30:18 +00:00
pacman -Syu plasma-desktop
2022-12-25 08:38:53 +00:00
# Login manager
2024-08-03 20:30:18 +00:00
pacman -Syu sddm
2022-12-25 08:38:53 +00:00
```
2024-08-06 09:16:03 +00:00
#### Worth trying
- [COSMIC](https://wiki.archlinux.org/title/COSMIC)
- [Pantheon](https://wiki.archlinux.org/title/Pantheon)
2022-12-25 08:38:53 +00:00
## [List of applications](https://wiki.archlinux.org/index.php/List_of_applications)
### [pacman](https://wiki.archlinux.org/index.php/pacman)
Uncomment in `/etc/pacman.conf`:
```txt
# Misc options
Color
ParallelDownloads
```
2024-07-22 19:57:31 +00:00
```sh
systemctl enable paccache.timer
```
2024-07-22 19:43:33 +00:00
### [Pipewire](https://wiki.archlinux.org/title/PipeWire)
2022-12-25 08:38:53 +00:00
```sh
pacman -Syu pipewire wireplumber \
pipewire-alsa pipewire-pulse \
gst-plugin-pipewire pipewire-v4l2
```
2023-08-05 18:56:25 +00:00
See
[Advanced Linux Sound Architecture](https://wiki.archlinux.org/title/Advanced_Linux_Sound_Architecture)
2023-01-08 10:50:11 +00:00
```sh
pacman -Syu sof-firmware
```
2024-07-22 19:43:33 +00:00
### [Flatpak](https://wiki.archlinux.org/title/Flatpak)
2022-12-25 08:38:53 +00:00
```sh
pacman -Syu flatpak
```
## [Improving performance](https://wiki.archlinux.org/index.php/improving_performance)
2023-09-05 17:27:15 +00:00
- https://wiki.archlinux.org/index.php/swap#Swap_file
- https://wiki.archlinux.org/index.php/swap#Swappiness
- https://wiki.archlinux.org/index.php/Systemd/Journal#Journal_size_limit
- https://wiki.archlinux.org/index.php/Core_dump#Disabling_automatic_core_dumps
2024-08-03 20:30:18 +00:00
- https://wiki.archlinux.org/title/Ext4#Enabling_fast_commit_in_existing_filesystems
2023-09-05 17:27:15 +00:00
- https://wiki.archlinux.org/index.php/Solid_state_drive#Periodic_TRIM
- https://wiki.archlinux.org/index.php/Silent_boot
- https://wiki.archlinux.org/title/Improving_performance#Watchdogs
2024-08-03 20:30:18 +00:00
- https://wiki.archlinux.org/title/Sysctl#Enable_TCP_Fast_Open
- [Fast commits for ext4](https://lwn.net/Articles/842385/)
- [TCP Fast Open: expediting web services](https://lwn.net/Articles/508865/)
- [The search for the correct amount of split-lock misery](https://lwn.net/Articles/911219/)
Edit `/etc/systemd/journald.conf.d/00-journal-size.conf` then restart:
```txt
[Journal]
SystemMaxUse=50M
```
2023-09-30 16:03:13 +00:00
2024-08-03 20:30:18 +00:00
Edit `/etc/systemd/coredump.conf.d/custom.conf` then restart:
2023-09-30 16:03:13 +00:00
```txt
2024-08-03 20:30:18 +00:00
[Coredump]
Storage=none
ProcessSizeMax=0
```
Enable ext4 fast commit:
```sh
tune2fs -O fast_commit /dev/partition
```
Periodic TRIM:
```sh
systemctl enable fstrim.timer
```
Edit `/etc/sysctl.d/99-sysctl.conf`:
```txt
# Enable TCP Fast Open
net.ipv4.tcp_fastopen = 3
2023-09-30 16:03:13 +00:00
kernel.split_lock_mitigate = 0
```
2022-12-25 08:38:53 +00:00
2024-08-03 20:30:18 +00:00
## [Security](https://wiki.archlinux.org/title/Security)
- https://wiki.archlinux.org/title/IPv6#Disable_IPv6
- [add init_on_alloc/init_on_free boot options](https://lwn.net/Articles/791380/)
- [mm: Randomize free memory](https://lwn.net/Articles/776228/)
- [mm: introduce Designated Movable Blocks](https://lwn.net/Articles/925941/)
```sh
# Kernel parameters
```
2023-09-05 17:27:15 +00:00
## Hardware dependent
2022-12-25 08:38:53 +00:00
2023-09-05 17:27:15 +00:00
- https://wiki.archlinux.org/title/Laptop
- https://wiki.archlinux.org/title/ASUS_Linux
- https://wiki.archlinux.org/title/PRIME
2022-12-25 08:38:53 +00:00
2023-09-05 17:27:15 +00:00
## Experiment
2022-12-25 08:38:53 +00:00
2023-09-05 17:27:15 +00:00
Do it at your own risk!!!
2022-12-25 08:38:53 +00:00
2024-08-03 20:30:18 +00:00
- https://wiki.archlinux.org/title/Unified_kernel_image
2023-11-09 08:56:45 +00:00
- https://wiki.archlinux.org/title/Pacman/Pacnew_and_Pacsave
2024-08-03 20:30:18 +00:00
- [Linux Hardening Guide](https://madaidans-insecurities.github.io/guides/linux-hardening.html)
- https://github.com/GrapheneOS/hardened_malloc
2023-09-05 17:27:15 +00:00
- https://github.com/AdnanHodzic/auto-cpufreq
- https://github.com/nbfc-linux/nbfc-linux
2022-12-25 08:38:53 +00:00
2024-07-22 19:57:31 +00:00
## Maintenance
See
[pacman/Tips and tricks](https://wiki.archlinux.org/title/Pacman/Tips_and_tricks)
```sh
sudo pacman -Syu
```
2022-12-25 08:38:53 +00:00
## In the end
This guide is updated regularly I promise.