Chowhowse.com

Home

Arch Linux Re-Installation - Part 2

January 16, 2019


Hello, everyone. This is the second part of my series detailing how I reinstalled Arch Linux on my PC. In the first part of this series, I described creating a bootable live USB drive, booting it up, and getting networking to work on it. This blog post will continue directly where the previous one left off, so you should probably read it first before beginning this one.


Formatting the HDD

After I got my Internet connection working, the next step was to get my hard disk ready to have a new OS installed on it permenantly. To begin with, I identified the name of the device file corresponding to the HDD I was writing to by locating it in the output of the 'lsblk' command:


lsblk


This command will print a series of block devices. Among the list was the device I wanted to partition. For me, that device was labled 'sdb', but it may have a different name on your PC. Generally speaking, SATA HDDs are named under the Linux '/dev/' directory with the format 'sdX', where X is a lowercase letter. The first drive installed on a system (that is, the one plugged into the first SATA slot) would be named 'sda', and the second 'sdb' and so on. Using this, as well as the size information printed out by 'lsblk', you should be able to easily determine which drive device to use, even on multi-drive systems.


Before I go over how to format a hard drive from the terminal, I should talk about how I determined how many partitions I would need. Every Linux system needs at least 2 partitions, a regular partition to hold the file system, and a swap partition. A swap partition is used by the operating system as 'virtual memory', basically allowing your computer to use hard disk space for memory-intensive tasks and load programs that might actually take more memory than the physical RAM your system provides. As for the file system, while it is true that having one single partition hold the whole system is totally possible, I typically will actually create three partitions, a root (/), a home (/home), and a boot (/boot) partition, and divide my system amongst those. That is also what I did with this installation, so that is the process I will be describing here.


I partitioned the disk using the 'fdisk' command. 'fdisk' is an interative terminal program that has lots of partition manipulation features, but I used it for its most common task: making new partitions. Run 'fdisk' with the drive you want to edit as an argument to begin (in my case, I ran 'fdisk /dev/sdb'):


fdisk [PATH TO DRIVE DEVICE FILE]


This will bring up fdisk's dialog prompt. fdisk takes single letter characters as arguments. You can press 'm' and hit 'Enter' to see a list of all commands and their descriptions. Notice how the prompt mentions that changes made in fdisk are in memory only until you write them to a disk. This is good: if you mess up, just don't write the changes, and you won't cause any problems.


First, I needed to clear all the partitions that may already have been on the drive. Enter the 'd' command. If you have more than one partition on this disk, this will produce a list and ask you which to delete. Since I needed to clear all the partitions that were on my disk, I simply kept passing the 'd' command until I had removed them all.


Next, I needed to begin making my partitions. I started out with the boot partition. I made a new partition by entering the 'n' command. This command will ask you what partition type to make this (we want all of our partitions to primary partitions), what partition number it should have (I always go with the default), and at what sectors to begin and end your partition (which will determine the size). For each partition that I made, I started at the default sector. The end sector (the size) depends on the purpose of the partition. For the boot partition, 500MB is more than enough, so that is what I used. To pass this to fdisk, I entered '+500M' in the end sector dialog and hit enter.


The following list describes the sizes I used for my four partitions:



The process for creating these is the same as described for the boot partition above: 'n' for a new partition, 'p' for primary, default partition number and starting sector, and +XX for the end sector, where XX is the size of the partition (in the case of the home partition, I saved it for last so that I could just pass the default for its size as well). If you are asked at any point to delete a filesystem signature, just press 'y' to remove it.


A brief note about the swap partition: the size of the swap partition is usually determined in proportion to the ammount of RAM installed on the computer. There is no hard and fast rule, and, indeed, lots of arguments have been made regarding proper swap sizing, but a common rule of thumb is 1.5x to 2x the ammount of RAM installed on your system. I have 4GB of RAM on my system, so I went with 8GB of swap space. If you are using this post as a guide to install your own system, you should adjust your swap sizing accordingly.


When this process was complete, I saved all of my changes by entering the 'w' command (which wrote them to the disk PERMENANTLY and reformatted the drive). This exited fdisk in the process, and left my HDD ready to use.


The next thing to do before installing Arch is to make the partitions into usable file systems. As is typical on GNU/Linux, I made my system partitions into ext4 file systems. I did this to the boot, home, and root partitions (the /swap partition does not get made into a file system and will be handled differently). To do this, I used the 'mkfs' command, specifically 'mkfs.ext4'. This command takes as an argument the path to the device file that corresponds with the partition you want to make a file system on. To find this file, run 'lsblk' again:


lsblk


Listed in the output when I ran this command was the drive I just edited, along with a series of partitions on that drive. These partitions are named after the drive followed by a number. Since I edited the drive 'sdb', and I put four partitions on it, these partitions were named 'sdb1', 'sdb2', 'sdb3', and 'sdb4'. Each of these partitions has a corresponding device in the /dev/ directory, and each of the numbers corresponds to the drive number entered into the 'fdisk' command. In the output of the 'lsblk' command, I could also see the size of each partition, which allowed me to identify what each one was meant for. Using this information, I passed the 'mkfs.ext4' the device file locations of the three partitions I was formatting:


mkfs.ext4 [PATH TO PARTITION DEVICE FILE]


The last step in the process of formatting the drive is to make the swap partition active. I already determined which partition device file corresponed to my swap partition, so I simply ran the 'mkswap' command with the path to that file as an argument to set it as my swap partition:


mkswap [PATH TO SWAP PARTITION DEVICE FILE]


Now I wanted to set this swap partition as active using the 'swapon' command:


swapon [PATH TO SWAP PARTITION DEVICE FILE]


And that's that! With this process done, my drive was ready to have Arch installed on it.


Mounting The Filesystem

With my drive prepared, my next task was to mount the /root partition so that I could begin the installation process. Firstly, I mounted the root (/) partition to my /mnt directory using the 'mount' command (that is, /mnt is the path to my mountpoint):


mount [PATH TO ROOT PARTITION DEVICE FILE] [PATH TO MOUNTPOINT]


When that was finished, I ran the same command twice more, once for my /home partition and once for my /boot partition. However, in each of those cases I made a directory under the /mnt directory to use as a mountpoint (/mnt/home and /mnt/boot, respectively). I did this with the 'mkdir' command:


mkdir [PATH TO NEW DIRECTORY]


Once I had mounted these three file systems, I could begin installing Arch on them. I will cover that process in the next blog post.


System Time

There is one other thing I did before I got to the point of fully installing Arch, and that is set my system time to match ntp, and thus be correct. I did that with the 'timedatectl' command as follows:


timedatectl set-ntp true


I verified that this had worked by getting the time with the 'date' command:


date


This matched the clocks in my house, so I was good to go on the time front.


That covers it for this part of the series. I will conclude this series in the next post, which will cover what I did to actually install Arch and get it running. Thanks for reading this far, and be sure to check out the next post!


UPDATE: The last part of this Arch installation series is now available. Read it here.