0

A rolling release guide to Arch Linux.

Arch Linux is one of my favorite GNU/Linux distributions. However, it is not as easy to install as are Ubuntu and openSUSE. I have installed Arch Linux so many times on my systems that I have almost memorized the procedure. I have translated that process into an easy to follow tutorial that can help new Arch Linux users.

I keep this tutorial updated as I learn about problems that other users face or if I find an easier day to get the task done. There are many Ubuntu-like derivatives of Arch that make it easier to get started with Arch, but I will discourage using them.

Installing Arch without understanding some of its core components and configurations will cause more problems in future when something breaks because you don’t know how it’s set-up or how it works. So I encourage you to do a manual installation of Arch Linux and understand its internals.

I also recommend referring to the official Arch Wiki to get in-depth information about each step and process.

I have broken this article into several small pieces to address one topic at a time without intimidating you with a single long page.

How to create bootable USB drive for Arch Linux

We will create a bootable installation media of Arch Linux that will be used for installing Arch on our machines. We need a working machine running macOS, Linux or Windows to create the bootable USB drive of Arch Linux.

First, download the latest ISO of Arch Linux.

Then insert the USB drive that you want to use as installation media into your system. Depending on the operating system, there are different ways to create the bootable USB drive of Linux.

Create Arch Linux bootable USB drive using Linux

If you are running Linux based distribution on your system, then we will do it command line way.

Find the block device name of the USB drive with the ‘lsblk’ command.

lsblk

[Tip: In the output you can easily identify the USB drive by looking at the storage capacity. If you still can’t figure out which one is it, unplug the drive and run the ‘lsblk’ command. Now plug the drive and run the command again. Compare the output of the commands, with and without USB drive plugged in, the new device that popped up after plugging in the USB drive is your device ;-)]

Now we will write the Arch Linux iso image to the USB drive using the DD command:

sudo dd if=/arch_.iso of=/usb_drive bs=1M

Replace ‘arch_.iso’ with the actual path of the downloaded Arch Linux iso file and ‘usb_drive’ with the block device name.

Example:

sudo dd if=/home/swapnil/Download/archlinux-2016.12.01-dual.iso of=/dev/sde bs=1M

Create Arch Linux bootable USB drive using macOS

macOS is pure UNIX, so you can use the Terminal to create the bootable drive of Arch Linux. Plug in the USB drive, open the Terminal app and use ‘diskutil’ command to find the USB drive:

diskutil list

As I explained earlier, you can easily identify the the USB drive by looking at the storage capacity in the output of the above command. If you still can’t figure out which one is it, unplug the drive and run the ‘diskutil list’ command. Now plug the drive and run the command again. Compare the output of the commands, with and without USB drive plugged in, the new device that popped up after plugging in the USB drive is your device 😉

On macOS, a 4GB USB Flash drive will look like this:


/dev/disk3 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: Apple_partition_scheme *4.0 GB disk3
1: Apple_partition_map 4.1 KB disk3s1
2: Apple_HFS 2.5 MB disk3s2

Now unmount the drive:

diskutil umountDisk /dev/disk3

Then use the ‘dd’ command to write the Arch Linux iso to the drive:
sudo dd if=/arch-dual.iso of=USB_drive bs=1m

Example:

sudo dd if=/Users/swapnil/Downloads/arch-dual.iso of=/dev/disk3 bs=1m

[Note: If you are running Windows 10, you can use Win32 Disk Imager or any such tool to create the bootble drive of Arch Linux.]

Once the ISO has been successfully written to the USB Flash drive, edit the BIOS settings of the target computer (where you will be installing Arch Linux) and configure it to boot from the removable drive. If your system has secure boot, please disable it. Arch Linux supports for UEFI and legacy BIOS mode. In this tutorial I will cover booting from both UEFI and legacy BIOS.

Plug your bootable Arch Linux USB Flash drive into the target PC and boot it. If everything does well, you should boot into Arch Linux boot screen. Choose ‘Boot Arch Linux (x86_64)’ from the list. It will open a command line interface.

We will be downloading all packages from the Internet to install our system. We need working network so we can connect to the Internet. If you have Ethernet cable, I will recommend using it to eliminate the complexity of setting up the wireless network. If you don’t have a wired connection, read up. Just one caveat: I am assuming that your system has well supported wireless card; otherwise you will have to install drivers manually and covering all of those is beyond the scope of this article.

Let’s run ‘ifconfig’ or ‘ip link’ command that will list all network devices.
# ip link

Note down the name of the device you want to use. Wired devices will start with something like ‘en’ whereas wireless devices will start with ‘wl’. In my case wired device was ‘enp0s3’ and wireless devices was ‘wlp2s0’.

Run the following command to set-up the wireless device (replace wlp2s0 with the name of your wireless devices)

# wifi-menu -o wlp2s0

Use arrow keys on your keyboard to select the wireless network you want to connect to and click OK (tip: mouse won’t work in the command line, hit enter or use the ‘Tab’ key to highlight the ‘Ok’ button and hit enter).

The next window will give you the option to change the name, leave it as it is. Enter the wireless password in the third window. You should be connected. Let’s ping Google to see if we are connected:

# ping  -c 3 www.google.com

If you get output, congrats you are connected. It’s time to proceed.

Prepare hard drive for installation

Working with storage devices from the command line could be intimidating.  In this article we are going to format the entire hard drive; it will wipe all partitions on it.

If you have other operating systems installed on your drive and you want to dual boot with Arch, or you want to install Arch on an existing partition without destroying other partitions on the hard drive then stop now and check out ‘prepare hard drive for dual boot’ article.

If this is your first experience formatting storage devices from the command line, I will suggest please unplug all storage devices from your system so you don’t end up formatting them by mistake. Plug only the one that you will format to install Arch Linux on it. If you can’t unplug them, then be careful with block device names.

We are going to create a new partition table and two partitions: root and swap. There are two kinds of partition tables: MBR and GPT. GPT is modern partition table and that’s what I recommend. But I will cover both MBR and GPT in this tutorial.

How to create MBR partition table

There are many tools to perform the task of creating the partition table, I will use ‘Parted’ for this article. Find the block device name with ‘lsblk’ command:

NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda              8:0    0 111.8G  0 disk

In my case the block device, or SSD on which I will be installing Arch Linux, is ‘/dev/sda’

We are using the ‘Parted’ tool to create the partition table. Run the ‘parted’ command against the block device, which in my case is ‘/dev/sda’.

# parted /dev/sdX

Replace ‘sdX’ with your block device name, in my case it was:

# parted /dev/sda

In the command line, you will notice that ‘#’ is replaced with ‘(parted)’, which means you are running the parted command. We have to first create a partition table with msdos (MBR).

(parted) mklabel msdos

It will warn you about destroying all data. Type Yes. Let’s create root and then swap using the following pattern:

(parted) mkpart part-type fs-type start end

For root, the part-type will be primary; the file system will be ext4. As you can see the start point is 1MB and end point is 40GB, which means it will create a 40GB partition. I am giving 40GB to root because I don’t create a separate home partition, it’s created inside the root partition. I gave

(parted) mkpart primary ext4 1MiB 40GiB

Now we will set boot flag on it:

(parted) set 1 boot on

Once the root partition is created, we will create the swap partition. For swap the file system will be ‘linux-swap’ and the end point for the previous partition will become the start point for next partition:

(parted) mkpart primary linux-swap 40GiB 42GiB

I am creating 2GB of swap because I have over 32GB of RAM on this system and I really don’t need any swap partition. If you have a good amount of RAM, you don’t really need swap. However, you do need it if you use ‘suspend to memory’ feature which I doubt anyone uses these days.

If you want, you can create more partitions, just use the same pattern. Just bear that end point of the previous partition is the start point for the next partition. If you want to use all of the remaining free space then used 100% as the end point.

An example:

(parted) mkpart primary ext4 42GiB 100%

This will create another partition with remaining free space.

Check if the partitions are created correctly by running the ‘print’ command:

(parted) print

If everything looks good, exit ‘parted’ tool with ‘quit’ command:

(parted) quit

Formatting hard drives

Now we need to format the partitions with appropriate file systems. The root partition must be formatted as ext4

# mkfs.ext4 /dev/sdxY

In my case root was /dev/sda1, so it’s:

# mkfs.ext4 /dev/sda1

Activate the swap partition:

# mkswap /dev/sdxY
# swapon /dev/sdxY

In my case it was:

# mkswap /dev/sda2
# swapon /dev/sda2

Mount the root partition to the ‘mnt’ directory:

# mount /dev/sdxN /mnt

In my case it was sda1:

# mount /dev/sda1 /mnt

We are all set, now it’s time to proceed to installation.

Prepare hard drive for installation (GPT/EFI)

This chapter is intended for UEFI/GPT partition, if your motherboard doesn’t support UEFI or you want to dual boot with Windows, then you need MBR partition table, please refer to the MBR chapter.

Find the block device name with ‘lsblk’ command:

NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda              8:0    0 111.8G  0 disk

In my case, the block device or SSD on which I will be installing Arch Linux is ‘/dev/sda’

We are using the ‘Parted’ tool to create the partition table. Run the ‘parted’ command against the block device, which in my case is ‘/dev/sda’.

# parted /dev/sdX

Replace ‘sdX’ with your block device name, in my case it was:

# parted /dev/sda

You will notice that ‘#’ is replaced by ‘(parted)’ that means you are running the parted command. We have to first create a partition table with gpt.

(parted) mklabel gpt

It will warn you about destroying all data, type ‘yes’. We will now create three partitions: UEFI boot partition, root partition and optional swap using the following pattern:

(parted) mkpart part-type fs-type start end

In case of UEFI boot partition, the part-type is ESP (EFI System Partition); the file system will be FAT 32 and we will allocate at least 512MB for this partition. The start point is 1MiB and the end point is 513MiB.

(parted) mkpart ESP fat32 1MiB 513MiB

Set boot flag on it:

(parted) set 1 boot on

For root, the part-type will be primary; the file system will be ext4. Just keep in mind that the start point for the next partition is the end point of the previous partition. We are creating root partition with 40GB space.

(parted) mkpart primary ext4 513MiB 40GiB

As you can see the start point is 513MB and end point is 40GB, which means it will create a 40GB partition. I am giving 40GB to root because I don’t create a separate home partition, it’s created inside the root partition.

Once the root partition is created we will create the swap partition. For swap the file system will be ‘linux-swap’ and the end point for the previous partition will become the start point for next partition:

(parted) mkpart primary linux-swap 40GiB 42GiB

I am creating 2GB of swap because I have over 32GB of RAM on this system and I really don’t need any swap partition. If you have a good amount of RAM, you don’t really need swap. However, you do need it if you use ‘suspend to memory’ feature which I doubt anyone uses these days.

If you want, you can create more partitions, just use the same pattern. Just bear that end point of the previous partition is the start point for the next partition. If you want to use all of the remaining free space then used 100% as the end point.

An example:

(parted) mkpart primary ext4 42GiB 100%

This will create another partition with remaining free space.

Check if the partitions are created correctly by running the ‘print’ command:

(parted) print

If everything looks good, exit ‘parted’ tool with ‘quit’ command:

(parted) quit

Create file systems and mount devices (UEFI/GPT)

Now we need to format the file system. The UEFI partition must be formatted as FAT32

# mkfs.fat -F32 /dev/sdxY

Root must be formatted as ext4:

# mkfs.ext4 /dev/sdxY

Activate swap

# mkswap /dev/sdxY
# swapon /dev/sdxY

(Please replace sdxY with partition you created for swap, in my case it was sda3)

# mkswap /dev/sda3
# swapon /dev/sda3

It’s time to mount boot and root partitions. First, we mount root:

# mount /dev/sdxY /mnt

In my case it was sda2:

# mount /dev/sda2 /mnt

Create ‘boot’ directory to mount the UEFI partition:

# mkdir -p /mnt/boot

Mount the ESP to boot:

# mount /dev/sdxY /mnt/boot

In my case it will be:

# mount /dev/sda1 /mnt/boot

We are all set to proceed to installation.

Install the system files

Since we will be downloading packages from the Internet, it’s recommended to choose the closest mirror for the fastest download speed. Edit the mirrorlist file with ‘nano’ editor (I prefer nano as it’s easy for new users.

# nano /etc/pacman.d/mirrorlist

Tip: You can use ‘Ctrl + w’ in nano to search the closest location. Copy the URL of the nearest mirror using Alt+6, use ‘page-up’ keys to go on top of the list and paste the URL using the Ctrl+U keys. Once done, use ‘Ctrl+x’ to save and close the file.

Once mirrorlist is configured, install the base packages:

# pacstrap -i /mnt base base-devel

Once all packages are installed, generate the ‘fstab’ file so that it has information about mounted partitions and system can boot into Arch Linux.

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

If you want, you can check the newly generated fstab file

# cat /mnt/etc/fstab

If you notice any errors, please edit the file manually instead of re-running the genfstab command.

Then ‘chroot’ into the newly installed system:

# arch-chroot /mnt

Configure language for the system by editing the ‘locale.gen’ file:

# nano /etc/locale.gen

Find the entry for your language, uncomment it and save the file (in my case it was US English):

LANG=en_US.UTF-8

Then run the following commands, one by one:

# locale-gen
# echo LANG=en_US.UTF-8 > /etc/locale.conf
# export LANG=en_US.UTF-8

Configure the time zone. Run the following command and follow the simple steps:

# tzselect

Once all steps are completed, it will show you the selected time zone. Now create a symlink to it:

# ln -s /usr/share/zoneinfo/Zone/SubZone > /etc/localtime

In my case it was:

# ln -s /usr/share/zoneinfo/America/New_York > /etc/localtime

Set hardware clock to UTC:

# hwclock --systohc --utc

Our base installation is complete. It’s time to install the boot manager, create the root password and give our hostname a decent identity (optional).

Warning: If you are using WiFi for connectivity, please also install these packages before you reboot the system otherwise you won’t be able to access wireless network:

# pacman -S iw wpa_supplicant dialog

Now you are all set to move to the next step.

How to set-up boot manager, root password, and hostname

Install two packages, ‘grub’ and ‘os-prober’, here grub is boot manager and os-prober detects if there are other operating systems installed on the system.

pacman -S grub os-prober

If you are using GPT/UEFI then also install the efibootmgr

pacman -S grub efibootmgr os-prober

For BIOS/MBR

Run the following command:

# grub-install --recheck --target=i386-pc /dev/sdX

Here sdX will be the drive and not a partition, so in my case it was:

# grub-install --recheck --target=i386-pc /dev/sda

Generate grub.cfg:

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

For UEFI/GPT

Run the following command:

# grub-install --target=x86_64-efi --efi-directory=esp --bootloader-id=grub

Replace ‘esp’ with the mount point for the EFI, which in this case was /boot

Run:

grub-mkconfig -o esp/grub/grub.cfg

In this case, it will be

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

We are all set with the OS install, we have to now install other components and configure the system.

Set up hostname

Give our system a decent host name:

# echo swapnil > /etc/hostname

Create the password for the root. Run the following command:

# passwd

Leave the chroot environment:

# exit

And unmount the partition:

# umount -R /mnt

Then shutdown the system:

# shutdown

Remove the USB drive that you used to install Arch and reboot the system.

Set-up Arch Linux

Once you booted into newly installed Arch, you will see the login prompt. Login as root user. We need to configure network.

Wired connection

If you are using wired connection (ethernet), enable dhcpcd service. Find the name of the Ethernet device with ‘ip link’ command:

# ip link

Run the following commands one by one, the first one starts the dhcp service and the second one sets it to start at system boot.

# systemctl start [email protected]
# systemctl enable [email protected]

Note: Exchange ‘enp0s25’ with the name of your wired device. Ping Google to check successful connection:

ping –c 3 www.google.com

If you get the ping, you are good.

Wireless Connection

If you are using wireless, disable dhcpcd service that was enabled by default. To find the name of wired/wireless devices run ‘ip link’ command that will give you the name of the Interfaces.

Disable the dhcpcd service:

# systemctl stop [email protected]

(Note: Replace ‘enp0s25’ with your wired device.)

Install ‘iw’, ‘wpa_supplicant’ and ‘dialogue’ packages to manage connections to the wireless networks:

# pacman -S iw wpa_supplicant dialog

Follow the on-screen steps and connect to your wireless network. Ping Google to check your connection:

ping –c 3 www.google.com

If you get successful pings, proceed to the next step.

How to create users on your system

We now have a completely working Arch Linux system. However, we still have a lot of things to do. The first thing we need to do is create a user.

# useradd -m -G additional_groups -s login_shell username

Here ‘wheel’ and ‘users’ will be the additional groups, the shell will be bash and user will be swapnil; of course, you will change the username.

# useradd -m -G wheel,users -s /bin/bash swapnil

Create a password for this user:

# passwd swapnil

Install ‘sudo’ so this user can perform administrative tasks :

# pacman -S sudo

Let’s handover sudo powers to this user. Edit the sudoers file using the visudo command:

# EDITOR=nano visudo

Un-comment this line in this file:

%wheel ALL=(ALL) ALL

Save and close the file with ‘Ctrl+x’ and then type ‘y’ to confirm. I also suggest installing the ‘bash-completion’ package which makes helps with auto completion of commands, paths and package names.

# pacman -S bash-completion

Alternatively, you can use ‘zsh’ shell which has more features than bash.

How to configure repositories

All repository information is saved in the ‘pacman.conf’ file. Edit this file with nano editor.

# nano /etc/pacman.conf

By default only stable repositories are enabled, but you can un-comment other repositories if you need alpha or pre-release packages. However, let’s start with only stable packages so you don’t nuke your Arch system. If you are using 64 system, you can still install 32 bit applications on your system. All you need to do is enable the ‘multilib’ repo. This will create a separate directory for 32-bit applications. Scroll down in the ‘pacman.conf’ file and un-comment the ‘multilib’ repo:

[multilib]
Include = /etc/pacman.d/mirrorlist

Save and close the config file. Then update the repositories by running this command:

# pacman -Sy

Note: You must always update repos before installing any packages. If you need packages that are not available in the official repo and you don’t want to compile them, you can always add more repositories to the config file.

How to install X-server and graphics drivers

We now have to install the display server, graphics drivers and other crucial components before we install the final piece of an operating system: the desktop environment.

# pacman -S xorg-server xorg-server-utils

It will ask you to install libgl package, choose the one for your GPU. If you have Intel card, then use mesa-libgl, if you have latest nvidia card then nvidia-libgl. It’s time to now install GPU driver for the graphic card on your system:

Intel GPU:

pacman -S xf86-video-intel

Nvidia (latest card, for older cards, check this page):

pacman -S nvidia nvidia-libgl

ATI/AMD:

pacman -S xf86-video-ati lib32-mesa-libgl

If you are using a laptop you will also need to install the drivers for input devices like touch-pad:

# pacman -S xf86-input-synaptics

We are all set to install the desired desktop environment. I will try to include all those desktop environments that I have tried so far. If you want me to write about your preferred DE, let me know and I will give it a try.

How to install applications in Arch Linux with pacman

You now have a complete Arch Linux system. In this article, I am going to talk about some basics of software management (installation and removal, and system maintenance.

You must always update repositories before installing any package:

sudo pacman –Sy

The following command updates the repositories and runs system updates:

sudo pacman –Syu

To install a package:

pacman –S package_name

Example

pacman –S gimp

If you want to install multiple packages from the same group, there is an easy and simpler way out. Let’s say we want to install several Virtualbox packages. Usually, you will have to list out each of these packages:

sudo pacman -S virtualbox-guest-dkms virtualbox-guest-dkms      virtualbox-guest-modules-lts virtualbox-guest-iso virtualbox-guest-utils virtualbox-guest-modules virtualbox-guest-utils-nox

But you can make it easier by using this pattern:

sudo pacman -S virtualbox-guest-{dkms,iso,modules,dkms,utils}

Easy peasy.

Optimize Pacman: Once in awhile you need to optimize pacman:

sudo pacman-optimize

Removing packages: To remove a package without touching its repositories:

pacman –R package_name

To remove a package and its dependencies:

pacman –Rns

(If these dependencies are required by other packages, pacman will show error.) If you do want to remove a package with all those packages that rely on these dependencies:

pacman -Rsc package_name

You need to be extra careful before running this command as it can remove a lot of needed packages and break your system. If you want to remove a package that is required by another package without removing the dependent package, use this command:

pacman -Rdd package_name

Keep it clean. Pacman saves the downloaded packages in ‘/var/cache/pacman/pkg’ directory. Once in awhile you need to clean it up to removed the older or uninstalled packages:

pacman -Sc

If you think that you many need to rollback to older package then you can run ‘paccache –r’ command that purges all cached version of packages leaving only 3 most recent version of packages. That’s pretty much all that you need to know to get started with Arch Linux.

How to use AUR aka Arch User Repository

Arch has a very huge repository of packages, however not everything is available through repos and oftentimes you may have to compile packages from AUR. While you can do it manually and it’s very easy, I tend to use tools like ‘yaourt’ to compile packages.

How to manually compile packages from AUR

You can search for the desired package in AUR and download the snapshot. In this example were installing Geary email client. We have downloaded the git snapshot, extract the downloaded package:

tar –xvf gearty-git.tar

cd to the extracted folder

cd geary-git

Run the following command as regular user (non-root)

makepkg –sri

It will ask you to enter root password when required. If no error are reported it will proceed to install. Once it awhile it will seek your confirmation to install packages and dependencies.  That’s how simple it is to compile packages on Arch.

Using Yaourt to install AUR packages

The above method requires you to search for package from AUR repositories from a web browser, download the snapshot and then install manually. Alternatively, you can use tools like Youart that allow you to install AUR packages from the command line. Install Yaourt, along with its dependency ‘package-query’.

git clone https://aur.archlinux.org/package-query.git

Change directory into the  downloaded package:

cd package-query

Run the makepkg command:

makepkg –sri

As usual it will ask you password, once the package is compiled and install, cd out of the package-query directory:

cd ..

Download the yaourt package from GIT

git clone https://aur.archlinux.org/yaourt.git

Change directory,

cd yaourt

And run makepkg:

makepkg -si

Once installed, get out the yaourt directory:

cd ..

You have Yaourt installed on your system.

How to use Yaourt

The first rule of Arch Club is: always refresh repository info before installing any package:

yaourt -Syu --aur

This command sync database, upgrades installed packages and AUR packages.

Installing packages with yaourt

The good news is that yaourt can also install those packages that are already available in the repo. So if you want to install GIMP, you can either use pacman:

sudo pacman –S package_name

Or you can use yaourt:

yaourt  -S gimp

If you want to search only AUR skipping packages from official repo then use without –S or use –aur flag:

yaourt --aur gimp

Let’s try to install Plex Media Server which is not in the official repos.

yaourt plex-media

You will see a list of packages related to Plex Media Server. It also shows how many people have installed it. All you need is enter the number of that package. Yaourt resolves all dependencies, compiles the packages and installs them.

Yaourt will also show if there were any bugs and errors reported by other users during compiling so play close attention. If there is any comment, Yaourt offers to edit the package file with your desired editor to make suggested changes.

How to install and configure Gnome on Arch Linux

Now we have a working Arch Linux system and all we need is install Gnome desktop and configure it. First let’s install Gnome:

pacman -S gnome gnome-extra

If you are going to use only Gnome on this system then you need to enable Gnome Display Manager aka gdm and set it to start at system reboot:

systemctl start gdm.service
systemctl enable gdm.service

If everything went well, you should see the login screen for Gnome. Log into the system with the user you previously created.

Congratulations, you are now an Arch Linux user.

You may also like