Installing Arch Linux with GNOME Desktop on Oracle VM VirtualBox
Arch Linux is a Linux distribution for computers with x86–64 processors. It adheres to five principles: simplicity, modernity, pragmatism, user centrality and versatility. Its unique package manager pacman is responsible for installing, updating, and removing software packages with complete tracking. It is designed entirely for free and open-source software, along with the support from the Linux community.
Sounds like a cool Linux distro, let’s install it! But the catch is — it ain’t as easy to install as with any other popular distribution, the reason being — Arch Linux doesn’t have a graphical installer. It is entirely command based.
A curious me wanted to find out what Arch was all about and tried to install it as a VM(coz I didn’t want to dual boot it for a trial — and thank god I didn’t!), until I ran into a nightmare of being stuck badly. After a few times of trying, I finally managed to install it. Yay!!
Seems daunting, but don’t worry, if you’ve got a good grip of working with a terminal (which I think you do — just because you are trying to install Arch😉), then it’s not as much of a challenge.
There is a saying,
Installing Arch can teach you Linux, unlike Ubuntu which will teach you Ubuntu.
I feel this is true. So let’s get started.
Step 1: Creating the VM
- Head over to the official downloads page of Arch Linux to download the ISO image. There are both torrent links and HTTP direct download links available.
- Open VirtualBox and click on New. Give a name to it, select a storage folder and select the Type & Version of the OS. In our case Type is Linux and Version is Arch Linux (64-bit).
- Next, select the amount of RAM. If you plan on installing a GUI desktop environment (which I recommend you should), then a minimum of 2 GB of RAM is required. If you wanna stick to the CLI, then a minimum of 512 MB would suffice.
- For the hard disk, select Create a virtual hard disk now and then select any of the disk file types you would prefer. Also select whether the storage should be dynamically allocated(recommended) or should be of a fixed size. Then select the virtual disk size — 8 GB recommended minimum (10 GB if you’re installing a GUI) and then click on Create.
- The VM is now created. Power it on and in the Select start-up disk menu, click on Add and select the previously downloaded ISO image to boot from. Once you do that and the system boots, you should see a screen like this:
- Select Boot Arch Linux and wait for the terminal to appear with root user automatically logged in.
Step 2: Partitioning disks
VMs usually boot in Legacy Mode which is an important point to remember. It means we need to create only a single partition — a root partition, no EFI partition required. We will be using the command line based partition manager fdisk for this purpose. Alternatively, you can also use cfdisk, an interactive version of fdisk.
Use this command to list all the disk and partitions on your system:
fdisk -l
Alternatively, you can also use to list the partitions:
lsblk
Other than loop/rom (which can be ignored), you must only see a disk /dev/sda
and select it for partitioning:
fdisk /dev/sda
If there are any existing partitions, I suggest you to delete them. This can be done by typing d in fdisk prompt, until no partitions are remaining. Then you can create a new partition by typing n. Then press p for primary partition and press enter for remaining options. It will by default assign a partition number 1 and uses the whole disk space — this is the root partition. Type w to write changes to the disk, and exit the fdisk command.
Step 3: Creating filesystem and modifying mirrorlist
Since there is a single partition, it will by default be /dev/sda1
and an EXT4 filesystem can be created as follows:
mkfs.ext4 /dev/sda1
Next, check whether you’re connected to an active internet connection:
ping archlinux.org
If you get reply bytes, you are connected. Use Ctrl+C to stop the ping reply. If not, check your host machine connection or VM Network settings.
The mirrorlist in Arch Linux is a file that contains various mirrors around the world form which packages are downloaded. But the problem is, the first mirror is automatically selected and they are not sorted in a right order for you. So if you just head to the install, it might be so slow that would take a long time to install or it might as well fail, wasting your time and bandwidth(😣). The solution is to retrieve a list of nearest and fastest mirrors. For this install the reflector tool:
pacman -Syy reflector
Then, get a good list of mirrors and save them to the mirrorlist. You can change the country IN(India) to your own.
reflector -c "IN" -f 15 -l 15 -n 15 --save /etc/pacman.d/mirrorlist
Step 4: Mounting the partition and Bootstrapping
Now you need to mount the root partition so that you will be able to install all the packages for Arch Linux.
mount /dev/sda1 /mnt
Now use the pacstrap script for bootstrapping the OS, which will install all the necessary packages:
pacstrap /mnt base base-devel nano
I have included nano because you need to edit some files later on. You might as well use vim instead. It will take a while to download and install the packages. If it fails in the middle, you can re-run the command and it will resume the download.
Step 5: Configuring the installed system
Now, generate the File Systems Table(fstab) file to define how disk partitions and file systems are mounted:
genfstab -U /mnt >> /mnt/etc/fstab
Now use arch-chroot to log into the mounted disk as root. You need to do some configurations here so that it can run properly when booted from disk.
arch-chroot /mnt
Setting up the locale
This is for configuring language settings, date and currency formats for the system. The file /etc/locale.gen
contains all the local settings and system language, but in a commented format. Open the file using vim/nano and remove the comment(the # symbol) from the line that contains the language you prefer. In my case, it is en_US.UTF-8. Next, generate the locale config file:
locale-gen
# Replace en_US.UTF-8 with your preferred language
echo LANG=en_US.UTF-8 > /etc/locale.conf
Setting up the timezone
Use the timedatectl command to set the timezone. Find your timezone by:
timedatectl list-timezones
And then set it up like:
# Replace Asia/Kolkata with your preferred timezone
timedatectl set-timezone Asia/Kolkata
Configuring network
You need to enter your hostname to the file /etc/hostname
, which can be anything. I’ll use the name arch.
# Replace arch with your choice of hostname
echo arch > /etc/hostname
Then create the hosts file,
nano /etc/hosts
and add the following lines to it:
# Replace arch with the hostname you chose earlier
127.0.0.1 localhost
::1 localhost
127.0.1.1 arch.localdomain arch
Setting the root password
Set the password for root account using the passwd command:
passwd
Step 6: Installing grub bootloader
In order to boot the OS into memory, you need the grub bootloader. First get the grub package:
pacman -S grub
Then, install and configure it with:
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
Step 7: Installing GNOME desktop environment (Optional)
If you need a GUI, you can proceed with the following steps. First install the X environment display server xorg:
pacman -S xorg
Next, install GNOME desktop environment and enable the display manager GDM:
pacman -S gnome
systemctl start gdm.service
systemctl enable gdm.service
Next, enable NetworkManager service:
systemctl enable NetworkManager.service
Step 8: Final Steps
If you have NOT enabled the NetworkManager service and want to stick to CLI, then you need to enable dhcpcd service:
systemctl enable dhcpcd.service
Now, exit from the chroot command,
exit
and reboot your system:
reboot
You will again encounter the boot menu you saw at the start, choose Boot Existing OS. And in the grub menu, choose Arch Linux. If you’ve followed the steps correctly(and are lucky enough 😜), you will see a login screen/prompt. Login with your password and have a good time exploring!
Troubleshooting
- If you are stuck in the grub prompt after rebooting, then unfortunately your installation might have failed. You need to do it again. Don’t give up!
- If you are stuck in a login loop in the GUI, then you can try restarting the GDM service,
sudo systemctl restart gdm.service
or, stop the service and start again:
sudo systemctl stop gdm.service
sudo systemctl start gdm.service
Bonus
Not a big one, but if you don’t want the boot menu to appear every time you power on the VM, there is a workaround(😬). Create a new VM and instead of creating a new Virtual Hard Disk, choose the already existing one from the VM you created above and power it on. And voila, you enter the grub menu directly and then to the login screen!