arch linux

Homepage

Installation

The official installation guide is here.

You will need to determine whether your computer is using BIOS or UEFI. If ls /sys/firmware/efi/efivars returns something your computer is running on UEFI, otherwise it is on BIOS.

The following guide is meant for machines using UEFI

Partitioning

This particular layout will be covered.

Use parted and format the disk you want to install Arch to with

lsblk to get the name of said disk
parted /dev/disk-name
mklabel gpt

Exit parted and fire up fdisk with fdisk /dev/sdX, where X is the ID of the target harddisk, or fdisk /dev/nvme0n1.

  1. Create an ESP partition
  2. Create SWAP partition
  3. Create root partition
  4. Write changes to disk

You can check here for alternatives.

For cross-reference

fdisk -l should return something similar to this:

Disk /dev/sda: 238.47 GiB, 256060514304 bytes, 500118192 sectors
Disk model: HFS256G39TND-N21
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 51B29D66-921E-48F3-A8D6-D31723075566

Device        Start       End   Sectors   Size Type
/dev/sda1      2048   2099199   2097152     1G EFI System
/dev/sda2   2099200  18876415  16777216     8G Linux swap
/dev/sda3  18876416 500118158 481241743 229.5G Linux filesystem

mkfs.fat -F32 /dev/your-boot-partition to format your boot partition as FAT32

mkswap /dev/swap_partition && swapon /dev/swap_partition

mkfs.ext4 /dev/root_partition to format your root partition

Encrypting the root partition (optional)

Check here for more information.

cryptsetup -y -v luksFormat /dev/root_partition
cryptsetup open /dev/root_partition root
mkfs.ext4 /dev/mapper/root
mount /dev/mapper/root /mnt

Mounting the boot partition

mount /dev/root_partition /mnt mounts your root partition at /mnt (For those who skipped the encryption step)

For unencrypted installations

mkdir -p /mnt/boot/efi to create the EFI boot folder

mount /dev/efi_partition /mnt/boot/efi to mount it

For encrypted installations

mkdir -p /mnt/boot to create the boot folder

mount /dev/efi_partition /mnt/boot so that the kernel gets installed to the unencrypted EFI partition rather than the encrypted root partition

Connecting to the Internet

If you’re using ethernet and ping google.com returns something, you can skip this step.

Try running ip link and see if your wifi card is detected. Something like this should appear:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: wlp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
    link/ether 3c:6a:a7:8f:e5:17 brd ff:ff:ff:ff:ff:ff

If you see a similar output, you can proceed by starting iwctl (iwctl is a command provided by the package iwd)

Here’s what you should be running after launching iwctl

[iwd]# device list
[iwd]# station *device* scan
[iwd]# station *device* get-networks
[iwd]# station *device* connect *SSID*

Installing the system

pacstrap /mnt base base-devel linux linux-firmware nano networkmanager nmtui to install essential packages.

genfstab -p /mnt >> /mnt/etc/fstab to create the fstab

arch-chroot /mnt to chroot into the root partition

Run systemctl enable NetworkManager.service to have working internet on your next boot.

Setting the clock

The timezones are listed in /usr/share/zoneinfo, link your corresponding city to /etc/localtime with ln -sf /usr/share/zoneinfo/Region/City /etc/localtime

hwclock --systohc to calibrate your hardware clock.

Note: Both -w and –-systohc are synonymous

Setting the locale

nano /etc/locale.gen and uncomment your corresponding locale. Ex. for those who are using American English, uncomment the lines en_US.UTF-8 and en_US ISO-8859-1.

Then, run locale-gen to generate your locales.

Create a new file with nano /etc/locale.conf, and append the lines LANG=en_US.UTF-8. Otherwise, see here.

If you want to set a permanent keyboard layout, go to /etc/vconsole.conf and append KEYMAP=your-keyboard-layout. Refer here and here for more information.

Setting the hostname

nano /etc/hostname and append the hostname you want for your computer.

Then you go to /etc/hosts, and add:

127.0.0.1       localhost
::1             localhost
127.0.1.1       myhostname.localdomain  myhostname

Change myhostname to the hostname you appended into /etc/hostname.

Installing the bootloader

pacman -S grub efibootmgr os-prober to install grub

nano /etc/default/grub and uncomment GRUB_ENABLE_CYRPTODISK=y (only required for encrypted root partitions)

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB to install grub bootloader, if you would want to change the ID of the bootloader, alter the parameter --bootloader-id=name-of-your-choice. Change --efi-directory=/boot/efi to --efi-directory=/boot if you’re doing the encrypted installation.

grub-mkconfig -o /boot/grub/grub.cfg to generate the GRUB config.

If you want GRUB to detect bootable partitions for other OSes, check here.

Additional configuration for encrypted setups

nano /etc/mkinitcpio.conf and add the hook encrypt to the HOOKS variable as such (For systemd-based initramfs check here):

HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt filesystems fsck)

Refer here for more options that you may require.

Then, regenerate the initramfs with mkinitcpio -P.

Next, run blkid and record down the UUID for /dev/root_partition (not the UUID for /dev/mapper/root) and /dev/swap_partition.

nano /etc/default/grub and append cryptdevice=UUID=device-UUID:root root=/dev/mapper/root to GRUB_CMDLINE_LINUX_DEFAULT where device-UUID is the UUID you recorded just now.

For those who are using the sd-encrypt hook, refer here.

For support to suspend to disk, add the option resume=UUID=swap-UUID to your GRUB_CMDLINE_LINUX_DEFAULT.

After configuring all the options, don’t forget rerun grub-mkconfig -o /boot/grub/grub.cfg.

Setting up the repositories

Edit /etc/pacman.conf and uncomment out repositories you want to include.

Setting up the user account

passwd to first set the password for root.

useradd -m -g users -s /bin/bash your-username to add a user which can use the sudo command.

passwd your-username to set the password for the user you’re going to use for your daily tasks. Run xdg-user-dirs-update after rebooting to generate the default folders for your home directory.

Finishing up

Before restarting, it is recommended to have a display manager and/or a windows manager installed. Refer here for a list of choices.

Cloning an Arch system

  1. Boot up an Arch live media
  2. Partition the new machine
  3. Mount the new machine
  4. Copy all your files over to the new harddisk
  5. Check /mnt/etc/fstab and remove (or comment) old entries, then run genfstab -U /mnt >> /mnt/etc/fstab
  6. arch-chroot into the root your new system
  7. Connect to the Internet and run pacman -S $(pacman -Qnq) and yay -S $(pacman -Qqm) (if you’re using yay), which reinstalls all packages as sometimes files may become corrupted or missing during transfers
  8. Run grub-install (The guide above has explained how to use grub-install) and grub-mkconfig -o /boot/grub/grub.cfg to get your GRUB installed
  9. Install the necessarily hardware stuff

Pacman

A list of less commonly used pacman commands

# Installing a package
pacman -U pkg_name.pkg.tar.zst
pacman -U https://webpage/pkg_name.pkg.tar.zst

# To see which group a package belongs to
pacman -Sg pkg_name

# Removing packages
pacman -Rs # remove with its dependencies
pacman -Rsu # remove even more packages

# Query packages
pacman -Ss pkg_name # Search the online database
pacman -Qs pkg_name # Search the local database
pacman -Si pkg_name # Extensive information of the package online
pacman -Qi pkg_name # Extensive information of the local package
pacman -Qii pkg_name # Shows more extensive information
pacman -Ql pkg_name # Lists installed packages
pacman -Qtd # Find orphaned packages
pacman -Qe # List all parent packages 

Edit /etc/pacman.conf and set ParallelDownloads to a positive integer, i.e. 12 for generally faster speeds.