DEV Community

Richard Halford
Richard Halford

Posted on • Originally published at xhalford.com on

Part 4: Arch Linux Installation Guide

Originally published on xhalford.com


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 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.
  • 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, the Linux kernel, and the Linux firmware package to help support common hardware on your device.

$ pacstrap /mnt base linux linux-firmware
Enter fullscreen mode Exit fullscreen mode

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

genfstab -U /mnt >> /mnt/etc/fstab
Enter fullscreen mode Exit fullscreen mode

Change Root Into Your New System

Chroot command to change root into this new installation.

arch-chroot /mnt
Enter fullscreen mode Exit fullscreen mode

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.

$ ls /usr/share/zoneinfo/
Enter fullscreen mode Exit fullscreen mode

And what city is the nearest one to your location.

$ ls /usr/share/zoneinfo/region/
Enter fullscreen mode Exit fullscreen mode

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.

$ ln -sf /usr/share/zoneinfo/REGION/CITY /etc/localtime
Enter fullscreen mode Exit fullscreen mode

Entering the following, will generate the adjtime file.

$ hwclock --systohc
Enter fullscreen mode Exit fullscreen mode

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.

$ pacman -S nano
Enter fullscreen mode Exit fullscreen mode

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

$ locale-gen
Enter fullscreen mode Exit fullscreen mode

Set the LANG Variable

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

$ nano /etc/locale.conf

LANG=en_GB.UTF-8
Enter fullscreen mode Exit fullscreen mode

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, we need to set the keyboard layout for our region. Refer to that article section, to find your KEYMAP value.

$ nano /etc/vconsole.conf

KEYMAP=uk
Enter fullscreen mode Exit fullscreen mode

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.

$ nano /etc/hostname

desktop
Enter fullscreen mode Exit fullscreen mode

Then we need to add our hosts to the /etc/hosts file. Using our hostname (e.g. desktop) where appropriate.

$ nano /etc/hosts

127.0.0.1   localhost
::1         localhost
127.0.1.1   desktop.localdomain desktop
Enter fullscreen mode Exit fullscreen mode

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.

$ passwd
New password:
Retype new password:
passwd: password updated successfully
Enter fullscreen mode Exit fullscreen mode

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.

$ pacman -S grub efibootmgr os-prober dosfstools mtools
Enter fullscreen mode Exit fullscreen mode
  • 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/.

$ mkdir /boot/efi
Enter fullscreen mode Exit fullscreen mode

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

$ mount /dev/nvme0n1p1 /boot/efi
Enter fullscreen mode Exit fullscreen mode

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

$ grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub_uefi --recheck
Enter fullscreen mode Exit fullscreen mode

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

$ grub-mkconfig -o /boot/grub/grub.cfg
Enter fullscreen mode Exit fullscreen mode

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!

Top comments (0)