Arch Linux Re-Installation - Part 3
January 17, 2019
Welcome to the third and final part of my series of posts regarding my process for reinstalling Arch Linux. This post will build on the topics I discussed in the first part and second part of this series, so it is my strong reccomendation that you read those posts first before continuing with this one.
At the conclusion of the last part, I had formatted the drive as necessary and mounted my three partitions (/, /home, and /boot) to the hard drive. Therefore, the only steps remaining were to simply install Arch and set up the bootloader, as well as a few other small tasks like setting up an fstab and making a hosts file.
The actual installation process for Arch almost couldn't be simpler. To install the OS, I will run the 'pacstrap' utility. 'pacstrap' takes as its arguments a directory to install in (this will be /mnt, our root) as well as a list of packages to install by default. The only packages I installed at the very begining were 'base' and 'base-devel', which are core components of the OS. Run 'pacstrap' as follows:
pacstrap [INSTALL DIRECTORY] [SPACE DELIMITED LIST OF PACKAGES]
After this was done, Arch was on the system! I was not yet quite done, however. The next step was to generate an fstab file and install a bootloader.
Generate fstab and Install GRUB
My next task was to make an 'fstab' file. The fstab file is used by the system to locate partitions at boot time and mount them automatically. The easiest way to create one of these files is by using the 'genfstab' command. The 'genfstab' command will take a directory with mounted drive(s) and return specially formatted text that lists the partitions mounted there and that can be output into an fstab file immediately. When I used it, I passed the -U option to make it output uncommented UUID's, which helps avoid issues that may arise in the case of, say, a partition name change. I wanted the output of this command to go to /etc/fstab on my new system, so I output to that file in the context of my /mnt directory. Run 'genfstab' as follows:
genfstab -U [PATH TO ROOT PARTITION MOUNT POINT] >> [PATH TO /etc/fstab ON MOUNTED ROOT PARTITION]
This created a perfectly functional fstab file for me, which means it was time to install a bootloader.
Before I did anything else, I used 'chroot' to change my root directory into what was currently my /mnt directory. This allowed me to execute commands as though this directory was my real root, and since when I was using it, it was going to be, this was what I wanted. I ran 'chroot' like so:
arch-chroot [PATH TO MOUNTED / PARTITION]
With my root changed, the next step was to install a bootloader. I chose GRUB, the GNU bootloader, because it is pretty much the best one available for Linux. I installed it with the 'pacman' package manager like so:
pacman -S grub
With GRUB installed by our package management utility, the next step is to install the bootloader within its own context to a drive:
grub-install [PATH TO DRIVE DEVICE FILE]
Notice that 'grub-install' points to a drive and not a partition. The last part of GRUB installation is to make a configuration file for it to use. I did this with the 'grub-mkconfig' utility, passing the -o option to specify the output location (I sent mine to /boot/grub/grub.cfg):
grub-mkconfig -o [PATH TO CONFIG FILE LOCATION]
And with that, GRUB is installed and ready to go, and Arch will boot up and run great now!
There are a few things left that I did to round out my install. Namely, I set my timezone, locale, and hostname, and set up a password for root.
To set the timezone, use the 'ln' command to create a symbolic link from the location of the timezone file to /etc/localtime:
ln -sf /usr/share/zoneinfo/[REGION]/[CITY] /etc/localtime
I then ran 'hwclock' to set the hardware clock in relation to the timezone:
hwclock --systohc --utc
To set my locale, I first edited the /etc/locale.gen file to uncomment my language (for me, 'en_US.UTF-8'). Then, I ran the handy 'locale-gen' program to generate a locale for me:
I then set the LANG value in /etc/locale.conf to my language (again, 'en_US.UTF-8'):
echo "LANG=[LOCALE LANGUAGE]" > /etc/locale.conf
Lastly, to use that value in the session I was currently running, I exported the LANG value:
export LANG=[LOCALE LANGUAGE]
With the locale set, the next thing to do was to set a hostname. To do this, I edited two files: /etc/hostname and /etc/hosts. The first did not exist to begin with, so I simply created it with the content I needed using the 'echo' command:
echo "[HOSTNAME"] > /etc/hostname
Your hostname can be whatever you want, but if you have a FQDN, you should use it. Next, I opened and edited the /etc/hosts file. This file already had some content, but I needed to add an entry for '127.0.1.1' that included my hostname and my local domain in the following format:
127.0.1.1 [HOSTNAME].[LOCALDOMAIN] [HOSTNAME]
Again, if you have a FQDN, use it here.
The very last thing that I did during my install that I will cover here is setting a root password. This is a very simple process. Since I was already logged in as root by default, I simply ran the 'passwd' command with no arguments:
This will prompt you to enter and confirm a new password. When you are done, root will now only be accessible if you log in with that password.
Where to Go from Here
If you have been following this series as a guide to install your own Arch distro, congratulations! Arch should now be successfully installed and ready to use. It will be, however, extremely bare-bones.
Some things to do from here include creating a regular user and giving them 'sudo' privileges, installing a networking manager ('networkmanager' is a decent one, and available in Arch's default repositories), installing a desktop environment or window manager, installing some other utility programs (like vim), and more. I won't be covering any of those in this particular series, but suffice it to say, if you got this far, you should be more than ready to take on any of those challenges.
That will do it for this series on my Arch Linux reinstallation adventures. Thanks for reading, and I hope it was useful or informative to you in some way. See you next time!