archlinux-installation-standard

The standard of archlinux installation & configuration for me

Enter F12 for Boot Menu when bootstrap

Pre-installation

  1. Update the system clock

    1
    # timedatectl set-ntp true
  2. 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
    # cryptsetup -y -v luksFormat /dev/sda2
    # cryptsetup open /dev/sda2 cryptroot
    # mkfs.btrfs -L arch_os /dev/mapper/cryptroot
    # mount /dev/mapper/cryptroot /mnt

    You 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

  1. Create top-level subvolumes
    1
    2
    3
    # btrfs subvolume create /mnt/@
    # btrfs subvolume create /mnt/@snapshots
    # btrfs subvolume create /mnt/@home
  2. Mount top-level subvolumes
    Unmount the system partition at /mnt.
    1
    # umount /mnt
    Now mount the newly created subvolumes by using the subvol= mount option (with enabled compress zstd).
    1
    2
    3
    4
    5
    # mount -o compress=zstd,[email protected] /dev/mapper/cryptroot /mnt
    # mkdir /mnt/{boot,home,.snapshots}
    # mount /dev/sda1 /mnt/boot
    # mount -o compress=zstd,[email protected] /dev/mapper/cryptroot /mnt/home
    # mount -o compress=zstd,[email protected] /dev/mapper/cryptroot /mnt/.snapshots
  3. Create nested subvolumes
    Create any nested subvolumes you do not want to have snapshots of when taking a snapshot of /.
    Every nested subvolume will be an empty directory inside the snapshot.
    Since the @ subvolume is mounted at /mnt you will need to create a subvolume at /mnt/var/cache/pacman/pkg as a nested subvolume
    You may have to create any parent directories first.
    1
    2
    3
    # mkdir -p /mnt/var/cache/pacman
    # btrfs subvolume create /mnt/var/cache/pacman/pkg
    # btrfs subvolume create /mnt/var/tmp

Installation

  1. Select the mirrors
    I will use huaweicloud as main mirror
    1
    # sed -i '1aServer = https://mirrors.huaweicloud.com/archlinux/$repo/os/$arch\n' /etc/pacman.d/mirrorlist
  2. Install essential packages
    1
    # pacstrap /mnt base base-devel linux linux-firmware btrfs-progs vim rng-tools git tmux openssh bash-completion systemd-swap bluez bluez-utils

Configure the system

  1. Fstab

    1
    # genfstab -U /mnt >> /mnt/etc/fstab
  2. Chroot

    1
    # arch-chroot /mnt
  3. Time zone

    1
    2
    3
    # ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    # timedatectl set-ntp true
    # hwclock --systohc
  4. Localization

    1
    2
    3
    4
    5
    # sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
    # sed -i 's/#zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
    # locale-gen
    # echo "LANG=en_US.UTF-8" >> /etc/locale.conf
    # echo "KEYMAP=us" >> /etc/vconsole.conf
  5. Network configuration
    Create the /etc/hostname file:

    1
    # echo "myhostname" > /etc/hostname

    Add matching entries to hosts(5):

    /etc/hosts
    1
    2
    3
    127.0.0.1	localhost
    ::1 localhost
    127.0.1.1 myhostname.neo myhostname
    • Use NetworkManager
      Install & Enable NetworkManager:
      1
      2
      3
      # pacman -S networkmanager
      # systemctl enable NetworkManager.service
      # systemctl enable systemd-resolved
    • Use iwd
      Install iwd: pacman -S iwd
      Wireless adapter configuration

      Use ip link to show network interface names

      /etc/systemd/network/25-wireless.network
      1
      2
      3
      4
      5
      [Match]
      Name=<Your wireless interface name>

      [Network]
      DHCP=yes
      Enable iwd and Systemd-networkd:
      1
      2
      3
      # systemctl enable iwd.service
      # systemctl enable systemd-networkd.service
      # systemctl enable systemd-resolved
  6. Random number generation
    Enable Rng-tools

    1
    # systemctl enable rngd.service
  7. Configuring mkinitcpio
    I prefer using the sd-encrypt hook with the systemd-base initramfs. (replace hook udev with hook system )

    /etc/mkinitcpio.conf
    1
    HOOKS=(base **systemd** autodetect **keyboard** **sd-vconsole** modconf block **sd-encrypt** filesystems fsck)

    Recreate the initramfs image

    1
    # mkinitcpio -P
  8. Users and password
    Create and use an unprivileged(non-root) user account(s) for most tasks

    1
    # useradd -m -s /bin/bash <Username>

    sudo: add user to sudoers and disable password prompt timeout

    1
    2
    # echo "<Username> ALL=(ALL) ALL" >> /etc/sudoers.d/<Username>
    # echo "Defaults passwd_timeout=0" > /etc/sudoers.d/notimeout

    Setting the new user and root user’s password

    1
    2
    # passwd <Username>
    # passwd root
  9. AUR helper
    I will use yay as my AUR helper

    1. Use 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 "[email protected]" --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 "[email protected]"
      else
      /bin/git "[email protected]"
      fi
      }

      source /bin/makepkg "[email protected]"
    2. Build & Install yay
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      # chmod 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/yay.git
      # cd yay
      # sudo -u <Username> makepkg-shallow --noconfirm -si
      # sudo -u <Username> yay --save --cleanafter --removemake --makepkg /usr/bin/makepkg-shallow
      # pacman -Qtdq | xargs -r pacman --noconfirm -Rcns
      # rm -rf /home/<Username>/.cache
      # rm -rf /build
  10. Boot loader
    Installing the EFI boot manager

    1
    # bootctl install

    Automatic update
    The package systemd-boot-pacman-hook provides a Pacman hook to automate the update process.

    Configuring the boot loader

    /boot/loader/loader.conf
    1
    2
    3
    4
    default  arch.conf
    timeout 4
    console-mode max
    editor no

    use lsblk -f to show persistent block device naming

    /boot/loader/entries/arch.conf
    1
    2
    3
    4
    title   Arch Linux
    linux /vmlinuz-linux
    initrd /initramfs-linux.img
    options rd.luks.name=<sda2-UUID>=cryptroot rd.luks.options=discard root=/dev/mapper/cryptroot rootflags=compress=zstd,[email protected]
    /boot/loader/entries/arch-fallback.conf
    1
    2
    3
    4
    title Arch Linux (fallback)
    linux /vmlinuz-linux
    initrd /initramfs-linux-fallback.img
    options rd.luks.name=<sda2-UUID>=cryptroot rd.luks.options=discard root=/dev/mapper/cryptroot rootflags=compress=zstd,[email protected]
  11. (Optional) Enable sshd

    1
    # systemctl enable sshd.service
  12. (Optional) Enable ZSWAP, ZRAM, SWAPFC
    Configuration

    /etc/systemd/swap.conf
    1
    2
    3
    4
    5
    6
    7
    ...
    zswap_enabled=1
    ...
    zram_enabled=1
    ...
    swapfc_enabled=1
    ...

    Enable systemd-swap

    1
    # systemctl enable systemd-swap
  13. (Optional) Enable bluetooth

    1
    # systemctl enable bluetooth.service

    Bluetooth auto power-on after boot:

    /etc/bluetooth/main.conf
    1
    2
    [Policy]
    AutoEnable=true
  14. (Optional) Add Archlinuxcn repository

    1
    2
    3
    4
    [archlinuxcn]
    Server = https://repo.archlinuxcn.org/$arch
    ## or install archlinuxcn-mirrorlist-git and use the mirrorlist
    #Include = /etc/pacman.d/archlinuxcn-mirrorlist

    Install archlinux-keyring

    1
    # pacman -S archlinuxcn-keyring

Desktop Environment

  1. Installation
    • KDE
      1
      2
      # pacman -S plasma-meta kde-system-meta kde-utilities-meta kde-network-meta kde-multimedia-meta kde-graphics-meta kio-fuse
      # systemctl enable sddm.service
    • GNOME

      Some packages require archlinuxcn’s repository

      1
      2
      3
      4
      5
      6
      $ yay -S gnome-shell gnome-shell-extensions gdm \
      nautilus file-roller sushi seahorse eog \
      gnome-{control-center,terminal,tweaks,keyring,backgrounds,clocks,logs,screenshot,menus} \
      gtk-engine-murrine materia-gtk-theme \
      dconf-editor loginized
      # systemctl enable gdm.service
  2. (Optional) Install & Configure input method:
    1
    2
    # pacman -S fcitx5-im fcitx5-chinese-addons fcitx5-configtool
    # cp /usr/share/applications/org.fcitx.Fcitx5.desktop ~/.config/autostart/
    ~/.pam_environment
    1
    2
    3
    GTK_IM_MODULE DEFAULT=fcitx
    QT_IM_MODULE DEFAULT=fcitx
    XMODIFIERS DEFAULT=\@im=fcitx
  3. (Optional|KDE) Turn off screen (DPMS) together with locking session:
    Go to: System Settings > Notifications > Applications(The button “Configure”) > Search “Screen Saver” > Configure Events:
    Select Screen locked and check box “Run command”, paste /bin/sleep 2; /usr/bin/xset dpms force off into it.

NVIDIA & NVIDIA Optimus

I will use the method of PRIME render offload which was official method supported by NVIDIA

  1. The nvidia-prime package provides a script that can be used to run programs on the NVIDIA card.
    1
    # pacman -S nvidia nvidia-prime
    To run a program on the NVIDIA card you can use the prime-run command:
    1
    2
    $ prime-run glxinfo | grep "OpenGL renderer"
    $ prime-run vulkaninfo
  2. Dynamic power management of the dGPU
    • Enable runtime power management for each PCI function

      1
      2
      # echo 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:

      1. 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

      2. Set the driver option via the kernel module configuration files
        /etc/modprobe.d/nvidia.conf
        1
        options nvidia "NVreg_DynamicPowerManagement=0x02"
      3. Reboot the system

Troubleshot

  1. blacklist kernel module
    /etc/modprobe.d/blacklist.conf
    1
    2
    blacklist ideapad_laptop
    blacklist nouveau
  2. yay: go get is slow in China
    1
    $ export GOPROXY=https://goproxy.io,direct
  3. Disable media automount in GNOME
    1
    2
    $ gsettings set org.gnome.desktop.media-handling automount false
    $ gsettings set org.gnome.desktop.media-handling automount-open false
  4. Video Decode is disabled in Microsoft Edge
    ~/.config/microsoft-edge-dev-flags.conf
    1
    2
    3
    --ignore-gpu-blocklist
    --enable-features=VaapiVideoDecoder
    --enable-accelerated-video-decode
  5. In Surface Devices:

    I use KDE for more smooth experience

    • Instal linux-surface kernel
      1
      2
      3
      4
      $ curl -s https://raw.githubusercontent.com/linux-surface/linux-surface/master/pkg/keys/surface.asc \
      | sudo pacman-key --add -
      $ sudo pacman-key --finger 56C464BAAC421453
      $ sudo pacman-key --lsign-key 56C464BAAC421453
      Add the repository:
      /etc/pacman.conf
      1
      2
      [linux-surface]
      Server = https://pkg.surfacelinux.com/arch/
      Then you can install the linux-surface kernel and its dependencies. You should also enable the iptsd service for touchscreen and stylus support:
      1
      2
      3
      $ sudo pacman -Syu
      $ sudo pacman -S linux-surface linux-surface-headers iptsd
      $ sudo systemctl enable iptsd
      Don’t forget to change the corresponding loader entries’ config
    • SDDM has problem with NetworkManager & Long loading time:
      Use GDM as a replace, don’t forget to configure KDE Wallet’s PAM:
      /etc/pam.d/gdm-password
      1
      2
      3
      ...
      auth optional pam_kwallet5.so
      session optional pam_kwallet5.so auto_start
    • Auto disable touch screen after login (X11):
      First install xorg-xinput.
      Then create a shell script:
      disable_touch_screen.sh
      1
      2
      3
      4
      #!/bin/bash
      if [[ ${XDG_SESSION_TYPE} = "x11" ]]; then
      xinput disable `xinput list | egrep -o "IPTS Touch.+id=[0-9]+" | egrep -o "[0-9]+"`
      fi
      Finally go to System Settings > Startup and Shutdown > Autostart:
      Press Add button and select Add Login Script, choose the script you just created.

Additional Packages

  1. Additional Packages
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    [AUR] gnome-shell-extension-appindicator
    [AUR] gnome-shell-extension-kimpanel-git
    [AUR] gnome-shell-extension-dash-to-dock
    [AUR] gnome-shell-extension-desktop-icons-ng
    [AUR] gnome-shell-extension-freon-git
    gvfs-mtp
    gpaste

    noto-fonts{,-cjk,-emoji}

    xf86-video-intel
    vulkan-intel
    vulkan-tools
    libva-utils
    ^[AUR] libva-intel-driver-hybrid
    ^intel-media-driver

    [AUR] fcitx5-pinyin-zhwiki
    fcitx5-material-color

    bpytop
    htop
    docker
    docker-compose
    zerotier-one
    man
    cmake
    gdb
    arch-install-scripts
    pacman-contrib
    rsync
    tree
    nmap
    traceroute
    compsize
    wireguard-tools
    picocom ($ picocom -b 1500000 /dev/ttyUSB0, Ctrl-a Ctrl-q to quit)
    [AUR] tealdeer
    ncdu
    [AUR] cppman
    openbsd-netcat
    bc
    p7zip
    unrar

    zsh
    zsh-autosuggestions
    zsh-syntax-highlighting
    zsh-history-substring-search

    npm
    [AUR] hexo-cli

    telegram-desktop
    thunderbird
    anki
    remmina
    - libvncserver
    - freerdp
    v2ray
    texlive-most
    - [AUR] tllocalmgr-git
    libreoffice-still
    blender
    krita
    [AUR] bitwarden
    [AUR] qv2ray-dev-git
    [AUR] v2ray-cap-git
    [AUR] cgproxy

    obs-studio
    mpv
    [AUR] visual-studio-code-bin
    [AUR] microsoft-edge-dev-bin
    [AUR] xmind-2020
    [AUR] netease-cloud-music-gtk

    steam
    - ttf-liberation
    - lib32-vulkan-intel

    python-pip
    python-matplotlib
    python-pandas
    python-seaborn

    lutris
    wine
    - lib32-giflib
    - lib32-gnutls
    - lib32-mpg123
    - lib32-openal
    - lib32-v4l-utils
    - lib32-libpulse
    - lib32-libxcomposite
    - lib32-libxinerama
    - lib32-libxslt
    - lib32-gst-plugins-base-libs

    debootstrap
    ubuntu-keyring

    virt-manager
    libvirt
    - dmidecode
    - dnsmasq
    - ebtables
    - ^qemu
    ^[AUR] qemu-user-static
    [AUR] binfmt-qemu-static-all-arch
    edk2-ovmf

    [AUR] v2raya
    [Archlinuxcn] fcitx5-pinyin-moegirl
    [AUR] syncthing-gtk
    qtcreator
Author

Ndoskrnl

Posted on

2020-10-20

Updated on

2021-12-05

Licensed under