Responsive image

Arch Linux: VM Installation


Arch Linux is a distribution of Linux favored by enthusiasts and users who want the most fine-grained control over every aspect of their system. Arch lets the user control almost everything, so it's also a great way to learn about Linux and the operation of computers in general. This website will guide you through installing Arch on a virtual machine. A virtual machine (VM) runs like a program on your computer—you'll still have access to all your other programs and data (in particular, this website!), but you will be able to run Arch Linux in a window as if it were it's own computer within your current operating system.

You'll find this guide easiest to follow if you have some previous experience with using a terminal on a Linux or OSX system. If you don't have that experience, some parts of the guide may be confusing, but you'll still get through with patience and perseverance.

Before you start following this guide, you'll need to download and install VirtualBox. VirtualBox is the software that will handle running the VM for you. It's available to run on Windows, OS X, and Linux. Download and install VirtualBox like you would for any other program on your computer.

Throughout this guide, there are offset blocks indicating commands to type or lines to enter in files.

# they look like this!

Note the # character at the beginning of the line. That's to show the start of the line, and it will match what you see on your terminal while installing Arch. You should not type this character when entering the commands.

Many of the commands are exactly the same for every installation. Some commands will include a piece of information particular to you or your installation, like a username you choose. When this information is included in a command, it will be italicized to tell you to replace it with the correct value for you.

# replace my_name

Given the above command, I would run replace anne.

Finally, some commands or tools require the enter key to be pressed at various points. When this is the case, presses of the enter key are indicated inside the output with the ↵ symbol.


Preparing VirtualBox


In this section, we will go over setting up a new VirtualBox VM for installing and using Arch Linux.

Prerequisites


Setting up a new Virtual Machine

  1. Open VirtualBox, and create a new virtual machine by clicking on the New button on the top left corner.
    This opens a wizard for setting up a new virtual machine.

  2. In the popup wizard, you will be asked to name your virtual machine, and describe its operating system.
    In the Name textbox, fill in a name for your virtual machine. I have chosen the name "Arch Linux" as an example.
    For Type, select Linux from the dropdown menu.
    For Version, select Arch Linux (32-bit) from the dropdown menu.
    Then, click Next to proceed.

  3. On the next page, you will be asked to select the memory size for your virtual machine.
    For Arch Linux, it is recommended to leave this page unchanged. VirtualBox will figure out the most optimal settings for your computer.
    Click Next to proceed.
  4. Then, you will be asked to create a virtual hard drive. This allows VirtualBox to store your Arch Linux settings somewhere in your computer.
    Select Create a virtual hard disk now, and click Next to proceed.
  5. A new dialog box for creating a virtual hard disk will pop up.
    You will be asked for the type of virtual hard disk to create, select VDI (VirtualBox Disk Image) .
    Then, click Next to proceed.
  6. You will then be prompted for the storage type for your virtual hard disk.
    For Arch Linux, it is recommended to choose Dynamically allocated.
    Click Next to proceed.
  7. You will then choose a file location for your virtual hard disk.
    It is recommended to leave this page unchanged. VirtualBox will figure out the most optimal settings for you.
    Click Create to finish setting up your virtual hard disk.
  8. The dialog box will then close, and you will be returned to the main screen.
    Take the time to verify that your virtual machine is successfully created, and that the Operating System description is Arch Linux (32-bit) as shown.

Loading the disk image

  1. With your newly created virtual machine selected:
    Click on Settings to open the settings dialog box.
    In the dialog box, click on the Storage icon to open the Storage menu as shown.
  2. By default, you should have a virtual optical drive available.
    Click on the optical drive selection under Controller::IDE as shown.
    Then, in the Attributes grouping, click on the disk icon.
    In the popup, select Choose Virtual Optical Disk File.
  3. A file dialog box will pop up. Select the Arch Linux disk image that you have downloaded.
    In my case, it is called arch-linux-2016.11.01-dual.iso.
    Click Open to confirm.
  4. You will then be brought back to the settings dialog box.
    Click OK to confirm and load your Arch Linux image.
    The Settings dialog box will then close, and you will be brought back to the main screen.

Starting your Arch Linux installation

  1. You can now run your virtual machine to start the installation.
    With your virtual machine selected, click on the Start button at the top to run your machine
  2. A new window will pop up, displaying your virtual machine running the Arch Linux installation process.
    You may now follow the Arch Linux installation steps to complete your installation.

Arch Linux Installation


Partitioning

Several partitions will be necessary on the VM's file system, to prepare for Arch installation. The boot partition will contain files necessary for the computer's startup process, allowing the computer to transfer control over to your operating system. The swap partition provides extra memory for the operating system, in the case that their is insufficient random access memory available. Finally, the root partition will contain your operating system and all of your files.

  1. We will create these partitions using the command line tool gdisk.

    # gdisk /dev/sda

    /dev/sda is Linux's name for your hard drive. This command should open the following prompt for gdisk

    Command (? for help):
  2. Create the boot partition:

    Command (? for help): n ↵
    Partition number (1-128, default 1): ↵
    First sector (start-end, default = start) or {+-}size{KMGTP}: ↵
    Last sector (afterstart-end, default = end) or {+-}size{KMGTP}: +512M ↵
    Current type is 'Microsoft basic data'
    Hex code or GUID (L to show codes, Enter = EF00): ↵
    Changed type of partition to 'EFI System'

    These commands create a new partition, starting at the beginning of the disk, of size 512 megabytes, of a EFI System filesystem (hex code EF00 in gdisk).

  3. Now create the swap partition:

    Command (? for help): n ↵
    Partition number (1-128, default 2): ↵
    First sector (afterboot-end, default = afterboot) or {+-}size{KMGTP}: ↵
    Last sector (afterafterboot-end, default = end) or {+-}size{KMGTP}: +2G ↵
    Current type is 'Microsoft basic data'
    Hex code or GUID (L to show codes, Enter = 8300): 8200 ↵
    Changed type of partition to 'Linux swap'

    These commands create a new partition, starting immediately after the boot partition, of size 2 gigabytes, of a Linux swap filesystem (hex code 8200 in gdisk).

  4. Finally, create the root partition:

    Command (? for help): n ↵
    Partition number (1-128, default 3): ↵
    First sector (afterswap-end, default = afterswap) or {+-}size{KMGTP}: ↵
    Last sector (afterafterswap-end, default = end) or {+-}size{KMGTP}: ↵
    Current type is 'Microsoft basic data'
    Hex code or GUID (L to show codes, Enter = 8300): ↵
    Changed type of partition to 'Linux filesystem'

    These commands create a new partition, starting immediately after the swap partition, filling the rest of the disk, of a Linux filesystem (hex code 8300 in gdisk).

  5. We now have to write these changes to the disk. gdisk has merely been drafting the changes, and has not actually written anything to the disk yet. To do so, enter the w command.

    Command (? for help): w ↵

    Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!

    Do you want to proceed? (Y/N): y ↵
    OK; writing new GUID partition table (GPT) to /dev/disk1.
    The operation has completed successfully.
  6. The last step is to properly format the boot partition for use as an EFI System Partition (ESP).

    # mkfs.fat -F32 /dev/sda1

Mounting

We now need to mount these three partitions to the correct directories.

# mount /dev/sda3 /mnt

Create the requisite directory for the boot partition, then mount it.

# mkdir /mnt/boot
# mount /dev/sda1 /mnt/boot

The swap partition will automatically be detected when creating the fstab


Installation

The pacstrap script will automatically install the base package group.

# pacstrap /mnt base

Settings

In this section, we will make some basic configurations to our Arch installation and make our system defaults more consistent with our daily usage.

  1. fstab will determine how your disk partitions from the previous step are mounted outside this installation process. Each time your computer starts, it needs to know how to properly mount the partitions so that you can access your files without hassle.

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

  2. chroot changes your apparent root directory. This readies your environment for the following instructions.

    # arch-chroot /mnt

  3. Next, you need to enter information about your timezone so that your system knows how to determine your local time. This command will display available timezones on your system:

    # timedatectl list-timezones
    The following two commands set the system clock. Use the Region and City listed above that correspond to your physical location.

    # ln -s /usr/share/zoneinfo/Region/City /etc/localtime
    # hwclock --systohc

  4. Setting locale information makes your system follow your preferred language formats (temperature, currency, grammar conventions, etc.). Fire up the nano editor (preinstalled in every system) and edit /etc/locale.gen with the command:

    # nano /etc/locale.gen
    And uncomment the line:

    # en_US.UTF-8 UTF-8
    By removing the leading # character. Save the file, and then exit nano. Then, apply the changes with the following command:

    # locale-gen
    Similarly, edit /etc/locale.conf with the nano editor to use the same language settings, by inserting

    LANG=en_US.UTF-8
    on the first line.

  5. A hostname is a unique identifier for your system. You will need to configure a hostname in order for other computers on your network to recognize and remember you. You have full freedom to determine what your hostname should be. We recommend picking something creative and easy to remember.

    To do this, you will need to first create the file /etc/hostname with the touch command:

    # touch /etc/hostname
    Then, edit this file with the nano editor, and fill in your chosen hostname. Save and exit from nano.
    Next, edit the /etc/hosts with the nano editor and enter the following line:

    127.0.1.1 chosenhostname.localdomain chosenhostname
    where you replace chosenhostname with your previously chosen hostname.

  6. Since your Arch installation is running in a virtual machine, your networking is already properly configured. However, you will still need to set up the DHCP service, so that network discovery is enabled every time you boot up Arch. To do this, run the following command:

    # systemctl enable dhcpd@eth0.service

  7. Your new system has a user called root that has full privileges to everything on your system. Hence, it is important to set up a password for root so that other remote users cannot maliciously obtain root access and modify your computer. To do this, run

    # passwd
    and follow the prompts as indicated.
    Note that no characters will show up as you type the password. This is an intentional security feature. The characters you type are being recorded, but not displayed, so that anyone lurking behind you will not be able to peek at your entered password.

  8. Since root has full access to everything on your system, it is not a good idea to log in as root for daily tasks, as you may damage your system by accident due to typos and other mistakes. Hence, it is a good idea to create a more restricted account for yourself.

    To do this:
    First pick a username you like.
    Then, add the username to the system with:

    # useradd -m -G wheel username
    Now, use the passwd command to set the password for your new user:
    # passwd username
    and follow the prompt instructions given.


Boot Loader

Before we leave the installation environment, we need to add files so our computer can boot to the operating system. To do this, we will use the grub bootloader with the ESP we created earlier.

  1. First, install the grub and efibootmgr packages, then run the grub-install.

    # pacman -S grub efibootmgr
    # grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub

  2. Finally, create the config file for the bootloader.

    # grub-mkconfig -o /boot/grub/grub.cfg
  3. At this point you can reboot and continue the process from the operation system itself.

    # exit

    On reboot, log in as root, with the root password that was set previously.


X11


The X11 window manager allows creation of basic graphical windows by programs. It is a prerequisite for any graphical desktop environment in most Linux distros.

Install the xorg-server package as well as some utilities from the xorg-server-utils package.

# pacman -S xorg-server xorg-xinit xorg-server-utils mesa xf86-input-synaptics

Gnome


Installation

Gnome provides a full desktop environment so you can quickly get started using Arch Linux easily.

Install the gnome and gnome-extra packages to enable the full Gnome experience.

# pacman -S gnome gnome-extra

Optional

To customize Gnome, you need to install Gnome Tweak Tool.

# sudo pacman -S gnome-tweak-tool

Enabling Gnome Display Manager

You need to enable the Gnome Display Manager (GDM), which allows you to boot directly into Gnome.

# systemctl enable gdm.services
# systemctl start gdm.services
GNOME Desktop
Sample Gnome Desktop

Conclusion


Further Reading

By now, your new Arch system should set up with all the basic features you need. For further reading, questions, and troubleshooting issues, these resources will likely come in handy:

  • Arch Wiki has comprehensive guides to troubleshooting for hardware and software issues from users with years of experience dealing with them.
  • Arch Forums is a good place to ask for help and seek out advice. It is a friendly community that welcomes users and developers with any level of experience with Arch. If there is an issue that you encountered during installation, it is likely that someone already found a solution to it, and posted somewhere in the forums.

Credits

Guide by Dhruv Khurana, Anne Kohlbrenner, Clifford Ressel, and Haoxuan Yue. Formatting and design completed with Bootstrap 3.0.