andis-sprinkis / linux-install

A personal guide and scripts for an Arch Linux desktop installation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arch Linux setup

With LVM on LUKS, systemd-boot bootloader, hibernation, applying user personal configuration files and preferences.

Setup process

  1. Download the Arch Linux installer image.

  2. Write the installation image to the installation media.

    • To write the image from a *nix system:
      < path/to/archlinux-version-x86_64.iso > /dev/sdx
    • To write the image from Microsoft Windows, use Rufus.
    • Alternatively, copy the downloaded image to a Ventoy prepared device.
  3. Disable "Secure Boot" in the BIOS of the installation target computer.

  4. Boot installation target computer into Arch Linux installation media environment.

  5. Verify EFI boot mode by listing efivars directory.

    ls /sys/firmware/efi/efivars
  6. To continue the installation remotely from another computer:

    1. Set the installation media root user password.
      passwd
    2. Enable and start SSH server.
      systemctl enable --now sshd
    3. Determine installation target computer IP address.
      ip a
    4. From another device SSH into installation target computer to continue the setup.
      ssh root@192.168.1.99
  7. Wipe the installation target disk. This document assumes installation target disk is /dev/nvme0n1 (use lsblk to list block devices).

    cryptsetup open --type plain -d /dev/urandom /dev/nvme0n1 to_be_wiped
    dd if=/dev/zero of=/dev/mapper/to_be_wiped bs=1M status=progress 2> /dev/null
    cryptsetup close to_be_wiped
  8. Create the top level physical partitions. Choose the option GPT partitioning.

    cfdisk /dev/nvme0n1
    /dev/ mapping Size Type
    /dev/nvme0n1p1 512M EFI System
    /dev/nvme0n1p2 rest of the drive Linux filesystem
  9. Format the LUKS container partition. Must provide the password.

    cryptsetup luksFormat /dev/nvme0n1p2
  10. Open the LUKS container.

    cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1_luks0
  11. Create physical volume in LUKS container.

    pvcreate /dev/mapper/nvme0n1_luks0
  12. Create a logical volume group and add the physical volume of the LUKS container to it.

    vgcreate nvme0n1_luks0_volgrp0 /dev/mapper/nvme0n1_luks0
  13. Create the logical partitions in the volume group.

    lvcreate -L 128G nvme0n1_luks0_volgrp0 -n root
    lvcreate -L 20G nvme0n1_luks0_volgrp0 -n swap
    lvcreate -l 100%FREE nvme0n1_luks0_volgrp0 -n home

    To determine the swap partition size:

    • RAM <=1 GB – at least the size of RAM, at most double the size of RAM.
    • RAM >1 GB – at least equal to the square root of the RAM size and at most double the size of RAM.
    • With hibernation – equal to size of RAM + the square root of the RAM size.
  14. Reduce /home partition by 256MiB for e2scrub use.

    lvreduce -L -256M nvme0n1_luks0_volgrp0/home
  15. Format the partitions of each logical volume.

    mkfs.ext4 /dev/nvme0n1_luks0_volgrp0/root
    mkfs.ext4 /dev/nvme0n1_luks0_volgrp0/home
    mkswap /dev/nvme0n1_luks0_volgrp0/swap
  16. Format the /boot partition.

    mkfs.vfat -F32 /dev/nvme0n1p1
  17. Create mount points and mount the system partitions.

    mkdir /mnt
    mount /dev/mapper/nvme0n1_luks0_volgrp0-root /mnt
    mkdir /mnt/{boot,home}
    mount /dev/mapper/nvme0n1_luks0_volgrp0-home /mnt/home
    mount /dev/nvme0n1p1 /mnt/boot
  18. Initialize /swap partition.

    swapon /dev/mapper/nvme0n1_luks0_volgrp0-swap
  19. Update Arch official package repository mirrors.

    reflector --country Latvia,Lithuania,Estonia,Finland,Sweden,Poland --protocol https --latest 10 --save /etc/pacman.d/mirrorlist
  20. Install base packages.

    pacstrap /mnt base linux linux-firmware networkmanager openssh sudo neovim git terminus-font lvm2
  21. Generate fstab.

    genfstab -U /mnt >> /mnt/etc/fstab
  22. Change root path of the system.

    arch-chroot /mnt
  23. Install root user Neovim configuration.

    mkdir -p /root/.config && cd /root/.config
    git clone https://github.com/andis-sprinkis/nvim-user-config nvim
    cd nvim && git checkout minimal-config
  24. Add boot-loader directories.

    mkdir -p /boot/loader/entries
  25. Get the LUKS container partition UUID.

    blkid --match-tag UUID -o value /dev/nvme0n1p2
  26. Add boot-loader entry. Add file /boot/loader/entries/arch.conf:

    title Arch Linux
    linux /vmlinuz-linux
    initrd /initramfs-linux.img
    options cryptdevice=UUID=<LUKS container partition UUID>:nvme0n1_luks0 root=/dev/nvme0n1_luks0_volgrp0/root resume=/dev/nvme0n1_luks0_volgrp0/swap module_blacklist=pcspkr,snd_pcsp
    

    Set TTY default screen rotation by specifying the fbcon=rotate:X boot options value.

    For a counter-clockwise rotation set:

    options ... fbcon=rotate:1
    
  27. Configure boot-loader. Add file /boot/loader/loader.conf:

    #timeout 0
    #console-mode keep
    
  28. Update /etc/mkinitcpio.conf variable HOOKS, adding encrypt lvm2 resume:

    HOOKS=(base udev autodetect modconf kms keyboard keymap consolefont block filesystems fsck encrypt lvm2 resume)
  29. Regenerate initfram file.

    mkinitcpio -P
  30. Install systemd-boot bootloader.

    bootctl --path=/boot install
  31. Add pacman update hook for systemd-boot bootloader:

    1. mkdir /etc/pacman.d/hooks
    2. Add file /etc/pacman.d/hooks/100-systemd-boot.hook:

      [Trigger]
      Type = Package
      Operation = Upgrade
      Target = systemd
      
      [Action]
      Description = Updating systemd-boot
      When = PostTransaction
      Exec = /usr/bin/bootctl update
      
  32. Enable NetworkManager service.

    systemctl enable NetworkManager
  33. Set hardware clock.

    hwclock --systohc
  34. Set system locale.

    1. Add to file /etc/locale.gen:
      en_US.UTF-8 UTF-8
      lv_LV.UTF-8 UTF-8
      
    2. locale-gen
    3. Add file /etc/locale.conf
      LANG=en_US.UTF-8
      LC_ADDRESS=lv_LV.UTF-8
      LC_COLLATE=lv_LV.UTF-8
      LC_CTYPE=lv_LV.UTF-8
      LC_MEASUREMENT=lv_LV.UTF-8
      LC_MONETARY=lv_LV.UTF-8
      LC_NUMERIC=lv_LV.UTF-8
      LC_PAPER=lv_LV.UTF-8
      LC_TELEPHONE=lv_LV.UTF-8
      LC_TIME=lv_LV.UTF-8
  35. Set the console font and keymap. Add to file /etc/vconsole.conf:

    FONT=ter-v24b
    KEYMAP=lv
  36. Set hostname.

    echo "arch-pc-00" > /etc/hostname
  37. Set root user password.

    passwd root
  38. Create a regular user.

    useradd -m user-00
    usermod -G wheel -a user-00
    passwd user-00
  39. Set sudo-ers.

    1. EDITOR=nvim
      visudo
    2. Add or uncomment:
      %wheel ALL=(ALL:ALL) ALL
      
  40. Create user mount directories.

    dirs=$(eval "echo /mnt/nvme{1..5} /mnt/sata{1..5} /mnt/usb{1..5} /mnt/pc{1..5} /mnt/nas{1..5} /mnt/vm{1..5} /mnt/mobile{1..5}")
    mkdir -p $dirs
    chown user-00:user-00 $dirs
  41. Exit from /mnt root shell and reboot, then log in as the regular user.

    exit
    reboot
  42. Set console typematic delay and rate (keyboard input speed).

    1. Add file /etc/systemd/system/console-kbdrate.service:

      [Unit]
      Description=Console typematic delay and rate (kbdrate).
      
      [Service]
      Type=oneshot
      RemainAfterExit=yes
      StandardInput=tty
      StandardOutput=tty
      ExecStart=/usr/bin/kbdrate --silent --delay 165 --rate 55
      
      [Install]
      WantedBy=multi-user.target
      
    2. systemctl enable --now console-kbdrate.service
  43. Enable Network Time Protocol.

    sudo timedatectl set-ntp on
  44. Set the time zone.

    sudo timedatectl set-timezone Europe/Riga
  45. Clone the repository containing the user package lists.

    cd $HOME
    git clone https://github.com/andis-sprinkis/linux-install
    cd linux-install
  46. Install the Arch official package repository packages.

    sudo pacman -S --needed $(echo $(< ./pkg_pacman))
  47. If installation target computer is a VirtualBox guest, install and enable the VirtualBox guest utilities.

    sudo pacman -S virtualbox-guest-utils
    sudo systemctl enable --now vboxservice.service
  48. Install AUR helper.

    temp_path=$(mktemp -d)
    git clone https://aur.archlinux.org/yay.git $temp_path
    cd $temp_path
    makepkg -si
    cd $HOME/linux-install
  49. Install AUR packages.

    yay -S --needed $(echo $(< ./pkg_aur))
  50. Install AppImage packages.

    for p in $(echo $(< ./pkg_appimage)); do
        curl --location --output-dir "$HOME/.local/opt/appimage" --remote-name "$p"
    done
    
    chmod +x $HOME/.local/opt/appimage/*
  51. Install user general configuration.

    git_url_cfg=https://github.com/andis-sprinkis/nix-user-config
    dir_cfg_git=$HOME/.dotfiles_git
    temp_path=$(mktemp -d)
    git clone --separate-git-dir=$dir_cfg_git $git_url_cfg $temp_path
    rsync --recursive --verbose --exclude '.git' $temp_path/ $HOME
    git --git-dir=$dir_cfg_git --work-tree=$HOME config --local status.showUntrackedFiles no
    git --git-dir=$dir_cfg_git --work-tree=$HOME submodule update --init
  52. Install user Neovim configuration.

    cd $HOME/.config
    git clone https://github.com/andis-sprinkis/nvim-user-config nvim
  53. Create user download directries.

    mkdir -p $HOME/dl/{_chrm,_eph,_ff,_jd2,_mnt,_qbt,_scdl,_ytdlp}
  54. Switch shell to ZSH for both root and the regular user and execute ZSH.

    sudo chsh -s /usr/bin/zsh root
    sudo chsh -s /usr/bin/zsh user-00
    exec zsh
  55. Install npm packages.

    volta install $(echo $(< ./pkg_npm))
  56. Install PyPi packages.

    for p in $(echo $(< ./pkg_pypi)); do pipx install $p; done
  57. Enable the audio system.

    systemctl --user enable --now pipewire.socket pipewire-pulse.socket wireplumber.service
  58. Enable the PC/SD Smart Card Daemon service.

    sudo systemctl enable pcscd.service
  59. Enable non-root users to be able to use allow_other mount option with FUSE. In file /etc/fuse.conf add or uncomment line

    user_allow_other
    
  60. Detect the hardware sensors.

    sudo sensors-detect
  61. To customize functions of the device power buttons:

    1. Update file /etc/systemd/logind.conf.
      sudo nvim /etc/systemd/logind.conf
    2. Restart the systemd-logind.service.
      sudo systemctl restart systemd-logind.service
  62. Log out and log in again.

    exit

Encryption, automatic unlocking and mounting of an another drive on the system

LVM on LUKS.

  1. Wipe the target disk. This document assumes the target disk is /dev/nvme1n1 (use lsblk to list block devices).
    sudo su
    cryptsetup open --type plain -d /dev/urandom /dev/nvme1n1 to_be_wiped
    dd if=/dev/zero of=/dev/mapper/to_be_wiped bs=1M status=progress 2> /dev/null
    cryptsetup close to_be_wiped
  2. Create the top level physical partition. Choose the option GPT partitioning and set the entire drive as Linux filesystem.
    cfdisk /dev/nvme1n1
  3. Generate the keyfile.
    dd bs=512 count=4 if=/dev/random of=/nvme1.key iflag=fullblock
  4. Set keyfile access permissions.
    chmod a=,u=rw /nvme1.key
  5. Format the LUKS container partition. Must provide the password.
    cryptsetup luksFormat /dev/nvme1n1p1
  6. Associate the keyfile with the LUKS container partition.
    cryptsetup luksAddKey /dev/nvme1n1p1 /nvme1.key
  7. Open the LUKS container.
    cryptsetup luksOpen /dev/nvme1n1p1 nvme1n1_luks0 --key-file /nvme1.key
  8. Create the physical volume in LUKS container.
    pvcreate /dev/mapper/nvme1n1_luks0
  9. Create a logical volume group and add the physical volume of the LUKS container to it.
    vgcreate nvme1n1_luks0_volgrp0 /dev/mapper/nvme1n1_luks0
  10. Create the logical partition in the volume group.
    lvcreate -l 100%FREE nvme1n1_luks0_volgrp0 -n data
  11. Reduce the /data logical partition by 256MiB for e2scrub use.
    lvreduce -L -256M nvme1n1_luks0_volgrp0/data
  12. Format the partition of the logical volume.
    mkfs.ext4 /dev/nvme1n1_luks0_volgrp0/data
  13. Get the LUKS container partition UUID.
    blkid --match-tag UUID -o value /dev/nvme1n1p1
  14. Add the LUKS container partition entry to file /etc/crypttab:
    nvme1          UUID=<LUKS container partition UUID>    /nvme1.key
    
  15. Get the logical volume partition UUID.
    blkid --match-tag UUID -o value /dev/mapper/nvme1n1_luks0_volgrp0-data
  16. Add the logical volume partition entry to file /etc/fstab:
    # /dev/mapper/nvme1n1_luks0_volgrp0-data
    UUID=<Logical volume partition UUID>  /mnt/nvme1 ext4 rw,relatime 0 0
    
  17. Re-mount /etc/fstab file specified devices.
    mount -a
    systemctl daemon-reload
  18. Change the mounted file system ownership to the regular user.
    chown -R user-00:user-00 /mnt/nvme1
  19. Reboot.
    systemctl reboot

Connecting to Wi-Fi

  • Installation media environment:
    iwctl station list
    iwctl station $station scan
    iwctl station $station get-networks
    iwctl station $station connect $network_name
  • The installed OS environment:
    • Interactively:
      nmtui
    • Non-interactively:
      nmcli device wifi connect $ssid password $password

Related resources

About

A personal guide and scripts for an Arch Linux desktop installation.

License:MIT License