Ricing Series Part 1 - Installing Arch Linux in a VM
Table of Contents
Acquire an Installation Image⌗
The first thing we need to do is to obtain an image for Arch Linux. Visit the Arch Linux download page to download the ISO image.
Create a Virtual Machine and Load the Arch ISO⌗
I will be using Virtual Machine Manager (Virt Manager) for managing the virtual machines From the main page, click the “Create a new Virtual Machine” button and then choose “Local install media (ISO image or CDROM)”
From there, select the ISO we downloaded in the first step, set the amount of RAM and number of CPU cores to use in the VM and then boot into the system
Check Network Connectivity⌗
The first thing I typically do on any fresh install is ensure that the connection to the internet is working
# ping archlinux.org
Set the System Clock⌗
Next we set the system clock to ensure that it is accurate with the following command
# timedatectl set-ntp true
Partition the Disk⌗
For this virtual machine, I will be using the BIOS/MBR partition scheme with a single root partition and with no swap for this virtual machine and will use fdisk
There are many other partition schemes that can and should be used if done on real hardware (see Arch Wiki for more details)
Create a Root Partition with Fdisk⌗
Run the following command to list the current partition table on the virtual machine: # fdisk -l
The partition we care about here is /dev/vda. Run the following command to edit the /dev/vda block device: # fdisk /dev/vda
After entering the fdisk prompt, enter d to delete any existing partiton(s)
Next, we want to create a new partition using all remaining space and with type Linux
From the Fdisk prompt, press n to create a new partiton and then press enter through the remaining prompts to continue and accept the default values until reaching the main prompt again
From the main prompt, enter a to flag the newly created partiton as bootable, then w to save the changes and quit fdisk
Format the Partition⌗
Run the following command to create an Ext4 file system on the newly created partition
# mkfs.ext4 /dev/vda1
Mount the File System⌗
Next, run the following command to mount the root volume to /mnt
# mount /dev/vda1 /mnt
Update the Mirrorlist⌗
Run the following command to update the mirrorlist and speed up downloads before running pacstrap and installing software
# reflector --sort rate --latest 5 --save /etc/pacman.d/mirrorlist
Install Essential Packages⌗
# pacstrap /mnt base base-devel linux linux-firmware vim networkmanager grub amd-ucode neofetch
Configure the System⌗
Generate an Fstab File⌗
Run the following command to generate an fstab file
# genfstab -U /mnt >> /mnt/etc/fstab
Chroot into the New System⌗
Chroot into the new system
# arch-chroot /mnt
Set the Time Zone⌗
# ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
# hwclock --systohc
Set the Localization⌗
Find and uncomment (remove #) any needed locales from /etc/locale.gen
(e.g. en_US.UTF-8 UTF-8) and run the following command to generate the locales
# locale-gen
Create the /etc/locale.conf file and set the LANG variable accordingly
# /etc/locale.conf
LANG=en_US.UTF-8
Configure the Network⌗
Create a file at /etc/hostname with a single word to act as the machine’s
hostname
# /etc/hostname
myhostname
Additionally, create a file at /etc/hosts using the following format
(replacing myhostname with the hostname set in the previous step)
# /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 myhostname
Create a new Initramfs⌗
Create a new initramfs with mkinitcpio
# mkinitcpio -P
Set the Root Password⌗
Set the root password with the following command
# passwd
Install/Configure GRUB⌗
Install and configure GRUB
# grub-install --target=i386-pc /dev/vda
# grub-mkconfig -o /boot/grub/grub.cfg
Create a New User⌗
Edit the Sudoers File⌗
In order to allow our new user to use sudo, we need to edit the /etc/sudoers
file using the following command to edit the file: EDITOR=vim visudo
Add a non-root User⌗
Run the following command to create a new user, create the home directory at
/home/username, and add the user to the wheel group
# useradd -mG wheel sudacode
Set a User Pssword⌗
# passwd sudacode
Edit pacman.conf⌗
Next, I like to edit the /etc/pacman.conf to include things such as color, parallel downloads, and Pac-Man
Update the Mirrorlist⌗
Run the following command to update the mirrorlist for faster download speeds
# sudo reflector --sort rate --latest 5 --save /etc/pacman.d/mirrorlist
Enable Networking⌗
We already installed NetworkManager into the system in Install Essential Packages, so all we have to do now is enable it on next boot
# systemctl enable NetworkManager
Unmount and Reboot the Virtual Machine⌗
Exit the chroot by typing exit or pressing Ctrl+d, then unmount the drives
with umount -R /mnt, and finally, restart the machine with reboot
Eject the Live ISO/Set the Boot Drive⌗
At this point, we can to set the virtual machine to boot from the virutal hard disk and eject/remove the live iso from the virutal machine
Log Into New System⌗
Finally, upon the reboot, you should be greeted with the GRUB launch screen and sent to the login page for your system, where you’ll be able to use the credentials for the user we created in the Add User section