Tutorial

How to install Arch Linux: the easiest guide

8

First, we need to create a bootable USB drive of Arch Linux that will be used to install the distro on the target machine. You can create the bootable USB drive from Desktop Linux, macOS or Windows.

Download the latest ISO of Arch Linux.

Plug the USB drive to the PC and note down the mount point so that you don’t format wrong drive and lose data.

We will use ‘dd’ command to create the bootable USB drive on Linux. Find the block device name of the USB drive with the ‘lsblk’ command.

lsblk

[Tip: note down the name of the USB drive from the output of the command. You can easily identify the drive by looking at the storage capacity. If you have a lot of drives, just unplug the USB drive run the command, plug it again and run the command. The new drive that popped up in the list is your USB drive 😉]

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 the same ‘dd’ command to write the image to the drive. 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 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, 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

Unmount the drive:

diskutil umountDisk /dev/disk3

Use the ‘dd’ command to write the Arch Linux iso to the drive:

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 bootable drive of Arch Linux.]

Boot into Arch Linux

Once the ISO has been successfully written to the USB Flash drive, edit the BIOS settings of the target PC (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 both UEFI and legacy BIOS. This tutorial will cover both.

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

We will be downloading the base packages from the internet, so the first thing we need to ensure is that the network is working properly. I heavily recommend using wire connection, over wireless as it eliminates the complexity of setting up wireless network. I am assuming your wireless card is fully supported on Linux, otherwise you will have to install drivers manually and that’s beyond the scope of this tutorial.

Let’s configure the network. Run ‘ifconfig’ or ‘ip link’ command that will list all network devices.

# ip link

Take a note of the network device. Wired devices start with ‘en’ and wireless devices start with ‘wl’. In my case, the wired device was ‘enp0s3’ and the wireless devices was ‘wlp2s0’.

If you do plan to use the wireless device (in case you don’t have ethernet connectivity), run the following command to set-up the wireless device (replace ‘wlp2s0’ with the name of your wireless device)

# wifi-menu -o wlp2s0

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

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

# ping  -c 3 www.google.com

If you get output, congrats you are connected.

Create the MBR/GPT partition tables

Working with storage devices from the command line could be intimidating.  In this article we are going to format the entire hard drive. If you have more than one hard drives or SSDs on the system, please remove them so that you don’t format the wrong devices by mistake and lose data. This tutorial is intended for single boot Arch Linux systems. If you plan to dual boot with Windows 10, I heavily recommend using separate SSDs for Windows 10 and Arch Linux. Dual booting is not covered in this article.

We will create a new partition table; there are two kinds of partition tables: MBR and GPT. GPT is a modern partition table and that’s what I recommend. But I will cover both MBR and GPT in this tutorial.

(a) How to create the 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 the ‘lsblk’ command:

NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT

sda              8:0    0 111.8G  0 disk

In my case, the HDD or SSD on which I will install Arch Linux, is ‘/dev/sda’. Run the ‘parted’ command with the device mount point.

# parted /dev/sda

Replace ‘sda’ with your device name.

You will notice that ‘#’ is replaced with ‘(parted)’. Let’s create the partition table with msdos (MBR).

(parted) mklabel msdos

You will get a warning about destruction of data on that drive, type ‘Yes’. Let’s create ‘root’ and ‘swap’:

(parted) mkpart primary ext4 1MiB 40GiB

Here the file system is ‘ext4’ and I am allocating 40GB to the root partition; you can choose whatever value you want. It must be at least 10GB if you plan to install a lot of package. Since I don’t create a separate ‘home’ folder, it becomes part of the root directory, so I allocate more space to it. As a principle I ‘never’ store any data on home directories like ‘music’, ‘movies’ or ‘documents’, all of my files are stored on a separate hard drive or on my home server. Only home directory I use is ‘download’ for downloading stuff.

Set boot flag on it, so it becomes bootable:

(parted) set 1 boot on

It’s time to create the ‘swap’ partition. How much space you allocate to swap is debatable. I have 32GB of physical RAM on my system, so I allocate around 2GB to swap for suspending the system. If you have less than 4GB of RAM, you can allocated as much SWAP as you have RAM. The end point of the root partition becomes the start point of swap partition. Make changes to the start point and end point accordingly. In this case I am allocating 2GB to swap:

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

If you want, you can create more partition. Just keep in mind that the end point for the last partition becomes the start point for the next partition. If you want to use all of the remaining free space for the partition, then use 100% as the end point.

An example:

(parted) mkpart primary ext4 42GiB 100%

The above command 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

[note: replace ‘sda’ with your device]

# mkfs.ext4 /dev/sda1

Activate the swap partition:

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

Mount the root partition to the ‘mnt’ directory:

# mount /dev/sda1 /mnt

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

(b) How to create the GPT partition table

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

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’. (replace sda with your device)

# parted /dev/sda

You will notice that ‘#’ is replaced with ‘(parted)’. 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. In case of UEFI boot partition, the part-type is ESP (EFI System Partition); the file system will be FAT 32 and we 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. As I explained earlier, 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 the 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.

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

Now, it’s time to 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.

Configure Network

Once you boot 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.

Arch Linux Manual: How to create users on your system

By 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

It’s time 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

In this section, we are 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 a while 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 a while 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.

Follow TFiR on Twitter, Facebook, YouTube and Reddit. Subscribe to our Weekly Newsletter
Swapnil Bhartiya
I have more than 12 years of experience covering Enterprise Open Source, Cloud, Containers, IoT, Machine Learning and general tech. My stories cover a very broad spectrum - traditional Linux, data center and Free Software to contemporary emerging technologies like 'serverless'. Widely Read: My stories have appeared in a multitude of leading publications including CIO, InfoWorld, Network World, The New Stack, Linux Pro Magazine, ADMIN Magazine, HPE Insights, Raspberry Pi Geek Magazine, SweetCode, Linux For You, Electronics For You and more.

Best Christmas Gifts for your techie child

Previous article

Baidu joins Kubernetes barn CNCF as a gold member

Next article