Arch Linux Installation Guide Part 1

Jan 24, 2018


Arch Linux is a Linux distribution known for its not-so-beginner-friendly command line installer, no ready-to-use system after installation and requirement of above average knowledge of command line. However, Arch Linux allows me to set up a system in my desired state in shortest possible time with least effort. This is why I keep coming back to Arch Linux even after some of its annoyances.

This guide is written primarily for my reference, as someone who has installed Arch Linux several times, I still can't remember all the installation steps perfectly. Most of the steps have been taken from Arch wiki and should work on other setups also.

All the commands are run in root shell unless otherwise specified.

0. Check your network connection

If you are behind a captive portal, use linkslinks to open browser and login into your network. For WiFi connections, use wifi-menuwifi-menu. LAN connections should not require any setup. The boot environment should automatically detect any wired connections. After connecting, test your connection by pinging any website:

ping -c 5 google.com
ping -c 5 google.com

1. Setup SSH

This step is not mandatory, though I prefer to use this method to install Arch Linux, as it provides me the convenience of copying and pasting the commands directly from Arch wiki.

By default the Arch Linux rootroot account password is empty. We need to set up a password for rootroot account, which is needed for an SSH connection.

passwd
passwd

Now we need to change the setting to permit rootroot login via SSH in /etc/ssh/sshd_config/etc/ssh/sshd_config. Check that PermitRootLogin yesPermitRootLogin yes is uncommented in this file. If this line is not present there, add this to the end. Now start the sshd.servicesshd.service by issuing the command

sudo systemctl start sshd.service
sudo systemctl start sshd.service

Also, note the IP address of the target machine by inspecting the output of the following command.

ip addr
ip addr

Pro tip: One liner to get only the IP address

ip -o -4 addr show | awk -F '[ /]+' '/global/ {print $4}'
ip -o -4 addr show | awk -F '[ /]+' '/global/ {print $4}'

Now on your host machine, connect to the target machine via SSH using the following command

ssh root@ip-address-of-target
ssh root@ip-address-of-target

2. Partition the disks

If Windows 8 or above is already installed on your machine, then your hard disk is probably using GPTGPT partitioning scheme. In that case, use gdiskgdisk to partition your hard disk. If you use fdiskfdisk on a GPT partitioned HDD, there is a possibility of data loss. fdiskfdisk understands GPTGPT partitioning scheme also.[1]

My preferred setup is to have one root partition and one home partition and use EFIEFI partition created by Windows to install boot-loader. The root and home partition will be formatted using ext4ext4 file-system and the EFIEFI partition should be formatted using FAT32FAT32 file-system.

For this guide, I am assuming that the EFIEFI partition is sda1sda1, root partition is sda9sda9 and home partition is sda10sda10.

Now to format the partitions with ext4ext4 file-system:

mkfs.ext4 /dev/sda9
mkfs.ext4 /dev/sda10
mkfs.ext4 /dev/sda9
mkfs.ext4 /dev/sda10

3. Mount the partitions

Now mount the root partition (sda9sda9 in this case) to /mnt/mnt

mount /dev/sda9 /mnt
mount /dev/sda9 /mnt

If you have created any other partitions in previous steps, mount them at appropriate locations.

mkdir /mnt/home
mount /dev/sda10 /mnt/home
 
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
mkdir /mnt/home
mount /dev/sda10 /mnt/home
 
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot

4. Install the base file-system

To install the base system and some development tools, issue the following command.

pacstrap /mnt base base-devel
pacstrap /mnt base base-devel

This will take a while to download and install. After it finishes, it will give you a bare-bone Arch Linux system with just the tools required to run a Linux distribution, no other software is installed.

5. Generate /etc/fstab

The /etc/fstab/etc/fstab file stores the information about file systems of partitions and how to mount the partitions on system boot up. To generate this file, issue the following command:

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

If you prefer to use partition labels (sda1, sda9 etc.) instead of UUID, then use -L-L flag in place of -U-U.

6. chroot into the system

From the Arch wiki :

Chroot is an operation that changes the apparent root directory for the
current running process and their children. A program that is run in such a
modified environment cannot access files and commands outside that
environmental directory tree. This modified environment is called a chroot
jail.

At this step, we will go to the root of the newly installed system at /mnt/mnt and pretend as if we are logged into this system.

arch-chroot /mnt
arch-chroot /mnt

7. Setup the time zone, locale, and hostname

Browse the /use/share/zoneinfo/use/share/zoneinfo directory to find your location entries. My location is India, so I will use this command.

ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime

To set the hardware clock:

hwclock --systohc
hwclock --systohc

To set the locale for your system, open the /etc/locale.gen/etc/locale.gen file and uncomment your language. or run the following command for the default en_US.UTF-8 UTF-8en_US.UTF-8 UTF-8.

LANG=C perl -i -pe 's/#(en_US.UTF)/$1/' /etc/locale.gen
LANG=C perl -i -pe 's/#(en_US.UTF)/$1/' /etc/locale.gen

Now generate the localization with

locale-gen
locale-gen

Then set the LANGLANG variable in /etc/locale.conf/etc/locale.conf accordingly, or run the following command:

localectl set-locale LANG="en_US.UTF-8"
localectl set-locale LANG="en_US.UTF-8"

To set the hostname for your machine:

hostnamectl set-hostname your-host-name
hostnamectl set-hostname your-host-name

To allow other machines to address the host by name, it is necessary to edit the /etc/hosts/etc/hosts file to look like this:

127.0.0.1    localhost.localdomain          localhost
::1          localhost.localdomain          localhost
127.0.1.1    your-host-name.localdomain     your-host-name
127.0.0.1    localhost.localdomain          localhost
::1          localhost.localdomain          localhost
127.0.1.1    your-host-name.localdomain     your-host-name

8. Create user account

Before creating user account, set password for rootroot account

passwd
passwd

Now create a local account for your user

useradd -m -G wheel -s /bin/bash your-user-name
useradd -m -G wheel -s /bin/bash your-user-name

This will set up your user account, create a home directory for your user, set the default shell to bashbash and add your user to wheelwheel group, which is necessary to gain sudosudo access in later steps.

Set password for your user.

passwd your-user-name
passwd your-user-name

9. Enable sudo access

This allows you to use root privileges without using the root account. To enable this, first open /etc/sudoers/etc/sudoers file

nano /etc/sudoers
nano /etc/sudoers

Now uncomment the following line to enable rootroot privilege for all the users inside wheelwheel group:

# %wheel ALL=(ALL) ALL
# %wheel ALL=(ALL) ALL

Now you can safely disable root account

passwd -l root
 
# login into your user account
su your-user-name
passwd -l root
 
# login into your user account
su your-user-name

From this point onwards, it is necessary to append sudosudo to any command that requires rootroot privileges.

10. Install bootloader

My preferred bootloader of choice is grubgrub. To install grubgrub, we need to install following packages.

sudo pacman -S grub efibootmgr
sudo pacman -S grub efibootmgr

Now install grubgrub with the following command.

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

Here --efi-directory--efi-directory is the folder where the EFIEFI partition is mounted step 3 and --bootloader-id--bootloader-id is the label that will appear in your UEFI boot menu entry.

This particular step is specific to my machine's hardware, you might not need to run this step. I need to add pci=nommconfpci=nommconf to my kernel boot parameters in /etc/default/grub/etc/default/grub, otherwise ttytty prints error messages continuously.

Now run to generate grub configuration file.

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

If you encounter any errors related to lvmlvm during installation of grub, then follow these steps.

# come out of chroot
exit
mkdir /mnt/hostrun
mount --bind /run /mnt/hostrun
 
# back to chroot
arch-chroot /mnt
mkdir /run/lvm
mount --bind /hostrun/lvm /run/lvm
# come out of chroot
exit
mkdir /mnt/hostrun
mount --bind /run /mnt/hostrun
 
# back to chroot
arch-chroot /mnt
mkdir /run/lvm
mount --bind /hostrun/lvm /run/lvm

Now you can install grubgrub without any errors.

11. Configure the network

By default, your current system cannot connect to the network in the current state. I prefer to use NetworkManager for my network management, even when I am not using GNOME. For wireless networking, install the following additional packages.

sudo pacman -S iw wpa_supplicant dialog networkmanager network-manager-applet dhclient
sudo pacman -S iw wpa_supplicant dialog networkmanager network-manager-applet dhclient

NetworkManagerNetworkManager supports basic DHCP configuration. For full support, I have installed dhclientdhclient. NetworkManagerNetworkManager also supports automatic wired connection detection and comes with curses based tool nmtuinmtui to setup wireless connection.

To enable NetworkManager to start at system startup

sudo systemctl enable NetworkManager.service
sudo systemctl enable NetworkManager.service

12. Reboot now

If you had performed the lvmlvm troubleshooting steps during grubgrub install, then

umount /run/lvm
umount /run/lvm

Now exit from chrootchroot by typing exitexit in the shell. Unmount all the mounted partitions with:

umount -R /mnt
umount -R /mnt

Finally, reboot your machine by typing rebootreboot and remove the installation USB drive. If you are not able to boot into your system at this point, boot from the installation media again and attempt to fix the installation.

If you can see a terminal with a prompt for your username, congratulations! You have completed the first step towards building your own system.

I will be writing about making your system usable and stable in the second part of this guide.

Hope you enjoyed the post. Stay tuned :)