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

  1. Download Arch iso image from here: Download
  2. Open VirtualBox and click "New". Then select OS type as Arch 64 bit. I just keep everything else as default for now.
  3. Once the VM is built, click "Start" to boot the machine. Select the downloaded iso image as the startup disk.
  4. Press "Enter" to select boot from medium or do nothing and wait for the timer to run out.
  5. 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

  1. Note: I'm booting with BIOS, so the directory /sys/firmware/efi is missing.
  2. 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
  3. 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
  4. Next, I need to format disk with:
    mkswap /dev/sda1 # Swap partition 1G
    mkfs.ext4 /dev/sda2 # Storage partition 7G
  5. 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

  1. I need to install linux kernel and other softwares. It's better to install utility tools like vim, man-db, man-pages and texinfo at this stage.
    pacstrap /mnt base linux linux-firmware vim man-db man-pages texinfo
  2. Next I should generate the disk partition tags info for future mounts.
    genfstab -U /mnt >> /mnt/etc/fstab
  3. Change to the new system root user and enter the user space.
    arch-chroot /mnt
  4. 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
  5. Next edit /etc/locale.gen file and uncomment the line en_US.UTF-8.
    Create /etc/locale.conf and add the line LANG=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
  6. 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
    # --------------------
  7. Change the root password with passwd.

Bootloader Installation

The following steps are taken dicretly from this Wiki.

  1. Since I'm booting with BIOS, I'll install GRUB bootloader. Pick suitable bootloaders from here.
  2. 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
  3. Now with everything done, I can do exit and shutdown -h now.

Tweaks & GUI

  1. Eject the iso image disk from VirtualBox by click Settings > Storage and the icon with a disk and a triangle on the right.
  2. Now start the VM and I'm greeted by the Arch Linux OS.
    I can login as root with the password I set earlier.
  3. 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
  4. 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
  5. Install the basic GNOME GUI with xorg and gnome pacakges.
    # Install packages
    pacman -S xorg
    pacman -S gnome

    # Run GUI to see if the packages are installed correctly systemctl start gdm.service
  6. Restart machine and enable GUI service at startup time.
    systemctl enable gdm.service

    # Reboot machine to see the effect
    reboot
  7. Note: It's better to give the VM more graphic RAM by going to Settings > Display.
  8. 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 number 3 at the end of the line with linux command and press Ctrl-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