Skip to content

Instantly share code, notes, and snippets.

@aarikpokras
Last active November 14, 2023 18:03
Show Gist options
  • Save aarikpokras/830f2d664b8b56384472ca6926bc72e4 to your computer and use it in GitHub Desktop.
Save aarikpokras/830f2d664b8b56384472ca6926bc72e4 to your computer and use it in GitHub Desktop.
A clearer installation and use guide for Arch Linux

Arch Linux Installation Guide

Contents

Skip

Introduction

This guide will guide you through the process of installing Arch Linux from a live USB to another drive. For the purposes of this guide, the former will be /dev/live_usb and the latter will be /dev/install.

Before you start, I encourage you to read through the FAQ. It'll be helpful in this process. If you are unclear about anything, please visit the Arch Linux Wiki here.

Pre-Installation

Get yourself an iso image from the official download page. If you're a beginner, I recommend not getting the netboot image. Just get the regular iso.

How to use mirrors:

  1. Find the section that is closest to you. For example, "United States".
  2. Select a mirror. I usually select one that ends with .edu.
  3. Select your desired download.

Verify your image

  1. From the mirror, download the sig file. It should look like this: archlinux-version-x86_64.iso.sig

Make sure the .sig file is downloaded to the same folder that the iso file is. In a file tree, it would look like this:

Downloads
|- archlinux-version-x86_64.iso
|- archlinux-version-x86_64.iso.sig

Flash the image

Using a software like unetbootin or using the dd command, flash the iso file to the disk. Here, I am going to use dd.

sudo dd if=/PATH/archlinux-version-x86_64.iso of=/dev/live_usb bs=4M status=progress

Please replace PATH with the path to the folder in which the iso is stored.

This code will decompress the ISO file to the live USB and display its progress to you.

Get your second drive ready

  1. Get out the drive to which you would like to install Arch Linux. Keep in mind that it can not be the one that you want to install from.
  2. Format the drive. Using a software on any computer (for macOS, Disk Utility, etc.), format the drive to which you would like to install to any format. Important information on formatting that you definitely should read

Boot up the Live Environment

Using whatever method your computer uses to change boot devices, boot up the live USB.

You may see multiple error messages. These are likely worth ignoring, the live USB will still boot.

Optional: Set Keyboard Layout and Font

This is only necessary if you don't have a regular American keyboard. Or if you don't like the really ugly font. Couldn't blame you, it hurts my eyes to look at it.

  1. List the available key maps.
ls /usr/share/kbd/keymaps/**/*.map.gz
  1. Use loadkeys to load the map.
loadkeys de-latin1
  1. Change the font with setfont. The fonts are stored in /usr/share/kbd/consolefonts/.
setfont 737-16

Verify Boot Mode

To make sure the computer is UEFI, we need to verify the boot mode.

If the following returns with 32 or 64, you are in UEFI:

cat /sys/firmware/efi/fw_platform_size

Connect to the Internet

In order to get our network interface, we need to use the following:

ip link

Look for something along the lines of wlan0 or eth0, for Wi-Fi and Ethernet respectively.

Here, we will be connecting through Wi-Fi.

To connect to Wi-Fi, we should use the iwctl command. Run the following commands:

iwctl device list
iwctl station INTERFACE scan
iwctl station INTERFACE get-networks
iwctl station INTERFACE connect SSID --passphrase=PASSWORD

Please replace INTERFACE with the device you find in iwctl device list, SSID with the SSID of the network to which you want to connect, and PASSWORD with the passphrase of the Wi-Fi network.

Check your connection by running lynx. If the page successfully loads, you are connected to Wi-Fi successfully.

Change the Time

If you are not located in the UTC time zone, then we need to change the system clock.

To check the system clock, run timedatectl. If it's not right, do the following:

timedatectl list-timezones | less
timedatectl set-timezone REGION/CITY

Partition the Disk

It's time to partition the disk to which you want to install Arch Linux. Plug it in to the computer now.

Give it a few seconds to recognize the disk, then run:

lsblk

This will list all devices.

Please make sure you have the right device. Please do not write to the computer's internal hard drive unless you actually want to.

After you've got the right device, run:

fdisk /dev/install

Replace /dev/install with the /dev path to your drive.

BIOS Systems

  1. In the fdisk shell, type d and hit enter. This will delete any existing partitions.
  2. Type o and hit enter. This will create an empty DOS MBR table.
  3. Type n and hit enter. This will create a new partition. When prompted for the first sector, use the default value. When prompted for the last sector, type +600M.
  4. Type t and hit enter. Type L to see a list of all partition types. Scroll through the list to find something like "Linux swap. There might be an alias present so you can just type swap`.
  5. Type n and hit enter. Go through the new partition process again. For the first and last sectors of this partition, please use the preset default values.
  6. Type t and hit enter. In the list of partition types, find "Linux".
  7. Type p and hit enter. This will display the partition table. Verify that it is how you want it.
  8. Type write and hit enter. This will write the changes to the drive.

UEFI Systems

  1. In the fdisk shell, run d to delete any existing partitions.
  2. Run g. This will create an empty GUID Partition Table.
  3. Run n. This will start the partitioning process. For the first sector, use the preset default value. For the last sector, use +400M if you're using one kernel (recommended) or +1G for multiple kernels.
  4. Run t. Use the list to find "EFI System Partition" or "EFI System". There may be an alias present so you can use uefi to change the partition type to ESP.
  5. Create a new partition with a first sector of the default value and a last sector of +600M.
  6. Change the newest partition's type to "Linux swap" or "swap".
  7. Create a new partition with a first and last sector of the default values. This is the root partition.
  8. Change the root partition's type to "Linux x86-64 root".
  9. Run write to write the changes to the device.

Format the Partitions

From this point forward in the guide, the root partition will be expressed with /dev/root_partition, the swap with /dev/swap, and the ESP (EFI System Partition) with /dev/esp. The device itself will still be referred to as /dev/install.

Now that we have all of our partitions, they need to be formatted with a certain type of filesystem. I recommend using ext4, but for the most part, you can use whatever one you want.

Now we will format the root partition.

mkfs.ext4 /dev/root_partition

Initialize the swap partition by running:

mkswap /dev/swap

Warning: Only do the following if you created the EFI System Partition during the partitioning step in this guide. Erasing an existing EFI System Partition could destroy important data.

Format the EFI System Partition by running:

mkfs.fat -F 32 /dev/esp

Mount the filesystems

Now we need to mount the drive to which we want to install Arch Linux. Make sure you have the right drive before you start this step.

To mount the drive, run the following:

mount /dev/root_partition /mnt

Mount the EFI System Partition:

mount /dev/esp /mnt/boot

Enable the swap volume:

swapon /dev/swap

Installation

Install Base Packages

pacstrap is a software made to install kernels and base packages from Arch Linux Live Media.

Use pacstrap to install the essential packages to the root partition:

pacstrap -K /mnt base linux linux-firmware

This will install the packages base, linux, and linux-firmware to /mnt.

Please note that when you boot into installed Arch Linux, you will not have all of the packages or utilities that you have in the live USB. If you want to install additional packages to the drive, append their names to the command above. Some that I recommend getting are nano, man, wpa_supplicant, dhcpcd, netctl, and other necessary networking utilities.

System Configuration

Fstab

Now we need to generate the fstab file. This determines how different devices should be mounted.

genfstab -U /mnt >> /mnt/etc/fstab

Chroot

Now we will use chroot to "enter" our disk to which we are installing.

To do this, run:

arch-chroot /mnt

Time

To set the time zone, run the following:

ln -sf /usr/share/zoneinfo/REGION/CITY /etc/localtime

The REGION and CITY parts are the same as they would be when using timedatectl.

Use hwclock to generate our /etc/adjtime:

hwclock --systohc

Locales and Locale Generation

We now need to generate the locale. This guide assumes that your locale is en_US.UTF-8 UTF-8, but you can change yours. Here is how you can change your locale.

If you used pacstrap to install a text editor, (in this case, we will use nano), then run the following:

nano /etc/locale.gen

And un-comment (remove the # in front of) your desired locale.

If you did not install a text editor, you can use sed to uncomment your locale.

sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen

Adjust the sed command according to the results when you cat the file.

If you changed the keyboard layout, make the changes consistent in the /etc/vsonsole.conf file. Modify the KEYMAP section. For example:

KEYMAP=de-latin1

Network Configuration

We now need to make the hostname file.

You can run:

touch /etc/hostname && echo "HOSTNAME" >> /etc/hostname

Replace "HOSTNAME" with your desired hostname.

We will connect to the internet on the installed device later.

Make sure your networking client is installed. If it's not, install it and other desired packages now:

pacman -Syu package1 package2 package3

initramfs

It's usually not required, but I recommend using mkinitcpio to create a new initramfs.

To create a new initramfs, run:

mkinitcpio -P

This may take a while, please do not kill the process.

Set Root Password

Set the root password:

passwd

Boot Loader

For this guide, I will be using GRUB as my boot loader because it's superior.

First, two packages must be installed: grub and efibootmgr:

pacman -Syu grub efibootmgr

Then, we can install GRUB to /boot:

grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB

If everything worked, you should see a message that looks like "Installation complete. No error returned". Don't worry, you're almost done.

Final Steps

  1. To exit the chroot environment, use ctrl+D.
  2. Unmount the drive that you're installing Arch to by running:
umount -R /mnt
  1. Restart your machine. I recommend using halt and manually turning it on after a few seconds to give your computer more time to recognize the drive.

Booting up

Turn on your computer.

Select the boot source. Using whatever method is appropriate for your computer, use it to select the boot disk. It should make itself clear. Boot it up.

Inspect the partitions. Use ls to look through the partitions for the ESP. For example:

> ls (hd1,gpt1)/

The / is important because it allows us to see the files inside of the partition.

Load the kernel. Because we didn't create a GRUB config file, we need to manually boot. You should run something like:

> linux (hd1,gpt1)/vmlinuz-linux

Load the initramfs. This is a necessary step in booting up. Don't worry though, you won't have to type all of this every time you boot up.

To load the initramfs, you can run:

> initrd (hd1,gpt1)/initramfs-linux.img

Please replace all of the file paths with the accurate one for your device.

Boot up. After you've loaded the kernel and initramfs, run:

> boot

In all above examples of the GRUB shell, please omit the preceding > character.

If You're Dropped into an Emergency Shell

  1. Don't panic. Don't cry, either. Your hard work is not in vain.
  2. In this shell, we do not have lsblk, fdisk, parted, pacman, or any other basic utilities. We need to work with our bare-minimum utilities. Run:
ls /dev | grep "sd"
  1. The above command should have returned roughly what running lsblk would have. Your device's /dev location likely changed. If, when you were installing Arch from live media, and your device's /dev location was sdc, it is likely sdb now. Please account for this.
  2. Mount the new root:
mount /dev/sdX /new_root
  1. Replace /dev/sdX with the path to your device.
  2. Use ^D to boot up Arch. After a little bit of waiting, you should see a login screen.

Logging in

Sign in as root with the password that you set using passwd.

Connecting

In this guide, we will only be connecting to WiFi. We will use netctl.

  1. Enter the /etc/netctl directory. It should have been created when you installed netctl.
  2. Create a new profile configuration file. You can call it whatever you want. This can be done by running:
touch /etc/netctl/my-wifi-connection
  1. Replace my-wifi-connection with your desired profile name.
  2. In the file, enter:
Description='Description'
Interface=[WIRELESS INTERFACE] # You can show all interfaces by running `ip link`.
Connection=wireless
Security=wpa-configsection # If it's a secured network. Use "open" if it has no security.
IP=dhcp

WPAConfigSection=(
  'ssid="SSID"'
  'key_mgmt=WPA-PSK'
  'psk="PASSWORD"'
)
  1. Replace "SSID" with your SSID and PASSWORD with your network's password
  2. To start the connection, run:
netctl start my-wifi-connection
  1. Replace my-wifi-connection with the name of the file in /etc/netctl.
  2. Check the status of your connection:
netctl status my-wifi-connection
  1. Enable the profile on startup:
netctl enable my-wifi-connection
  1. Restart systemd-networkd:
systemctl restart systemd-networkd
  1. Optional: Restart your computer.

Desktop Environment

If you haven't already, please install sudo:

pacman -Syu sudo

XFCE

We need to install four packages: xorg, xfce, lightdm, and lightdm-gtk-greeter:

sudo pacman -Syu xorg xfce lightdm lightdm-gtk-greeter

Now, enable lightdm:

sudo systemctl enable lightdm

GNOME

Using GDM (Recommended)

We need to install four packages: xorg, gnome, gdm, and optionally gnome-extra:

sudo pacman -Syu xorg gnome gdm gnome-extra

Now, we have to enable gdm on startup:

sudo systemctl enable gdm

Using LightDM

We need to install the following packages: xorg, gnome, lightdm, lightdm-gtk-greeter, and optionally gnome-extra:

sudo pacman -Syu xorg gnome lightdm lightdm-gtk-greeter gnome-extra

Now we enable lightdm:

sudo systemctl enable lightdm

KDE Plasma

Using SDDM (Recommended)

We need to install the following: xorg, plasma-meta, sddm, and optionally kde-applications:

sudo pacman -Syu xorg plasma-meta sddm kde-applications

Now we enable SDDM:

sudo systemctl enable sddm

Using LightDM

We need to install the following packages: xorg, plasma-meta, lightdm, lightdm-gtk-greeter, and optionally kde-applications:

sudo pacman -Syu xorg plasma-meta lightdm lightdm-gtk-greeter kde-applications

Enable LightDM:

sudo systemctl enable lightdm

After installing your DE of choice, reboot your system. When you start it up again, follow the no GRUB config boot process.

sudo reboot

Automating Boot Process with GRUB

If you don't want to have to manually boot up, then you can use a grub.cfg file to do it for you. There are two ways you can do this:

grub-mkconfig

To make the config file, you can run:

grub-mkconfig -o /boot/grub/grub.cfg

Manual Configuration

  1. Create the configuration file:
sudo touch /boot/grub/grub.cfg
  1. Edit the file. In it, put something like the following:
menuentry "Boot up Arch Linux" {
  linux (hdX,gptX)/vmlinuz-linux
  initrd (hdX,gptX)/initramfs-linux.img
  boot
}
  1. Add any other things you want to the cfg file, but make sure you replace "hdX,gptX" and any other aspects to match what you did in the manual boot-up process.

Disk formats

UEFI Computer BIOS Computer
Partition Maps GUID Partition Table Master Boot Record
EFI System Partition rqd. Yes No
SWAP Partition rqd. Yes Yes
Root Partition rqd. Yes Yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment