Ubuntu server on macOS
QEMU for MacOS
With QEMU it is possible to run eg. Linux as a virtual machine on your Mac. A few steps are needed to startup your first virtual machine. Linux comes in many flavors, so-called distributions and below example takes Ubuntu server to create a VM. The most obvious choice might be to take the Ubuntu live server ISO images, and run it to create and setup the VM. But instead below describes how we configure an almost up-and-running image and use cloud-init to insert the necessary details.
Install QEMU for MacOS
Install the QEMU binaries as described on the macOS page. We took the method of Homebrew so running brew install qemu
did the trick. While we're at it, also make sure that brew install cdrtools
has been executed. Next step is to get an Ubuntu server image and prepare a VM environment.
Download the cloud image
Navigate to the Ubuntu cloud images page and download the appropriate image. In this example we use a Macbook Pro M1 that runs MacOS Sonoma and hence we download the image that is built wrt. the ARM-64 architecture. Second, we'll go for the latest Ubuntu server LTS (22.04 aka Jammy Jellyfish) which can be pulled from this link under directory 'current'.
Prepare for a VM
Create a separate directory for a VM and prepare the cloud-init files, for example:
Create the Cloud Init ISO image
Open the meta-data file and enter the following information. Take any instance-id and local-hostname but note that they differ across VM's
Open the user-data file and enter the following information. This will enable the default user ubuntu
with a password and ability to logon directly from the terminal.
Finally, create the ISO image by executing following command:
The resulting cidata.iso
will be used when starting up the VM and initializes the cloud image
Create startup script
For convenience, create a small shell script to startup the VM. Edit the file startup.sh
and add the following command(s):
This script will startup a VM in a separate window and initializes it with the cloud init data from the ISO image.