Running ArchLinux ARM in UTM on a M1 MacBook Air

ArchLinux is a text-based operating system that does not come with a graphical interface, and all tasks are performed by running commands in the Command Line Interface (CLI).

Setup

The setting up of UTM and running virtual machines on it is rather simple. Just follow the steps shown below and you’ll be playing around soon enough.

  1. Download UTM

  2. Click on Open in UTM - this automatically redirects you to your newly installed UTM app, where UTM will download the pre-built ArchLinux VM for you.

  3. (Optional) You can run the VM as is, but feel free to tweak with the settings if you want to.

Install Dependencies

sudo

1
2
3
4
5
6
su -

pacman -Syu

pacman -S sudo

su is short for “substitute user”, and it is used to switch to another user account in Unix-based operating systems. When you use su without any options, it will switch to the root user account by default.

The - option used with su is used to simulate a full login for the new user, and it is not specific to the root user. When you use su - followed by a username, it will switch to that user’s account with a login shell.

So, to summarize:

  • su is used to switch to another user account.

  • su without any options will switch to the root user account by default.

  • su - followed by a username will switch to that user’s account with a login shell, simulating a full login for that user.


pacman

pacman is the package manager for Arch Linux, a lightweight and flexible Linux distribution.

With pacman, users can easily install, remove, and update software packages on their Arch Linux system. It uses a binary package format, which means that packages are precompiled and ready to install, making the process faster and more efficient than compiling from source.

Some common pacman options include:

pacman -Syu: -S stands for “sync”, -y and -u are options that tell pacman to refresh the package databases and upgrade all packages, respectively. -Syu, as a whole, updates the system and all installed packages to the latest version.

pacman -S <package>: -S is a shorthand for --sync. This command installs a package. When --needed option is specified alongside the pacman -S command, only packages that are not already installed on your system get installed.

pacman -R <package>: -R stands for “remove”. This command removes a package.

pacman -Ss <searchterm>: -Ss stands for “synchronize/search”. This command searches for packages containing the specified search term.

pacman -Q: -Q stands for “query”. This command lists all installed packages on the system.

Use the following commands with caution!

pacman -Sc: Removes all the packages from the cache which are not currently installed on the system. It will only remove packages that are not needed anymore and will not affect any installed packages. This command can be useful to free up disk space on the system.

pacman -Scc: Removes all the packages from the cache, including those that are currently installed on the system. It will remove all the package files from the cache, along with their associated databases. This command can be useful if you want to completely clean the package cache and start fresh.

pacman -Syy: Forces a refresh of all package databases, even if they are already up to date. This ensures that you have the latest package database information available, which can be useful in situations where the package databases may have become out of sync or corrupted.


Once the installation is complete, we need to configure sudo to allow users to execute commands with administrative privileges. To do this, you need to add the user to the wheel group. Run the following command to add the user to the wheel group:

1
usermod -aG wheel <username>

This command is used to add a user to the wheel group, which will give them the ability to perform administrative tasks on the system using the sudo command.

usermod: This is a command-line utility in Unix-based operating systems that is used to modify user account properties. The usermod command allows you to add or remove a user from a group, change a user’s home directory, and modify other user account settings.

wheel: This is a special group in Unix-based operating systems that is used to control access to administrative tasks. Users who are members of the wheel group are allowed to use the sudo command to execute commands with root privileges.

-aG: These two options used alongside usermod are used to add a user to a group. Specifically, -a stands for “append”, which means that the user is added to the group without removing them from any other groups they may already be a member of. -G stands for “group”, and is followed by the name of the group to add the user to.


1
visudo -f /etc/sudoers

visudo: This is a command used in Unix-based operating systems to edit the sudoers file, which controls user access to administrative commands.

-f: This option is used to specify the file to edit.

visudo uses the system’s default editor to open and edit the sudoers file, which is often vi.

If vi is not your thing, you can always specify which editor to use by pass EDITOR=<editor-name> in front of visudo. You can change the default editor once and for all by change these two environment variables: VISUAL and EDITOR.

1
export EDITOR=nano

Note
The main difference between the two is that VISUAL is used for visual editors, such as Sublime Text, Atom, or Visual Studio Code, while EDITOR is used for non-visual editors, such as nano, vim, or emacs.

Let’s add the finishing touch and uncomment the following line in the sudoers file:

1
%wheel ALL=(ALL:ALL) ALL

SPICE guest tools

SPICE stands for Simple Protocol for Independent Computing Environments. It is a remote computing solution that allows users to access the desktop of a virtual machine or remote system from a client device. SPICE provides a high-performance, low-latency connection that supports a wide range of features, including audio, video, and USB redirection. It is commonly used in virtualization environments, such as those provided by QEMU and KVM, to provide remote access to virtual machines.

However, we’re using it for clipboard sharing. With SPICE guest tools installed, the clipboard will be synced between the guest and the host.

Install the spice-vdagent package by running the following command:

1
sudo pacman -S spice-vdagent

Once the installation is complete, start the spice-vdagent service by running the following command:

1
sudo systemctl start spice-vdagentd.service

You can also enable the service to start automatically at boot time by running the following command:

1
sudo systemctl enable spice-vdagentd.service

However, I wasn’t able to enable it on first try.

The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled or disabled using systemctl.

Possible reasons for having this kind of units are:

* A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
* A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
* A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
* In case of template units, the unit is meant to be enabled with some
  instance name specified.

Here are some potential reasons why this error might be occurring and how we can address them:

The unit file might be missing the [Install] section. Check the spice-vdagentd.service file located in /usr/lib/systemd/system to see if it contains an [Install] section with the appropriate WantedBy or RequiredBy settings. If the section is missing or incomplete, you can add it manually. For example, to enable the service at boot time, you can add the line WantedBy=multi-user.target to the [Install] section.

The unit file might be a template unit. Template units are designed to be instantiated with specific instance names and cannot be enabled or disabled directly. Check the spice-vdagentd.service file to see if it contains the DefaultInstance setting in the [Install] section. If it does, you will need to specify an instance name when enabling the service using the systemctl enable command. For example, if the DefaultInstance setting is my-instance, you would run systemctl enable spice-vdagentd@my-instance.service.

The unit file might be symlinked from another unit’s .wants/ or .requires/ directory. Check the contents of these directories located in /etc/systemd/system to see if there are any symlinks pointing to spice-vdagentd.service. If there are, you do not need to enable the service separately as it will be started automatically when the dependent unit is started.

It’s the first fix for me. My [Install] section had only one line “Also=spice-vdagentd.socket“, so I added a second.

wget

Install the wget command-line tool:

1
2
3
4
5
sudo pacman -Syy

# Update package database

sudo pacman -S wget

Note: You may need to refresh your keychains first!

git

Install the git package by running the following command:

1
sudo pacman -S git

yay

The reason why we’re not installing apt is because apt is a package manager used in Debian-based Linux distributions like Ubuntu, and it is not available in Arch Linux. Instead, Arch Linux uses its own package manager called pacman, the one we just talked about.

If you are familiar with apt and want to use a similar package manager in Arch Linux, you can use yay, which is a popular AUR (Arch User Repository) helper that provides a pacman-like interface with added features.

1
sudo pacman -S base-devel

Install yay by running the following command:

1
2
3
4
5
6
git clone https://aur.archlinux.org/yay.git

cd yay

makepkg -si

makepkg -si is a command used in Arch Linux to build and install a package from source code.

makepkg: This is a tool that automates the process of building packages from source code in Arch Linux. It creates a package file that can be installed using the package manager.

-s: A flag that tells makepkg to install any dependencies needed to build the package.

-i: A flag that tells makepkg to install the package after it has been built.

neovim

1
sudo pacman -S --needed neovim

Create a non-root user

Before we move on to the next step, we have to create an alternative user apart from our current root, otherwise makepkg -si won’t work.

It’s fairly simple.

To create a non-root user account on Arch Linux, we have to run these few steps:

Run the following command to create a new user account:

1
useradd -m -s /bin/bash <username>

Set a password for the new user account:

1
sudo passwd <username>

Add the new user to the wheel group to allow them to use sudo:

1
usermod -aG wheel <username>

At last, we simply log out of the root user account and log in to the new user account by entering the username and password we just created.


Once the installation is complete, you can use yay to search for and install packages from the AUR. For example, to install the firefox package from the AUR, you can run the following command:

1
yay -S firefox

Or if you want to uninstall, run the following command:

1
yay -Rns firefox

This command will remove Firefox and its dependencies (-R), including any configuration files (-n) and any packages that were installed as dependencies and are no longer required (-s).

Now, yay will automatically download and install the package and its dependencies.

Note
While yay provides a pacman-like interface, it is not a drop-in replacement for apt, and there may be some differences in the way packages are managed and installed.


Refresh keys

PGP keys are used to verify the authenticity of packages in the official Arch Linux repositories.

Update the keyring package by running the following command:

1
sudo pacman -Sy archlinux-keyring

Import the new keys by running the following command:

1
sudo pacman-key --populate archlinux

Refresh the keyring by running the following command:

1
2
3
sudo pacman-key --refresh-keys

# This command retrieves the latest keys from the keyserver and update your keyring accordingly.

Now your keychains should be up to date and you should be able to verify the authenticity of packages in the official Arch Linux repositories.

Poweroff

Once you had your fun, you’d probably want to poweroff. Here’s what you should do:

1
sudo poweroff

Or:

1
sudo shutdown -h now