Tricks Of The Trades

Arch Linux VM Base Installation

I set up the base system components of Arch on a VM recently, here are the notes on one of the many ways of doing this.

So bear in mind that these notes in places are relative to me.

Download Here: Arch Linux Source Download Page

1 – Initial Shell Prompt

After being presented with a shell prompt where you are automatically logged in as root. Begin by setting the keyboard language to your relevant country.

The shell in use is Zsh.

Show the possible keyboard layouts available with this command.

[alert-announce]

  1. $ localectl list-keymaps

[/alert-announce]

To set it use loadkeys plus your keyboard layout choice:

[alert-announce]

  1. $ loadkeys uk

[/alert-announce]

The dhcpcd network daemon starts automatically during boot, and it will attempt to start a wired connection by default.

Use ping to check connectivity.

[alert-announce]

  1. $ ping -c 5 www.google.co.uk

[/alert-announce]

In a Virtual Machine that shares the host’s network connection, the ping should be successful as long as the host itself is connected and working, when using a bridged hardware network setting. If not this then… improvise.

2 – Partitioning

This will list all devices connected to your system along with their partition schemes, including those used to host and boot live Arch installation media (e.g. a USB drive). Not all devices listed will, therefore, be viable or appropriate mediums for installation. To filter out inappropriate results, use this grep.

[alert-announce]

  1. $ lsblk | grep -v “rom\|loop\|airoot”

[/alert-announce]

Devices (e.g. hard drives) will be listed as sdx, where x is a lower-case letter starting from a for the first device (sda), b for the second device (sdb), and so on. For the VM only one device is available (sda) which is the allocated host hard drive space.

Open the device (host HDD) that the partition table is to be created with and create a new MBR/msdos partition table for BIOS systems. All done using the following command:

[alert-announce]

  1. $ parted -s /dev/sda mktable msdos

[/alert-announce]

Here I’m making two partitions in total for the VM. The first with line 1 and second with line 2.

[alert-announce]

  1. $ parted -s /dev/sda mkpart primary 0% 100m
  2. $ parted -s /dev/sda mkpart primary 100m 100%

[/alert-announce]

You can run the earlier grep pattern again to see the newly created partitions.

[alert-announce]

  1. $ lsblk | grep -v “rom\|loop\|airoot”

[/alert-announce]

Or use parted instead to see the partition table.

[alert-announce]

  1. $ parted /dev/sda print

[/alert-announce]

3 – Filesystems

/boot

The boot filesystem is formatted and placed on the first partition created (smaller of the two) with:

[alert-announce]

  1. $ mkfs.ext2 /dev/sda1

[/alert-announce]

/

The root filesystem is formatted on the other main partition now via:

[alert-announce]

  1. $ mkfs.btrfs /dev/sda2

[/alert-announce]

4 – Mounting

/mnt/

This will mount the main partition:

[alert-announce]

  1. $ mount /dev/sda2 /mnt/

[/alert-announce]

Make a boot directory in /mnt/ which is now mapped/mounted to /dev/sda2 .

[alert-announce]

  1. $ mkdir /mnt/boot

[/alert-announce]

Mount the boot partition to the newly created boot sub-directory in the main root partition.

[alert-announce]

  1. $ mount /dev/sda1 /mnt/boot

[/alert-announce]

5 – Mirrors & System Packages

Begin by appending the system’s mirrorlist file name with .orig and the mv command.

[alert-announce]

  1. $ mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.orig

[/alert-announce]

Then run rankmirrors on the aforementioned file with the -n parameter to find and redirect the fastest 6 mirrors into a new mirrorlist file.

[alert-announce]

  1. $ rankmirrors -n 6 /etc/pacman.d/mirrorlist.orig >/etc/pacman.d/mirrorlist

[/alert-announce]

Note: This takes several minutes to process and complete, have faith and wait…

After this use pacman to update and sync the systems package listings.

“Whenever you change your mirrorlist, refresh all package lists with pacman, to ensure that the package lists are updated consistently.”

[alert-announce]

  1. $ pacman -Syy

[/alert-announce]

Next install all the system’s base packages. Time to download packages will vary on your internet connection and the respective mirrors.

Adding a -i parameter to this command enables a prompt for every package to be installed during the process, if preferred.

[alert-announce]

  1. $ pacstrap /mnt/ base base-devel

[/alert-announce]

Copy the mirrorlist(s) from earlier over also.

[alert-announce]

  1. $ cp /etc/pacman.d/mirrorlist* /mnt/etc/pacman.d

[/alert-announce]

6 – fstab

Here generate fstab like so in this directory:

[alert-announce]

  1. $ genfstab -p /mnt/ >>/mnt/etc/fstab

[/alert-announce]

7 – chroot

chroot into a bash shell in /mnt/ .

[alert-announce]

  1. $ arch-chroot /mnt/ /bin/bash

[/alert-announce]

8 – hostname

Set the hostname to today’s date, or whatever you prefer.
[alert-announce]

  1. $ echo “archlinux-vm-$(date +”%d-%m-%y”)” >/etc/hostname

[/alert-announce]

9 – localtime

Set the localtime to London’s current time (obviously change this in relation to your own timezone.)

[alert-announce]

  1. $ ln -s /usr/share/zoneinfo/Europe/London /etc/localtime

[/alert-announce]

10 – locale

Locales define which language the system uses and other regional considerations like currency denomination, numerology and character sets.

Using vi do this:

[alert-announce]

  1. $ vi /etc/locale.gen

[/alert-announce]

Uncomment the relevant language you wish to use (UTF-8 support recommended).

[alert-announce]

  1. en_GB.UTF-8 UTF-8

[/alert-announce]

Then generate the locales.

[alert-announce]

  1. $ locale-gen

[/alert-announce]

The /etc/locale.conf file does not exist by default. Create it, where LANG refers to the first uncommented entry in /etc/locale.gen from earlier.

See the next command for an example:

[alert-announce]

  1. $ echo LANG=en_GB.UTF-8 > /etc/locale.conf

[/alert-announce]

Lastly export the chosen locale.

[alert-announce]

  1. $ export LANG=en_GB.UTF-8

[/alert-announce]

11 – passwd

Change the root user’s password for the VM.

[alert-announce]

  1. $ passwd

[/alert-announce]

12 – GRUB Bootloader

Here installation with GRUB and MBR/msdos is demonstrated.

Install the grub package and then run grub-install to install the bootloader:

[alert-announce]

  1. $ pacman -S grub
  2. $ grub-install –target=i386-pc –recheck /dev/sda

[/alert-announce]

Warning: Change /dev/sda to reflect the drive you installed Arch on if needed. Do not append a partition number, and do not replace it with “sdax” either.

Next automatically generate the main grub config file.

[alert-announce]

  1. $ grub-mkconfig -o /boot/grub/grub.cfg

[/alert-announce]

13 – unmount & reboot

Exit from the chrooted shell environment:

[alert-announce]

  1. $ exit

[/alert-announce]

While partitions are unmounted automatically by systemd on shutdown, you may do so manually with the next command as a safety measure.

[alert-announce]

  1. $ umount -R /mnt/

[/alert-announce]

Finally if using a CD image you may have to remove it from your VM manager software, before rebooting.

[alert-announce]

  1. $ reboot

[/alert-announce]

“Your new Arch Linux base system is now a functional GNU/Linux environment ready to be built into whatever you wish or require.”

Write A Comment