Arch Linux is a popular Linux distribution that can be installed on a virtual machine. This guide will show you how to install Arch Linux in a virtual machine.
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.
1 – Initial Shell Prompt2 – Partitioning3 – Filesystems4 – Mounting5 – Mirrors & System Packages6 – fstab7 – chroot8 – hostname9 – localtime10 – locale11 – passwd12 – GRUB Bootloader13 – unmount & reboot
The shell in use is Zsh.
Show the possible keyboard layouts available with this command.
[alert-announce]
$ localectl list-keymaps
[/alert-announce]
To set it use loadkeys plus your keyboard layout choice:
[alert-announce]
$ 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]
$ 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]
$ 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]
$ 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]
$ parted -s /dev/sda mkpart primary 0% 100m $ 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]
$ lsblk | grep -v “rom|loop|airoot”
[/alert-announce]
Or use parted instead to see the partition table.
[alert-announce]
$ 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]
$ mkfs. ext2 /dev/sda1
[/alert-announce]
/
The root filesystem is formatted on the other main partition now via:
[alert-announce]
$ mkfs. btrfs /dev/sda2
[/alert-announce]
4 – Mounting
/mnt/
This will mount the main partition:
[alert-announce]
$ mount /dev/sda2 /mnt/
[/alert-announce]
Make a boot directory in /mnt/ which is now mapped/mounted to /dev/sda2 .
[alert-announce]
$ mkdir /mnt/boot
[/alert-announce]
Mount the boot partition to the newly created boot sub-directory in the main root partition.
[alert-announce]
$ 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]
$ 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]
$ rankmirrors -n 6 /etc/pacman. d/mirrorlist. orig >/etc/pacman. d/mirrorlist
[/alert-announce]
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]
$ 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]
$ pacstrap /mnt/ base base-devel
[/alert-announce]
Copy the mirrorlist(s) from earlier over also.
[alert-announce]
$ cp /etc/pacman. d/mirrorlist* /mnt/etc/pacman. d
[/alert-announce]
6 – fstab
Here generate fstab like so in this directory:
[alert-announce]
$ genfstab -p /mnt/ »/mnt/etc/fstab
[/alert-announce]
7 – chroot
chroot into a bash shell in /mnt/ .
[alert-announce]
$ arch-chroot /mnt/ /bin/bash
[/alert-announce]
8 – hostname
Set the hostname to today’s date, or whatever you prefer. [alert-announce]
$ 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]
$ 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]
$ vi /etc/locale. gen
[/alert-announce]
Uncomment the relevant language you wish to use (UTF-8 support recommended).
[alert-announce]
en_GB. UTF-8 UTF-8
[/alert-announce]
Then generate the locales.
[alert-announce]
$ 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]
$ echo LANG=en_GB. UTF-8 > /etc/locale. conf
[/alert-announce]
Lastly export the chosen locale.
[alert-announce]
$ export LANG=en_GB. UTF-8
[/alert-announce]
11 – passwd
Change the root user’s password for the VM.
[alert-announce]
$ 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]
$ pacman -S grub $ grub-install –target=i386-pc –recheck /dev/sda
[/alert-announce]
Next automatically generate the main grub config file.
[alert-announce]
$ grub-mkconfig -o /boot/grub/grub. cfg
[/alert-announce]
13 – unmount & reboot
Exit from the chrooted shell environment:
[alert-announce]
$ 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]
$ 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]
$ 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.”