Installing a fast Linux server on an M1-based Mac

+

One of the biggest worries that IT users have regarding Apple’s new ARM-based M1 platform is the ability to run virtual machines (VMs) of other operating systems using hypervisor software. And while it’s possible to run virtual machines of both Windows and Linux operating systems made for the Intel platform on the M1, the performance cost of translating Intel instructions to ARM is high (even with the optimizations Apple has within their M1 CPU). Luckily, the most common VM that an IT systems administrator or developer will install is Linux, and ARM versions of Linux have been mainstream for well over a decade now.

Instead of buying an expensive Parallels or VMWare Fusion license to run a VM of Linux (slowly) on the M1, you can use the free UTM app. UTM leverages the native hypervisor framework in macOS alongside the open source Qemu framework that is used for virtualizing operating systems on Linux. If you run an Intel version of Linux in UTM, Qemu will translate the Intel instructions to run on the M1 and there will be a noticable performance cost. However, if you run an ARM version of Linux in UTM, Qemu will run it directly on the M1 at near native speed. Better yet, the VirtIO storage bus used by Qemu and the Linux kernel can access the underlying storage in the Mac at near native speed. In short, UTM allows you to run ARM-based Linux VMs very very fast on the M1 platform for free.

To get started, you should first download an ARM-based Linux distribution. If you need a graphical desktop, I recommend the latest version of Fedora Workstation (shown below in UTM). If you just want to host a server (no graphical desktop), I recommend Ubuntu Server as it will likely be the same one hosting your services and Web apps in the cloud. You can visit https://getfedora.org/en/workstation/download/ to download the DVD ISO image for the latest Fedora Workstation (aarch64) or https://ubuntu.com/download/server to download the DVD ISO image for the latest Ubuntu Server (ARM).

ARM Powered logo

Next, you can perform the following steps to create a Linux server VM using UTM:

  1. Download the free version of UTM from https://mac.getutm.app and copy it to your Applications folder.
  2. Open UTM and click + to create a new VM and click Virtualize, and Linux.
  3. On the Linux page, deselect Use Apple Virtualization (this ensures you are also using Qemu - not just the native hypervisor framework in macOS). Click Browse, select the DVD ISO image you downloaded and click Next.
  4. On the Hardware page, specify the amount of memory you’d like to give your VM and click Next. For Linux with a graphical desktop (e.g. Fedora Workstation), specify 4096 MB to give your VM 4GB of memory. For a Linux server without a graphical desktop (e.g. Ubuntu Server), specify 1024 MB to give your VM 1GB of memory.
  5. On the Storage page, specify the size of the dynamically-expanding virtual hard disk file that will be created and click Next. The default value is 64 GB, but you can increase this value to accomodate the software you plan on installing on your Linux VM.
  6. On the Shared Directory page, optionally click Browse and select a folder on your system that you’d like to be made available to your VM for easy file transfer. Click Next when finished.
  7. On Summary page, specify a name for your VM and click Save.
  8. Click the Play icon next to your new VM to boot it from the virtual DVD ISO image. Some distributions validate the checksum of the DVD first. If you see a black window with the UTM logo in it for a few minutes, be patient - your Linux installer will start after the checksum is verified.
  9. Install your Linux distribution as you normally would. The virtual hard disk file show up as /dev/vda instead of /dev/sda because we’re using the very fast VirtIO interface instead of emulating a SCSI, SATA or NVMe interface.

During the Linux installation, you’ll be prompted to create a regular user account (e.g. jason). While this first user account is automatically added to the wheel or sudo group on your Linux distribution to allow it to run administrative commands as the root user, you should set the root user password following installation using the sudo passwd root command.

If you are a developer that needs a local Linux server for testing your Web apps, you’ll need to install additional software packages. For example, to install the Apache Web server, Very Secure FTP daemon (for uploading files), MySQL/MariaDB database server, and PHP (including the most useful plugins) on an Ubuntu Server, you could switch to the root user (su -) and run the following commands:

apt update
apt upgrade
apt install apache2 vsftpd mysql-server 
mysql_secure_installation    #Configure your MySQL settings and password
apt install php libapache2-mod-php php-mysql phpmyadmin php-mbstring php-zip php-gd php-json php-curl
vi /etc/apache2/mods-enabled/dir.conf    #Add index.php to the DirectoryIndex line
systemctl restart apache2

While UTM can run ARM Linux at near native speed on macOS, you’ll soon be able to install Linux natively on M1 hardware, eliminating the need for macOS entirely. Most of this development is already done by those working on the Asahi Linux project. Visit https://asahilinux.org/about/ to learn more.