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 Start from Scratch.
  3. On the Information tab, supply an appropriate name and select Operating System from the Style drop-down box.
  4. On the System tab, select ARM64 (aarch64) from the Architecture drop-down box and specify the amount of memory you’d like to give your VM in the Memory dialog box. For Linux with a graphical desktop (e.g. Fedora Workstation), specify 4096 to give your VM 4GB (4096MB) of memory. For a Linux server without a graphical desktop (e.g. Ubuntu Server), specify 1024 to give your VM 1GB (1024MB) of memory.
  5. On the Drives tab, click New Drive, ensure that VirtIO is displayed in the Interface drop-down box, type 127 in the Size dialog box (for a dynamically expanding virtual hard drive that uses up to 127GB of storage) and click Create. Click New Drive again, select the Removeable checkbox to create a USB drive that we’ll later attach to the Linux DVD ISO you downloaded earlier and click Create. At this point, your screen should look like the following:

UTM drives

  1. On the Network tab, select Bridged (Advanced) from the Network Mode drop-down box to ensure that your VM appears as a separate system on your network alongside macOS and then click Save.
  2. In the UTM window for your VM, select Browse from the CD/DVD drop-down box, select the Linux DVD ISO from your Downloads folder to insert it into the removable drive and then click the large Play icon to start your VM. 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.
  3. Install your Linux distribution as you normally would. The 127GB virtual disk will 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.