wiki-grav/pages/02.linux/guides/arch/default.en.md

428 lines
8.2 KiB
Markdown
Raw Normal View History

---
title: Arch
visible: true
---
[toc]
2022-12-16 11:50:40 +01:00
## Keyboard layout
2022-12-16 11:50:40 +01:00
`loadkeys de_CH-latin1`
## Check UEFI mode
2022-12-16 11:50:40 +01:00
If the following command works, the system is booted in EFI.
2022-12-16 11:50:40 +01:00
`ls /sys/firmware/efi/efivars`
## Verify internet connection
2022-12-16 11:50:40 +01:00
`ping www.realstickman.net`
## Update system clock
2022-12-16 11:50:40 +01:00
`timedatectl set-ntp true`
## Creating partitions
2022-12-16 11:50:40 +01:00
`cfdisk`
Use `EFI System` for EFI partition
2022-12-16 11:50:40 +01:00
Use `Linux filesystem` for other partitions
## (LUKS) Create encrypted partition
2022-12-16 11:50:40 +01:00
_Note: Do not put your /efi partition on an encrypted partition!_
Create encrypted Partition
2022-12-16 11:50:40 +01:00
`cryptsetup luksFormat /dev/(partition) --type luks1`
To view if this worked correctly
2022-12-16 11:50:40 +01:00
`cryptsetup luksDump /dev/(partition)`
Open the partition
Give it a fitting name
2022-12-16 11:50:40 +01:00
`cryptsetup open /dev/(partition) (name)`
Check if this worked with `ls /dev/mapper/`
2022-12-16 11:50:40 +01:00
The name should show up there
## Format partitions
2022-12-16 11:50:40 +01:00
Fat 32:
`mkfs.fat -F32 /dev/(partition)`
2022-12-16 11:50:40 +01:00
_For EFI or BOOT partition_
Ext4:
`mkfs.ext4 /dev/(partition)`
2022-12-16 11:50:40 +01:00
_All other partitions_
btrfs:
`mkfs.btrfs /dev/(partition)`
2022-12-16 11:50:40 +01:00
_All other partitions_
F2FS:
`mkfs.f2fs -O extra_attr,inode_checksum,sb_checksum,compression /dev/(partition)`
2022-12-16 11:50:40 +01:00
_All other partitions_
## Mounting partitions
2022-12-16 11:50:40 +01:00
Generally partitions have to be mounted where you will later use them in your system.
BTRFS with its subvolumes is a special case
2022-12-16 11:50:40 +01:00
For EFI, prefer the /efi mountpoint
```
Root: /mnt
EFI: /mnt/efi or /mnt/boot
Home: /mnt/home
etc...
```
### (BTRFS) Btrfs preparation of subvolumes and mounting
2022-12-16 11:50:40 +01:00
Mount root partition
2022-12-16 11:50:40 +01:00
`mount /dev/(partition) /mnt`
Root subvolume
2022-12-16 11:50:40 +01:00
`btrfs subv create /mnt/@`
Home subvolume
2022-12-16 11:50:40 +01:00
`btrfs subv create /mnt/@home`
Snapshots subvolume for snapper
2022-12-16 11:50:40 +01:00
`btrfs subv create /mnt/@snapshots`
2022-06-05 15:14:33 +02:00
Snapshots subvolume for timeshift
2022-12-16 11:50:40 +01:00
`btrfs subv create /mnt/@timeshift`
Var subvolume
2022-12-16 11:50:40 +01:00
`btrfs subv create /mnt/@var_log`
2022-12-16 11:50:40 +01:00
_If you want to use a swapfile with Snapper, create a new subvolume now_
Swap subvolume
2022-12-16 11:50:40 +01:00
`btrfs subv create /mnt/@swap`
2022-12-16 11:50:40 +01:00
`umount /mnt`
Mount root
2022-12-16 11:50:40 +01:00
`mount -o noatime,compress-force=zstd,space_cache=v2,subvol=@ /dev/(partition) /mnt`
With /efi
`mkdir -p /mnt/{efi,home,.snapshots,var/log,swap}`
With /boot
`mkdir -p /mnt/{boot,home,.snapshots,var/log,swap}`
With /boot and timeshift
2022-12-16 11:50:40 +01:00
`mkdir -p /mnt/{boot,home,timeshift-btrfs,var/log,swap}`
Mount home
`mount -o noatime,compress-force=zstd,space_cache=v2,subvol=@home /dev/(partition) /mnt/home`
Mount snapshots for snapper
`mount -o noatime,compress-force=zstd,space_cache=v2,subvol=@snapshots /dev/(partition) /mnt/.snapshots`
Mount snapshots for timeshift
2022-12-16 11:50:40 +01:00
`mount -o noatime,compress-force=zstd,space_cache=v2,subvol=@timeshift /dev/(partition) /mnt/timeshift-btrfs`
Mount var
`mount -o noatime,compress-force=zstd,space_cache=v2,subvol=@var_log /dev/(partition) /mnt/var/log`
Swap subvolume
2022-12-16 11:50:40 +01:00
`mount -o noatime,compress-force=zstd,space_cache=v2,subvol=@swap /dev/(partition) /mnt/swap`
2022-12-16 11:50:40 +01:00
**Don't forget mounting other partitions!!**
### (F2FS) Mounting
2022-12-16 11:50:40 +01:00
Mount partition with compression algorithm specified
2022-12-16 11:50:40 +01:00
`mount -o compress_algorithm=zstd /dev/(partition) /mnt`
With /efi
`mkdir -p /mnt/efi`
With /boot
2022-12-16 11:50:40 +01:00
`mkdir -p /mnt/boot`
2022-12-16 11:50:40 +01:00
**Don't forget mounting other partitions!!**
## Swap
2022-12-16 11:50:40 +01:00
### Swap partition
2022-12-16 11:50:40 +01:00
TODO
### Swapfile
2022-12-16 11:50:40 +01:00
#### Normal way
2022-12-16 11:50:40 +01:00
**NOT FOR BTRFS!**
2022-12-16 11:50:40 +01:00
`dd if=/dev/zero of=/mnt/swapfile bs=1M count=(size) status=progress`
#### (BTRFS) Swapfile in btrfs
2022-12-16 11:50:40 +01:00
_Does not work with snapper_
_Use a separate subvolume in that case_
```sh
truncate -s 0 /mnt/swapfile
chattr +C /mnt/swapfile
btrfs property set /mnt/swapfile compression none
fallocate -l (size)M /mnt/swapfile
```
#### Initialising swapfile
```sh
chmod 600 /mnt/swapfile
mkswap /mnt/swapfile
swapon /mnt/swapfile
```
## Essential packages
2022-12-16 11:50:40 +01:00
Some things like the userspace utilities for file management will vary.
See [file systems](https://wiki.archlinux.org/index.php/File_systems#Types_of_file_systems)
2022-12-16 11:50:40 +01:00
`pacstrap /mnt base linux linux-firmware vim git openssh networkmanager network-manager-applet dialog base-devel linux-headers`
### Microcode
2022-12-16 11:50:40 +01:00
`amd-ucode`
`intel-ucode`
### Filesystems
2022-12-16 11:50:40 +01:00
Fat32:
2022-12-16 11:50:40 +01:00
`dosfstools mtools`
Ext4:
2022-12-16 11:50:40 +01:00
`e2fsprogs`
Btrfs:
2022-12-16 11:50:40 +01:00
`btrfs-progs compsize`
F2FS:
2022-12-16 11:50:40 +01:00
`f2fs-tools`
### Wifi
2022-12-16 11:50:40 +01:00
`wpa_supplicant`
### Snapper
2022-12-16 11:50:40 +01:00
`snapper`
### Certificates
2022-12-16 11:50:40 +01:00
`ca-certificates ca-certificates-mozilla`
### other
2022-12-16 11:50:40 +01:00
`cups hplip xdg-utils xdg-user-dirs inetutils`
## Generate fstab
2022-12-16 11:50:40 +01:00
`genfstab -U /mnt >> /mnt/etc/fstab`
2022-12-16 11:50:40 +01:00
**Make sure the fstab file has everything included**
## Chroot into the system
2022-12-16 11:50:40 +01:00
`arch-chroot /mnt`
## Set timezone
2022-12-16 11:50:40 +01:00
`ln -sf /usr/share/zoneinfo/Europe/Zurich /etc/localtime`
## Set hardware clock
2022-12-16 11:50:40 +01:00
`hwclock --systohc`
## Set locale
2022-12-16 11:50:40 +01:00
`vim /etc/locale.gen`
Uncomment the locales that should be generated.
2022-12-16 11:50:40 +01:00
Make sure to use a UTF-8 entry.
2022-12-16 11:50:40 +01:00
`locale-gen`
2022-12-16 11:50:40 +01:00
`echo "LANG=de_CH.UTF-8" > /etc/locale.conf`
## Set keymap permanently
2022-12-16 11:50:40 +01:00
`echo "KEYMAP=de_CH-latin1" > /etc/vconsole.conf`
## Set hostname
2022-12-16 11:50:40 +01:00
`echo "(hostname)" > /etc/hostname`
Edit `/etc/hosts`
```
127.0.0.1 localhost
::1 localhost
127.0.1.1 (hostname).localdomain (hostname)
```
## Change root password
2022-12-16 11:50:40 +01:00
`passwd`
## Bootloader installation
2022-12-16 11:50:40 +01:00
### GRUB UEFI
2022-12-16 11:50:40 +01:00
`pacman -S grub efibootmgr`
If you are using encryption, see the next section first. **Make sure to come back here again though**
`grub-install --target=x86_64-efi --efi-directory=(efi partition mountpoint) --bootloader-id=GRUB`
2022-12-16 11:50:40 +01:00
`grub-mkconfig -o /boot/grub/grub.cfg`
#### (LUKS) Encryption with /efi
2022-12-16 11:50:40 +01:00
Create keyfile and add it to mkinitcpio.conf
2022-12-16 11:50:40 +01:00
`dd bs=512 count=4 if=/dev/random of=/crypto_keyfile.bin iflag=fullblock`
2022-12-16 11:50:40 +01:00
`chmod 600 /crypto_keyfile.bin`
**This command should be run after installing a new kernel!**
2022-12-16 11:50:40 +01:00
`chmod 600 /boot/initramfs-linux*`
2022-12-16 11:50:40 +01:00
`cryptsetup luksAddKey /dev/(partition) /crypto_keyfile.bin`
Include the file in `/etc/mkinitcpio.conf`
2022-12-16 11:50:40 +01:00
`FILES=(/crypto_keyfile.bin)`
2022-12-16 11:50:40 +01:00
Edit the `HOOKS` section as well. _Example:_
`HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems fsck)`
2022-12-16 11:50:40 +01:00
`mkinitcpio -p linux`
Edit `/etc/default/grub`
2022-12-16 11:50:40 +01:00
`GRUB_ENABLE_CRYPTODISK=y`
Some options in `GRUB_CMDLINE_LINUX_DEFAULT`
**Make sure to change /dev/(partition) to UUID ASAP!**
2022-12-16 11:50:40 +01:00
_Not sure how to actually do that though, will have to read some more._
`cryptdevice=/dev/(partition):(name)`
2022-12-16 11:50:40 +01:00
`cryptkey=/dev/mapper/(name):(filesystem):/crypto_keyfile.bin`
2022-12-16 11:50:40 +01:00
**Go back and install grub!!**
#### (LUKS) Encryption with /boot
2022-12-16 11:50:40 +01:00
Edit the `HOOKS` section in `/etc/mkinitcpio.conf` _Example:_
`HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems fsck)`
2022-12-16 11:50:40 +01:00
`mkinitcpio -p linux`
Next, edit `/etc/default/grub`
Add an option in `GRUB_CMDLINE_LINUX_DEFAULT`
**Make sure to change /dev/(partition) to UUID ASAP!**
2022-12-16 11:50:40 +01:00
_Not sure how to actually do that though, will have to read some more._
`cryptdevice=/dev/(partition):(name)`
2022-12-16 11:50:40 +01:00
**Go back and install grub!!**
## Mkinitcpio
### BTRFS
2022-12-16 11:50:40 +01:00
Load required modules
`vim /etc/mkinitcpio.conf`
`MODULES=(btrfs)`
2022-12-16 11:50:40 +01:00
`BINARIES=("/usr/bin/btrfs")`
2022-12-16 11:50:40 +01:00
`mkinitcpio -p linux`
2022-12-16 11:50:40 +01:00
**Go back and install grub!!**
### EXT4
### F2FS
## Networking
2022-12-16 11:50:40 +01:00
`systemctl enable NetworkManager`
## (CUPS) Printing
2022-12-16 11:50:40 +01:00
`systemctl enable cups`
## Add user
2022-12-16 11:50:40 +01:00
`useradd -mG wheel (user)`
Set password
2022-12-16 11:50:40 +01:00
`passwd (user)`
### Enable sudo
2022-12-16 11:50:40 +01:00
`visudo`
2022-12-16 11:50:40 +01:00
Uncomment `%wheel ALL=(ALL) ALL`
## Finishing installation
2022-12-16 11:50:40 +01:00
`exit`
`poweroff`
2022-12-16 11:50:40 +01:00
Remove the installation cd
## (Snapper) Setup
2022-12-16 11:50:40 +01:00
`# umount /.snapshots`
`# rm -r /.snapshots`
Create snapper config
2022-12-16 11:50:40 +01:00
`# snapper -c root create-config /`
Delete unneeded volume
2022-12-16 11:50:40 +01:00
`# btrfs subv del /.snapshots/`
2022-12-16 11:50:40 +01:00
`# mkdir /.snapshots`
Mount snapshots volume
2022-12-16 11:50:40 +01:00
`# mount -a`
2022-12-16 11:50:40 +01:00
`# chmod 750 /.snapshots`
2022-12-16 11:50:40 +01:00
`# vim /etc/snapper/configs/root`
Change these things:
2022-12-16 11:50:40 +01:00
`ALLOW_USERS="(user)"`
```
TIMELINE_LIMIT_HOURLY="5"
TIMELINE_LIMIT_DAILY="7"
TIMELINE_LIMIT_WEEKLY="0"
TIMELINE_LIMIT_MONTHLY="0"
TIMELINE_LIMIT_YEARLY="0"
```
Enable snapper
`# systemctl enable --now snapper-timeline.timer`
2022-12-16 11:50:40 +01:00
`# systemctl enable --now snapper-cleanup.timer`
Allow user to access snapshots
`# chmod a+rx /.snapshots`
2022-12-16 11:50:40 +01:00
`# chown :(user) /.snapshots`
## Install AUR helper
2022-12-16 11:50:40 +01:00
### yay
2022-12-16 11:50:40 +01:00
```sh
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
```
### paru
2022-12-16 11:50:40 +01:00
```sh
git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si
```
## (Snapper) Snap pac and GUI
2022-12-16 11:50:40 +01:00
`$ paru -S snap-pac-grub snapper-gui`