Install Arch Linux on VirtualBox
Jan. 17, 2021, 20:48:50
People say Arch Linux is the ultimate Linux Distro for geeks.
It's very customizable and has detailed Wiki page on everything. However, it's also very tricky to setup compared to Ubuntu which basically works out-of-the-box.
So I want to document my successful setup of Arch Linux in Virtual Box booted with BIOS and GRUB here, as a reminder for myself and a guide for those who want to do the same setup.
Create VM
- Download Arch iso image from here: Download
- Open VirtualBox and click "New". Then select OS type as Arch 64 bit. I just keep everything else as default for now.
- Once the VM is built, click "Start" to boot the machine. Select the downloaded iso image as the startup disk.
- Press "Enter" to select boot from medium or do nothing and wait for the timer to run out.
- Greeting from the terminal! The ISO image is successfully loaded.
Now I must follow the official tutorial here: Tutorial. The following steps are directly taken from this tutorial (with modifications).
Firmware Setup
-
Note: I'm booting with BIOS, so the directory
/sys/firmware/efi is missing. -
After checking network connections, I need to enable time syncing with ntp servers.
# Check network connection
ip link
ping archlinux.org
# Enable time-syncing
timedatectl set-ntp true
# Check syncing status
timedatectl status
-
The next step is to partition the disk. The default storage space for this VM is 8GB. Based on an example given in the tutorial, I can assign 1GB for the swap partition and leaving the rest (7GB) as regular storage. A detailed example of partitioning with
fdisk .# Check storage name
fdisk -l
# Partition disk
fdisk /dev/sda
-
Next, I need to format disk with:
mkswap /dev/sda1 # Swap partition 1G
mkfs.ext4 /dev/sda2 # Storage partition 7G
-
Then I mount the volume I just partitioned for the software installation steps next. Also, I should enable swap partition.
# Mount storage volume
mount /dev/sda2 /mnt
# Enable swap
swapon /dev/sda1
# Check partitions are correct
lsblk
Software Installation
-
I need to install linux kernel and other softwares. It's better to install utility tools like
vim ,man-db ,man-pages andtexinfo at this stage.pacstrap /mnt base linux linux-firmware vim man-db man-pages texinfo -
Next I should generate the disk partition tags info for future mounts.
genfstab -U /mnt >> /mnt/etc/fstab
-
Change to the new system root user and enter the user space.
arch-chroot /mnt
-
Initialize and sync time with hardware.
# Create symbolic link to point localtime to US-pacific time
ln -sf /usr/share/US/Pacific /etc/localtime
# Sync with hardware
hwclock --systohc
-
Next edit
/etc/locale.gen file and uncomment the lineen_US.UTF-8 .
Create/etc/locale.conf and add the lineLANG=en_US.UTF-8 .# Uncomment line in /etc/locale.gen
sed -i 's/#en_US.UTF-8/en_US.UTF-8/g' /etc/locale.gen
# Generate locale
locale-gen
# Create /etc/locale.conf
echo 'LANG=en_US.UTF-8' > /etc/locale.conf
-
Set the VM hostname and list known hosts in
/etc/hosts .# Set hostname
echo 'HackerryArchDemo' > /etc/hostname
# List known hosts
# --------------------
# In /etc/hosts:
#
# 127.0.0.1 localhost
# ::1 localhost
# 127.0.1.1 HackerryArchDemo.localdomain HackerryArchDemo
# --------------------
-
Change the root password with
passwd .
Bootloader Installation
The following steps are taken dicretly from this Wiki.
- Since I'm booting with BIOS, I'll install GRUB bootloader. Pick suitable bootloaders from here.
-
Note: During the partitioning step,
fdisk has already left 1MB space at the front of the disk. So I can just install grub and generate the configuration file.# Install grub
pacman -S grub
grub-install --target=i386-pc /dev/sda
# Generate configuration file
grub-mkconfig -o /boot/grub/grub.cfg
-
Now with everything done, I can do
exit andshutdown -h now .
Tweaks & GUI
- Eject the iso image disk from VirtualBox by click Settings > Storage and the icon with a disk and a triangle on the right.
-
Now start the VM and I'm greeted by the Arch Linux OS.
I can login asroot with the password I set earlier. -
There are some network configurations to be done at this point. The default network manager is
systemd-networkd in the base package. It is, however, disabled by default. I need to enable them to connect to the internet. To read more here.# Enable network manager services systemctl enable systemd-networkd.service systemctl enable systemd-resolved.service -
Next, I need to configure the VM's network interface to use DHCP to get dynamic ip addresses by writing to
/etc/systemd/network/20-wired.network file.
The configurations are different for different connection types (read more from the link in the previous step).# In this case, my network is wired.
# Check connection type and network interface name with "ip link".
#
# ----------------------------------
# In /etc/systemd/network/20-wired.network:
#
# [Match]
# Name=enp1s0 # <- Network interface name
#
# [Network]
# DHCP=yes
# ----------------------------------
#
# Restart network manager
systemctl restart systemd-networkd.service
systemctl restart systemd-resolved.service
# Check status
systemctl status systemd-networkd.service
systemctl status systemd-resolved.service
# Check network connection
ping archlinux.org
-
Install the basic GNOME GUI with
xorg andgnome pacakges.# Install packages
pacman -S xorg
pacman -S gnome
# Run GUI to see if the packages are installed correctly systemctl start gdm.service -
Restart machine and enable GUI service at startup time.
systemctl enable gdm.service
# Reboot machine to see the effect
reboot
- Note: It's better to give the VM more graphic RAM by going to Settings > Display.
-
Note: If something goes wrong here and the machine tries to boot with GUI but fails, press 'E' when prompted to select boot method (as in Figure 1).
Add the number3 at the end of the line withlinux command and pressCtrl-X to boot into root terminal again (as in Figure 2).
Tada! An Arch Linux machine is installed on VirtualBox!
Useful Links/References:
Disk partioning with fdisk
Install Arch Linux with UEFI boot mode
Boot into Linux Command Line with GRUB