In Part 1 I create a virtual machine to host Arch Linux and booted the installation media. In this part I will begin installing Arch by following the wikis installation guide.
The guide starts by having me check the UEFI and keyboard settings. I wont be using UEFI and the defauly keyboard layout is US so I don’t need to make any changes. Next the guide tells me to confirm that I have an active internet connection. I do this by pinging an internet address. The response looks good.
Next as instructed I run the following command to make sure NTP is active. This should ensure that my system date and time are accurate.
timedatectl set-ntp true
Now for the first step that requires some planning. The virtual machines hard disk must be partitioned. This means dividing the hard drive into logical sections that will each be used for specific purposes. In the past when installing Linux I usually click a button that will automatically partition the drive based on standard practices. In Arch it needs to be done manually. I haven’t needed to partition a hard disk for any OS for a long time.
My first decision is deciding if I will be using a MBR or GUID style partition table. MBR is required for some legacy operating systems or hardware. Since I don’t have these requirements I’ll use the more modern GUID. There are a lot of options for partitioning a Linux system. I am going to go with a fairly straight forward one and create 3 partitions.
- Boot- this will contain the machines bootup information. The guide recomends 100MB-300MB in size. I’m going to just allocate 300MB because it’s such a small amount of space.
- Swap- This will be swap space for the VM to use. Essentially it acts as extra memory. The old rule of thumb is to have a swap partition that is twice the size of your memory. That rule is outdated. If you need to use hibernation features you want your swap partition to be at least the same size as your memory. I won’t use hibernation so I am going with a 2GB swap partition.
- Root- This will be the directory that all other directories reside in. Think of it like the C: drive on most Windows computers. Ill use all of the remaining hard drive space for this.
The install guide recomends using gdisk for GUID partitions so that’s what I’ll do.
I startup gdisk and it asks which device I would like to work with. Hard disk devices are treated as files (everything in Linux is a file) and they are found in /dev. I checkout /dev and find that my drive is as sda so I input that drive path to gdisk.
gdisk warns me that no partition table was found. Then it presents me with a command prompt and tells me to type “?” for help. I go ahead and get the help menu.
Alright it’s telling me to press n for a new partition so I follow it’s instruction. I’m asked which partition number to use. The default is 1 so I leave the default. Next it asks me where I would like the first sector of this new partition. I want it to be located at the beginning of the drive so again I leave the default. Now I’m asked where the end of the partition should be. I want a 300 MB partition so I enter +300M. Finally I’m asked which filesystem type I would like to use. The default is Linux filesystem so again I leave the default.
Great I have my boot partition ready to go. Now I need to setup my swap partition. Again I select mostly the defaults. This will give the partition the number 2 and will start it directly next to my boot partition. For the size I use +2G so it will be 2 GB in size. The big difference this time is that I use the hex code 8200 to define this partition as the type “Linux swap”.
The last partition is for root. Since I just want to use up the rest of the drive and have the partition type be “Linux filesystem” I just use all defaults.
These partitions have all been defined but they haven’t been written to disk yet. To write the changes that I made I type “w”.
Now that I have my partitions created I need to format them with a file system. Since the partitions were created on /dev/sda they now show up as /dev/sda1, /dev/sda2, and /dev/sda3. They can be seen using the lsblk command.
The Arch install guide has the following tip.
To create a new file system of type fstype on a partition do: # mkfs.fstype /dev/partition
There are a lot of file system options out there but in my experience the most common is ext. I was going to format both the boot and root partitions with ext4. However on the arch wiki it mentions that syslinux (the boot loader that I will use) does not support ext4 partitions with the 64bit feature enabled. I tried formating the partition with ext4 using options to disable the 6bit feature but it wouldn’t work for me. Instead I just used ext3 for my boot partition and ext4 for my root partition. So I format my partitions using the commands “mkfs.ext3 /dev/sda1” and “mkfs.ext4 /dev/sda3”.
Formatting the swap partition is a little different. I follow the instillation guide again and use the command “mkswap /dev/sda2” to format my second partition. Then I use the command “lsblk -no UUID /dev/sda2” to get the UUID of the partition.
According to the install guide I’ll need this UUID later to make sure the swap is enabled on boot. Now I enable my swap partition with swapon.
To be able to read and write to my new sda3 partition I need to mount it. The best place to mount a device like this is the /mnt folder so I use the command “mount /dev/sda3 /mnt”. Then I cd into my mounted partition.
I will need to mount my boot partition so I create a folder for it and mount it as well.
All of my partitions are setup and accessible so it’s time to install the operating system onto my virtual machines hard drive. The install guide recommends that I edit my mirror list. This list determines where my operating system will go online to get updates and new software packages. The guide says “This file will later be copied to the new system by pacstrap, so it is worth getting right.” Arch provides a tool to check your connection speed to mirrors and output the fastest ones. I create a backup of the default mirror list and run rankmirrors to output the fastest 10 mirrors. I use this output to overwrite my default mirror list.
Ironically only about half of the mirrors that rankmirror returned were from the USA where I am located. Some others were from Germany, Canada, and Belgium. The install guide also warns that you don’t want to use out of synch mirrors even if they are fast. To make sure I’m not using any bad mirrors I check the Arch mirror status page and lookup the 10 mirrors that rankmirrors gave me. I actually did find 1 out of synch mirror in my list so I commented it out leaving me with 9 fast mirrors.
Arch provides a script to install the essentials of the operating system called pacstrap. The install guide tells me to install using “pacstrap /mnt base”. This will install the “base” package to the “/mnt” directory which is where I have my root partition mounted. The base package is a bare bones set of packages that are meant to get you up and running. Details of the packages can be found here. I input the command and let the install run.
After a few minutes of downloading and installing packages pacstrap finished. When I list the directories in /mnt now I can see what looks like a standard Linux set of folders.
Next I need to generate an fstab file. This file is responsible for telling the computer how to mount that partitions when the computer boots. Arch provides a script to help with this also called “genfstab”. The install guide recomends running “genfstab -p /mnt >> /mnt/etc/fstab”. Then it recomends checking that the /mnt/etc/fstab file that is generated looks correct. I run the command then take a look at the new fstab file.
This all looks good. The fstab file lists /dev/sda3 as my root partition, /dev/sda1 as /boot, and /dev/sda2 as swap. Also the swap UUID matches the one that I recorded earlier. Now I can chroot into the operating system. The command “arch-chroot /mnt” makes the /mnt folder my new root folder. This means that anything else I do will effect my newly installed OS instead of the live cd that I have been running from so far.
At this point it’s time to start adjusting some settings for the operating system. First the install guide has me set the time zone by creating a symbolic link from my local time zone to /etc/localtime. Then I run “hwclock –systohc –utc” to synch the hardware clock. I’m not sure if I needed to do this second step with VirtualBox but I figured it couldn’t hurt.
Now I need to set the locale of the OS. For english speaking US I need to uncomment “en_US.UTF-8 UTF-8” and “en_US ISO-8859-1″ from the /etc/locale.gen file. Then I need to create the file /etc/locale.conf and enter the string LANG=”en_US.UTF-8”. This is all basically to set the prefered language and character codes for my operating system. I had to use google to find the particular codes for my region and language. Finally I run locale-gen to generate my locale settings.
The next step is to set a hostname for the machine. I will call my machine “ArchPen” which is short for Arch pentesting. To do this I just put the hostname in a file called /etc/hostname. Then I set a password for my root user account using passwd.
Almost there! Basically the whole OS is configured and ready to go. Now I need to install a bootloader. This is how the machine knows where to find my operating system when it starts (in my case a virtual machine). I’m going to use the syslinux bootloader. To install the syslinux files I use the pacman package mangager command “pacmand -S syslinux”. To configure syslinux I run another script provided by Arch called syslinux-install_update. This automates some basic setup tasks for the syslinux bootloader.
I need to setup an initial ramdisk for the system to use. I just use the command “mkinitcpio -p linux” to use the default linux settings. Now all that’s left to do is exit my mounted operating system, unmount my partitions, and set the disk to bootable.
The command “sgdisk/dev/sda –attributes=1:set:2” means set partition 1 of sda to 2 (meaning bios bootable).
After my reboot I am greeted with my syslinux bootloader.
Then I’m sent to my new operating systems login screen.
Awesome! It was a lot more work to install Arch than your typical modern OS installer but that’s the whole point of Arch. You have complete control over the OS and can set it up any way you want to. The added choices and complexity also force you to learn and think along the way. In the next part of this series I’ll be doing some basic post installation setup.