Contents

Install Arch Linux in virtualbox

Pre-installation

Acquire an installation image

Arch is a “rolling release” distribution, download the .iso file from its offical site.

Create VM

Create a vm in virtualbox, make sure enable EFI in the motherboard. We will use use UEFI instead of the older BIOS spec to boot the VM.

uefi

Verify the boot mode

To verify the boot mode, list the efivars directory:

1
# ls /sys/firmware/efi/efivars

If the command shows the directory without error, then the system is booted in UEFI mode.

Partition the disks

We are going to use a simple partition scheme:

  • an EFI system partition (ESP)
  • one encrypted partition that holds our root filesystem
  • a small partition for swap space

List storage device

1
# fdisk -l

Start the actual partitioning process, run fdisk /dev/sda

  1. Create a GPT table by typing g (then hit enter).
  2. Create your ESP by typing n.
  3. Type t to change the type of the new partition (partition 1) to “EFI System”.
  4. Create your main root partition by typing n again. (This partition should already have the correct type, “Linux filesystem”)
  5. Create your swap partition by typing n and just take all the defaults.
  6. Type t to change the type of the swap partition (partition 3) to “Linux swap”
  7. Type p to show the current partition table. You should see an “EFI System” partition, a “Linux filesystem” partition, and a “Linux swap” partition.
  8. Type w to finally actually write the changes to disk.

Create filesystems

ESP

The ESP (EFI System Partition) has to be in a FAT format. Find ESP partition fdisk -l /dev/sda it should be sda1 mkfs.fat -F32 /dev/sda1 to create the FAT32 filesystem.

Root partition

Root partition should be /dev/sda2, we are going to encrypt it. Details refer Arch doc

1
2
3
cryptsetup open --type plain -d /dev/urandom /dev/sda2 to_be_wiped
dd if=/dev/zero of=/dev/mapper/to_be_wiped status=progress bs=1M
cryptsetup close to_be_wiped
1
cryptsetup -y -v luksFormat /dev/sda2

Open the encrypted partition

1
cryptsetup open /dev/sda2 cryptroot

Use lsblk to see the hierarchy of these partitions, create the actual filesystem

1
mkfs.ext4 /dev/mapper/cryptroot

Swap

1
2
mkswap /dev/sda3
swapon /dev/sda3

Mount the new filesystems

1
2
3
mount /dev/mapper/cryptroot /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot

Installation

For details check arch wiki

Install essential packages

1
pacstrap /mnt base linux linux-firmware

Configure the system

Fstab

Generate an fstab file (use -U or -L to define by UUID or labels, respectively):

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

Chroot

1
# arch-chroot /mnt

vim is not installed in the chroot by default. You can do pacman -S vim to install it

Time zone

1
# ln -sf /usr/share/zoneinfo/Region/City /etc/localtime

Run hwclock(8) to generate /etc/adjtime:

1
# hwclock --systohc

Localization

Edit /etc/locale.gen and uncomment en_US.UTF-8 UTF-8 and other needed locales. Generate the locales by running:

1
# locale-gen

Network configuration

Create the hostname file:

1
2
vim /etc/hostname
myhostname

Add matching entries to hosts(5):

1
2
3
4
vim /etc/hosts
127.0.0.1	localhost
::1		localhost
127.0.1.1	myhostname.localdomain	myhostname

initramfs

On Arch, there’s a system to generate initramfs, need to make sure add disk encryption support.

1
2
vim /etc/mkinitcpio.conf
HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems fsck)

Run mkinitcpio -p linux to generate the new initramfs based on the new config file.

Root password

1
passwd

Boot loader

Historically, GRUB has been the only reasonable choice of boot loader. with the advent of UEFI, there are lots of different good options, we will use systemd-boot.

install systemd-boot

1
bootctl --path=/boot install

Create a bootloader entry

1
2
3
4
5
6
vim /boot/loader/entries/arch.conf

title   Arch Linux
linux   /vmlinuz-linux
initrd  /initramfs-linux.img
options cryptdevice=UUID=b219d331-8ea6-4678-ae6b-f041ee146bd2:cryptroot root=/dev/mapper/cryptroot rw

Make sure replace 2b219d331-8ea6-4678-ae6b-f041ee146bd2 with the correct UUID for the encrypted /dev/sda2 partition.

1
ls -l /dev/disk/by-uuid

Enable DHCP and SSH

1
2
3
4
pacman -S dhcpcd
systemctl enable dhcpcd
pacman -S openssh
systemctl enable sshd

Type exit to exit the chroot and then type reboot

Config static IP (optional)

1
2
3
4
5
6
7
vim /etc/dhcpcd.conf
interface enp0s3
static ip_address=192.168.10.10/24
static routers=192.168.10.1
static domain_name_servers=8.8.8.8

systemctl restart dhcpcd

That’s all 🎉