Part 4: Arch Linux Installation Guide
Tags: linux, archlinux, tutorial
Published: 2021-08-12 15:17:54

*Originally published on [xhalford.com](https://www.xhalford.com/part-5-arch-linux-installation-guide/)*


---

In part 4 of this **series**, we will be installing essential packages. Configuring the system. And adding a boot loader to the system. This follows on from the drive partitioning, formatting and mounting in the [previous part](https://www.xhalford.com/part-3-arch-linux-installation-guide/) of this guide series.

> _**Notes:** There are a few presumptions being made for this guide. Regarding yourself and your current setup._
> 
> - *You will be moving from another \*nix system.*
>     - *This will help with the initial steps, with the programs being used to download the image and write it to a USB drive.*
>     - *If you are coming from Windows, I will try to link to articles explaining this fairly trivial difference.*
> - *Have access to this guide on another device.*
>     - *As once we get to installing Arch Linux, we'll be stuck in a terminal for some major steps.*
> 
> - *Can handle looking deep into the empty void of the tty.*
> - *Make sure not to make any typos - as I try to do the same throughout these guides.*


---

## What you'll need:

- Maintain the internet connection you [setup in part 2](https://www.xhalford.com/part-2-arch-linux-installation-guide/#make-sure-were-online).
- The patience to re-read every command you type, and output given.
- It's not the end of the world if you "mess up" at any stage here. You'll just save yourself the time of redoing anything, if you do.


---

# Installing Arch Linux

Arch Linux uses the package manager, _pacman_. The Debian equivalent to _apt_ or Fedora's _dnf_. Before we can do any of that, we need to install three essential packages. That provide everything necessary for you to tell other people that you "use Arch Linux by the way."

> In the future I may write about pacman's repository system, and the different ways to use it. But carrying out the commands later on in this tutorial are simple enough.

For now we'll be using the _pacstrap_ script to install packages to the new root directory. Installing the [_base_ package](https://archlinux.org/packages/core/any/base/), the Linux kernel, and the Linux firmware package to help support common hardware on your device.

```sh
$ pacstrap /mnt base linux linux-firmware
```
> The _linux_ kernel package can be changed for the _linux-hardened_, _linux-lts_ or _linux-zen_ kernels.

Leave that to do it's work for a few minutes...

Then, once done, we'll go through some configurations for the system.

---

# Generating the fstab File

As the [Arch Wiki](https://wiki.archlinux.org/index.php/Fstab) states;

> _"The fstab file can be used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem."_

To generate this _fstab_ file, enter the below command.

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

---

# Change Root Into Your New System

Chroot command to change root into this new installation.

```sh
arch-chroot /mnt
```

Now you can use the _ls_ command to view what the file structure of your new home will look like. Look's nice, huh?

---

# Set Time Zone

As we are now in a new installation, we need to set the time zone. To do this, we need to know which region we are from.

```sh
$ ls /usr/share/zoneinfo/
```

And what city is the nearest one to your location.

```sh
$ ls /usr/share/zoneinfo/region/
```
> Remembering to replace _/region/_ with one that is appropriate to yourself.

Now we know the closest location. We'll use the following command to force create a symbolic link - using the _-sf_ arguments.

```sh
$ ln -sf /usr/share/zoneinfo/REGION/CITY /etc/localtime
```

Entering the following, will generate the _adjtime_ file.

```sh
$ hwclock --systohc
```

---

# Localisation

With the system's time zone set, we need to select and then generate the locales. Which are required for certain programs and libraries to function as expected.

We do this by editing the _/etc/locale.gen_ file. Uncommenting locales that relate to you. For example, in the US, this will likely be `en_US.UTF-8 UTF-8` - found on line 177.

---

## Using an Editor

As Arch doesn't come with a text editor installed with the _base_ package. We need to install one to make the edit to the locale.gen file.

My recommendations here are to use the beginner-friendly command-line interface editor _nano_. As it shows the appropriate Ctrl, _^_, commands to save and exit the program, once done uncommenting the locales.

Otherwise, install and use _vim_. And let your mind expand.

To do this, enter the following command - with your chosen editor as the argument.

```sh
$ pacman -S nano
```

Now you can edit that _locale.gen_ file. Once the correct lines have been uncommented, generate the locales.

```sh
$ locale-gen
```

---

## Set the LANG Variable

Next up is to create and then set the LANG variable.

```sh
$ nano /etc/locale.conf

LANG=en_GB.UTF-8
```
> Entering the same information for the variable, as you uncommented from the locale.gen file.

---

## Keyboard Layout

Like we did in [part 2 of this series](https://xhalford.com/part-2-arch-linux-installation-guide/#keyboard-layout), we need to set the keyboard layout for our region. Refer to that article section, to find your KEYMAP value.

```sh
$ nano /etc/vconsole.conf

KEYMAP=uk
```

---

# Network Configuration

Create and edit the _hostname_ file. Here you will enter the name you want your device to be known as on your network.

```sh
$ nano /etc/hostname

desktop
```

Then we need to add our hosts to the _/etc/hosts_ file. Using our _hostname_ (e.g. _desktop_) where appropriate.

```sh
$ nano /etc/hosts

127.0.0.1   localhost
::1         localhost
127.0.1.1   desktop.localdomain desktop
```

---

# Setting the Root Password

So we don't have to _chroot_ when we load back up. It's best to set the root password now. Using the _passwd_ script, create your password and confirm it.

```sh
$ passwd
New password:
Retype new password:
passwd: password updated successfully
```

---

# Bootloader

Before we're done with setting up the base install and configuring it. We need to to install a few packages to make sure the UEFI firmware can find and start the bootloader, which is in the EFI system partition.

Basically, when you start your computer, Arch Linux will be listed and can be started.

The almost "standard" bootloader these days is _GRUB_. As it can support our chosen firmware (UEFI), partition table (GPT), can multi-boot, and supports our Linux file system partition (ext4).

To setup _GRUB_, we also need to install a few other packages that will support it's installation.

```sh
$ pacman -S grub efibootmgr os-prober dosfstools mtools
```

  - _grub_ is the bootloader.
  - _efibootmgr_ writes the boot entries, making Arch Linux discoverable.
  - _os-prober_ is used to discover other installed operating systems on your computer.
  - _dosfstools_ allows the system to create, check and label FAT32 file systems.
    - e.g. format a USB to FAT32.
  - _mtools_ allows you to access FAT file systems.

Now we need to create an EFI directory in _/boot/_.

```sh
$ mkdir /boot/efi
```

We can now mount the EFI system partition to that new directory.

```sh
$ mount /dev/nvme0n1p1 /boot/efi
```

Then we need to run the GRUB installation script, _grub-install_. Which will install the GRUB EFI application and install it's modules.

```sh
$ grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub_uefi --recheck
```

When the computer starts up, it loads the GRUB configuration file, _/boot/grub/grub.cfg_. So we need to generate this file.

```sh
$ grub-mkconfig -o /boot/grub/grub.cfg
```

---

# We're Done! (mostly)

At this point you can `exit` the chroot environment, `umount -R /mnt` and enter `reboot`. Before doing that, however, this is a good place to your user account and install a few more packages. Making your new home a bit nicer to look and easier to use, than this black void.

---

Follow me on [Twitter!](https://twitter.com/intent/user?screen_name=richardhalford_)