Setting up a basic Arch Linux VM on Ubuntu 24.04

Introduction

Let’s set up an Arch Linux VM on a Ubuntu 24.04 host system.

There is great material out there, e.g. this guide on installing Arch Linux, but I was missing small pieces here and there. Hence this post.

Install Virtualbox

One tool to manage virtual machines is Virtualbox. To install it run

sudo apt install virtualbox

For a more detailed guide please see this page.

Now if you enter

virtualbox -h

in your terminal you should see something like

This also means you should be able to start the graphical user interface

Download The ISO Image

Go to https://archlinux.org/download/ to download the torrent file

which should show up as something like archlinux-2024.10.01-x86_64.iso.torrent in your ~/Downloads folder.

In order to download the iso install qbittorrent via

sudo apt install qbittorrent

Now you should be able to double click the archlinux-2024.10.01-x86_64.iso.torrent file, starting the qbittorrent graphical user interface. Once your download is completed you should have the file archlinux-2024.10.01-x86_64.iso in ~/Downloads. Now you can terminate qbittorrent as we won’t be needing it anymore.

Create The Arch Linux VM

Start the virtualbox app and click “New”

Select the the archlinux-2024.10.01-x86_64.iso file and choose a name for your VM, I’ll call it “archie”

Select the compute hardware specs and tick the “Enable EFI” box

Set the storage hardware specs

Configure The Arch Linux Guest OS

Now the image should be created. Time to start it and set up the guest OS.

After clicking “Start, a new window will open, you will see 3-4 startup options and a count down, select the first one or just let the counter run out.

Keyboard layout

Now we follow the steps in this guide on installing Arch Linux from 1.5 Set the console keyboard layout and font onwards (only relevant if your keyboard layout is a non-US layout). To list the keymap run

localectl list-keymaps

This seems to enter a vi editor (basic commands) by default. To quit the editor enter :q. To set the keymap run

loadkeys YOURKEYMAP

Boot mode

Enter

cat /sys/firmware/efi/fw_platform_size

mainly to check 1) if the efi/ directory is present (if not you forgot to tick “Enable EFI” in the virtualbox interface (see above). If the directory is present you should get 64 returned and all is good.

Internet sanity check

Do we have internet access? Run

ping archlinux.org

should show something like

and interrupt it at some point with CTRL + C after a few packages were sent, I lost patience at 3 evidently.

Check the time

Run

timedatectl

In my case the time zone is off but the rest is fine. To get the available commands run

timedatectl -h

In my case I want run

timedatectl set-timezone MYZONE/MYCITY

Available values for MYZONE and MYCITY can be found through entering one letter after the other and the Tab key, e.g. producing Europe/London`.

Disk business overview

We want to assign parts of our hard drive reserved for this image to partitions and tell the Arch OS where it can find what.

What we are going to do is create three partitions, assign their types and mount them. The relevant tools are: fdisk, lsblk, mkfs, mwswap, mount and swapon.

In the following table you can see what our setup will look like once we stepped through the upcoming commands

Order created in with fdiskPartition typeDevice identifierSizeFile System TypeMount pointfdisk Start Sectorfdisk End Sector
1EFI system partition/dev/sda11 GBFAT32/boot20482099202
2Linux swap/dev/sda24 GBSwapswap210124810489858
3Linux root/dev/sda359 GB (rest)ext4/10491904134217727

During disk partitioning with fdisk you will be asked from which start sector to which end sector the partition should stretch. A sector, turns out, is span of 512 bytes. So based on this helpful StackExchange post the logic is as follow

(n_hd * 1024**3 + n_swap * 1024) / 512 + start sector = end sector

So if we want to assign a partition of size 3 GB we would use n_hd = 3 and n_swap = 1 (unless we feel like assigning for for the swap header). The start sector will be suggested to us by fdisk during execution. A full example:

(1 * 1024**3 + 1 * 1024) / 512 + 2048 = 6293506

So our 3GB + 1KB partition would start at sector 2028 and end at 6293506.

Alright let’s do it!

Partitioning the disk

When you run

fdisk -l

you should see something like

We will use the device /dev/sda. In case you are curios (what that stands for see here and here) and ignore /dev/loop0.

So let’s start partitioning by running

fdisk /dev/sda

The first partition we want to create is our 1GB EFI system partition.

Type: n, enter, enter, enter, 2099202

The number can be obtained using our logic from above, we calculate the end sector (1 * 1024**3 + 1 * 1024) / 512 + 2048 = 2099202

Onto the 4GB sized swap partition.

Type: n, enter, enter, enter, 10489858

The number of the end sector is obtained using (4 * 1024**3 + 1 * 1024) / 512 + 2101248 = 10489858

Lastly to our 59GB root partition.

Type: n, enter, enter, enter, enter

Here we don’t need to calcualte the final sector because we just fill up the remaining sectors with out partition.

You are not done!

Type w and press enter to write the table to disk. If you quit without doing that the table you have created is discarded.

To sanity check run

fdisk -l

and you should see something like

If you do not you forgot the w at the end of the fdisk process. But if that happens to you, know the pain is shared.

Formatting The Partitions

Next let’s assign the partition types

First the ext4 type to the root partition (/dev/sda3)

mkfs.ext4 /dev/sda3

then swap to the erm swap partition (/dev/sda2)

mkswap /dev/sda2

and finally FAT32 to the EFI partition (/dev/sda1)

mkfs.fat -F 32 /dev/sda1

Mount The Partitions

Now let’s mount the partitions using

mount /dev/sda3 /mnt

mount --mkdir /dev/sda1 /mnt/boot

swapon /dev/sda2

Install Packages

Now let’s install some helpful packages

pacstrap -K /mnt base linux linux-firmware

Note that this will download ~530MB and may take a few minutes to install after the download.

Configuring The Install

Time to

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

Change the root dir

arch-chroot /mnt

Symbolically link the timezone config

ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime

Set the clock

hwclock --systohc

To set the locale you need a text editor. I prefer vim. So let’s install it. The next lines are a rough guide on what to do to set the US UTF-8 locale.

First install vim with

pacman -S vim

Then use vim to edit

vim /etc/locale.gen

Witihin vim search for “en” by typing

/en + enter

Then switch to insert mode by typing

i

With normal key bindings delete the # in front of en_US.UTF-8 UTF-8. And leave the insert mode using

ctrl + c

To save and exit run

:x + enter

Now run the locale generator using

locale-gen

Write to the locale.conf file using echo "LANG=en_US.UTF-8 >> /etc/locale.conf

Check that the file contains the line we just passed with head /etc/locale.conf

After the locale bit is done let’s do some more random things

echo "KEYMAP=us" >> /etc/vconsole.conf

To check run head /etc/vconsole.conf.

To name your host run echo "YOURFUNKYNAME" >> /etc/hostname

Sometimes running mkinitcpio -P (will take a moment) helps, although apparently not required.

Let’s set the root password so we can log in after the upcoming reboot using

passwd

Boot Loader

Almost done. Now we need to tell the boot loader how to trigger our Arch setup.

First install the efibootmgr tool using

pacman -S efibootmgr

For what’s next we need to know the root UUID. To get the root UUID run head -n 10 /etc/fstab and select the value for /dev/sda3.

Now check presence of vmlinuz-linux and initramfs-linux.img using ls /boot/.

Then let’s create the bootloader entry using

efibootmgr --create --disk /dev/sda --part 1 --label "My Arch Linux Boot Option" --loader /vmlinuz-linux --unicode 'root=UUID=YOURSDA3UUID rw initrd=\initramfs-linux.img'

Now, suddenly, we are pretty much all done. 😛 Enter exit or ctrl + d to leave chroot environment.

Detaching

To verify if we can detach the partitions run

umount -R /mnt

If that was successful run

reboot

Now the vm machine should reboot.

Logging in

If everything worked out correctly you should see the following after the reboot

Here enter root and then use the root password you’ve set above. If that worked you should see the glorious

Conclusion

Kid: How do you know someone uses Arch Linux?

Dad: They will tell you.

by nixcraft @ reddit

Welcome to the “they”! 🙂

2 thoughts on “Setting up a basic Arch Linux VM on Ubuntu 24.04

Leave a comment