Tricks Of The Trades

Arch Linux VM Base Installation

Pinterest LinkedIn Tumblr

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.

  1. $ localectl list-keymaps

To set it use loadkeys plus your keyboard layout choice:

  1. $ loadkeys uk

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

Use ping to check connectivity.

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

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.

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

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:

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

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

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

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

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

Or use parted instead to see the partition table.

  1. $ parted /dev/sda print

3 – Filesystems

/boot

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

  1. $ mkfs.ext2 /dev/sda1

/

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

  1. $ mkfs.btrfs /dev/sda2

4 – Mounting

/mnt/

This will mount the main partition:

  1. $ mount /dev/sda2 /mnt/

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

  1. $ mkdir /mnt/boot

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

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

5 – Mirrors & System Packages

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

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

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

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

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.”

  1. $ pacman -Syy

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.

  1. $ pacstrap /mnt/ base base-devel

Copy the mirrorlist(s) from earlier over also.

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

6 – fstab

Here generate fstab like so in this directory:

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

7 – chroot

chroot into a bash shell in /mnt/ .

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

8 – hostname

Set the hostname to today’s date, or whatever you prefer.

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

9 – localtime

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

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

10 – locale

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

Using vi do this:

  1. $ vi /etc/locale.gen

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

  1. en_GB.UTF-8 UTF-8

Then generate the locales.

  1. $ locale-gen

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:

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

Lastly export the chosen locale.

  1. $ export LANG=en_GB.UTF-8

11 – passwd

Change the root user’s password for the VM.

  1. $ passwd

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:

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

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.

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

13 – unmount & reboot

Exit from the chrooted shell environment:

  1. $ exit

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

  1. $ umount -R /mnt/

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

  1. $ reboot

“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