Shahzeb Ihsan

"The reasonable man adapts himself to the world; the unreasonable man persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw


Blog | Archive | About Me | Projects

Installing Arch Linux on VirtualBox

23 Jun 2015 | virtualbox, virtualmachine, archlinux, linux, development

Arch Linux has to be installed manually since the official Arch Linux ISO doesn’t contain an installer, additionally, no packages are included in the ISO, so a working internet connection is required during installation. If you’d rather just download a pre-configured Arch Linux VM, go here.

Most of the information below can be found in the official installation guide but some other information requires some Googling and a little bit of digging around on the Arch Linux wiki and forums.

Virtual Machine Configuration

Create a new virtual machine in VirtualBox for Arch Linux (sample configuration shown below). Once the VM is created, add the Arch Linux ISO to the CD/DVD drive.

Virtual Machine Configuration

Configuration of the highlighted settings in the screenshot below are important and the rest are optional. Arch Linux can run on a pretty low memory configuration so you can set the size of the display and base memories according to your preference.

For storage, I configured a “dynamically allocated” 8.0 GB hard drive image since I wanted to upload the resulting VMs to Dropbox, but I would recommend using a “fixed size” hard drive if you have space to spare on your host machine.

Network settings are important: at a minimum, you need to bridge your host machine’s network interface (which is connected to the internet) with your VM as shown in the following image:

Virtual Machine Configuration - Network

In case you would like any folders from your host machine to be accessible in your VM, the simplest way is to add them to the “Machine Folders” section under “Shared Folders” but do not select the “Auto-mount” option otherwise they will only be accessible as root (I’ve since moved to using sshfs for mounting my Windows host machine folders).

Installing Arch Linux

Now that the VM has been created with the ISO already inserted, start the virtual machine and login with user ID and password “root”.

Partitioning the VM's Hard Drive

You can partition the hard drive using either a single root partition or discrete partitions. I’ve chosen a mixture of the 2 partitioning schemes: 200MB as /boot for installing GRUB, 1024MB swap file and the rest allocated as a single root partition.

root@archiso ~ # lsblk
NAME             MAJ:MIN RM    SIZE  RO  TYPE  MOUNTPOINT
sda                8:0    0      8G   0  disk
sr0               11:0    1    637M   0  rom   /run/archiso/bootmnt
loop0              7:0    0  278.2M   1  loop  /run/archiso/sfs/airootfs
loop1              7:1    0     32G   1  loop
└─arch_airootfs  254:0    0     32G   0  dm    /
loop2              7:2    0    256M   0  loop
└─arch_airootfs  254:0    0     32G   0  dm    /  
root@archiso ~ # parted  /dev/sda  print
Error:  /dev/sda:  unrecognised  disk  label
Model:  ATA  VBOX HHRDDISK  (scsi)
Disk  /dev/sdai  8590MB
Sector  size  (logical/physical):  512B/512B
Partition  Table:  unknown
Disk Flags:
root@archiso ~ # parted  /dev/sda  
(parted)  mklabel  msdos  
(parted)  mkpart  primary  ext4  1MiB  200MiB  
(parted)  set  1  boot  on  
(parted)  mkpart  primary  linux-swap  210MiB  1177MiB  
(parted)  mkpart  primary  ext4  1024MiB  100%  
(parted)  print
Model:  ATA  VBOX  HARDDISK  (scsi)
Disk  /dev/sda:  8590MB
Sector  size  (logical/physical):  512B/512B
Partition  Table:  msdos
Disk  Flags:

Number   Start    End      Size     Type      File system   Flags
 1       1049kB   210MB    209MB    primary                 boot
 2       220MB    1234MB   1014MB   primary
 3       1234MB   8590MB   7356MB   primary
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0     8G  0 disk
├─sda1            8:1    0   199M  0 part
├─sda2            8:2    0   967M  0 part
└─sda3            8:3    0   6.9G  0 part
sr0              11:0    1   637M  0 rom  /run/archiso/bootmnt
loop0             7:0    0 278.2M  1 loop /run/archiso/sfs/airootfs
loop1             7:1    0    32G  1 loop
└─arch_airootfs 254:0    0    32G  0 dm   /
loop2             7:2    0   256M  0 loop
└─arch_airootfs 254:0    0    32G  0 dm   /
root@archiso ~ # mkfs.ext4  /dev/sda1  
root@archiso ~ # mkfs.ext4  /dev/sda3  
root@archiso ~ # mkswap  /dev/sda2  
root@archiso ~ # swapon  /dev/sda2  
Installing the Base System

Mount the root and boot partitions:

root@archiso ~ # mount  /dev/sda3  /mnt  
root@archiso ~ # mkdir  -p  /mnt/boot  
root@archiso ~ # mount  /dev/sda1  /mnt/boot  

Install the base system using pacstrap:

root@archiso ~ # pacstrap  -i  /mnt  base  base-devel  

And finally, generate “fstab”:

root@archiso ~ # genfstab  -U  -p  /mnt  >>  /mnt/etc/fstab  

Chroot into Your Newly Installed Base System

root@archiso ~ # arch-chroot  /mnt  /bin/bash  
root@archiso ~ # passwd
root@archiso ~ # useradd  [username]  
root@archiso ~ # passwd  [username]
root@archiso ~ # mkdir /home/[username]
root@archiso ~ # chown [username] /home/[username]
root@archiso ~ # pacman  -S  grub  os-prober  
root@archiso ~ # grub-install  --recheck  /dev/sda  
root@archiso ~ # grub-mkconfig  -o  /boot/grub/grub.cfg  
root@archiso ~ # exit  
root@archiso ~ # umount  -R  /mnt  
root@archiso ~ # reboot  

Network Configuration

After you restart your VM (you can now login as the new user you created above) and boot into your shiny new Arch Linux installation, you’ll realize that the network doesn’t work. Even though the network worked out-of-the-box in the ISO, for some reason, it has to be configured from scratch now :angry:. I find this feature very strange extremely annoying. I’ve seen this in other distros as well, even in some with fancy Live CDs. I wonder why the network configuration is not copied during installation (did I miss something during installation?).

$ cat  /etc/systemd/network/enp0s3.network  
[Match]
Name = enp0s3

[Network]
DHCP = ipv4
DNS = 8.8.8.8
DNS = 8.8.4.4
DNS = 123.241.172.101
DNS = 23.126.223.57
DNS = 210.57.226.138

[DHCP]
RouteMetric = 10
$ cat  /etc/systemd/network/enp0s8.network

[Match]
Name = enp0s8

[Network]
DHCP = ipv4

[DHCP]
RouteMetric = 20
$ cat  /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 123.241.172.101
nameserver 23.126.223.57
nameserver 210.57.226.138
$ sudo  systemctl  enable  dhcpcd@enp0s3.service  
$ sudo  systemctl  enable  dhcpcd@enp0s8.service  
$ sudo  systemctl  restart  systemd-networkd  
$ networkctl  
IDX LINK             TYPE               OPERATIONAL SETUP
  1 lo               loopback           carrier     unmanaged
  2 enp0s3           ether              routable    configured
  3 enp0s8           ether              routable    configuring
$ sudo  pacman  -Syu

Installing VirtualBox Guest Additions

This is required if you want to auto-resize the guest display, mount shared folders using vboxsf or would like to share your VM’s clipboard with your host machine or vice-versa.

$ sudo  pacman  -S  virtualbox-guest-modules  virtualbox-guest-utils  
$ sudo  modprobe  -a  vboxguest  vboxsf  vboxvideo  

Installing LXQT

This step is only required if you want to install LXQT (which I prefer over XFCE). In case you would like to use XFCE, you can move on to the next section which lists the steps for installing XFCE.

$ pacman  -S  lxqt  openbox  obconf  sddm  
$ sudo  pacman  -S  xorg-server-utils  xorg-xinit  gnome-themes-standard  xfce4-terminal  lxterminal
$ su
$ sddm  --example-config  >  /etc/sddm.conf  
$ systemctl  enable  sddm.service  

Installing XFCE

Since Arch Linux’s preferred desktop manager is XFCE, it is really easy to install. Just install the XFCE program group, XORG and LXDM (Arch Linux’s recommend display manager for XFCE). Afterwards, enable the display manager service and then you can start XFCE. Next time you restart your VM, you should see a graphical login manager and once you log in, XFCE should start automatically.

$ sudo  pacman  -S  xfce4  xorg  lxdm  
$ sudo  systemctl  enable  lxdm.service  
$ startxfce
comments powered by Disqus

Older · View Archive (8)

First Post - Blog & Site Finally Ready

I finally have a shiny new Jekyll based Github blog.

Newer

Download Arch Linux VMs

I have uploaded 3 Arch Linux Virtual Machines to Dropbox. One without any desktop environment (command line only), another with LXQT and a third with XFCE. You will need to create a new user since these VMs only contain the default “root” account with password “root”. If you’d rather install Arch Linux on VirtualBox from scratch, go here.