I first learned about
QEMU three years ago when I wrote a guide on how to virtualize macOS on a Linux system. Today I will be showing the opposite, virtualizing Linux on macOS using the same tools. I was surprised that with so many software developers using MacBooks everyday, nobody has created a guide on how to use
QEMU with macOS.
According to Wikipedia, Oracle VM VirtualBox is a free and open-source hosted hypervisor for x86 virtualization. Now you can use Ubuntu on Mac OS, install whatever apps you want, and still.
QEMU better? First of all, it's free and open-source. Unlike Parallels Desktop and VMWare Fusion, you won't need to pay for expensive subscriptions or manage licenses. There does exist an open-source alternative (from Oracle!) called VirtualBox, which works pretty well. However, VirtualBox does not support macOS's Hypervisor.Framework, a virtualization API created to limit kernel modification. This means the installer will ask for admin access to install kernel extensions, a feature Apple is now phasing out for security reasons.
QEMU on the other hand has had support for Hypervisor.Framework since 2018. Just say no to kexts!
- Get a taste of macOS using QEMU/KVM virtual machines on your Ubuntu Linux installation. Virtual machines are very important in computing and software engineering. They primarily allow us to test and use different operating systems without the need for extra hardware.
- I can't figure out how to connect to the web server running on Ubuntu from a browser on my Mac. I've tried editting the nat.conf like this: # Use these with care - anyone can enter into your VM through these. # The format and example are as follows: # =:#8080 = 172.16.3.1 = 172.16.147.1:8080. But when I go to my browser and enter.
- There are two ways that we can run Ubuntu on the Mac. We can either setup a dual boot or we can run Ubuntu as a virtual machine. We will be using the virtual machine method in this tutorial. There are pros and cons to each method, however a virtual machine will be plenty adequate for most dual operating system requirements.
Furthermore, like many developers, I like to run VMs headless, i.e. without a desktop GUI, so that I can SSH into them. Running VMs in the background seems like a simple feature, but it requires a lot of complex configuration for both
VirtualBox and VMWare Fusion. And Parallels wants you buy the Pro Edition to gain access. Market segmentation at its finest.. With
libvirt, VMs start headless. Plus, when you shutdown macOS, it sends a shutdown signal to your VMs as well.
To be clear, this method doesn't support USB Passthrough, GPU Passthrough, or bridge networking. But if you just need to test, for example, node.js or nginx on a Linux VM, then this method is great.
Installing libvirt and QEMU
- First, install homebrew, which is a package manager for macOS.
brew install qemu gcc libvirt.
- Since macOS doesn't support QEMU security features, we need to disable them:
- Finally start the libvirt service, with
brew services start libvirt. It will start after boot as well.
Installing Ubuntu Server 20.04
There are two ways to access the virtual display of the VM, either using a VNC client or the virt-viewer program. I recommend RealVNC Viewer. The VNC client is responsive and quick to install, but if you have multiple VMs you need to manually manage the different ports. With virt-viewer, you get a popup with all the VMs currently running, but it is laggy and takes an eternity to install. virt-viewer can be installed through homebrew. The rest of this guide uses VNC.
vmsfolder in your home directory, and generate a disk image. Change
50gto the size of your prefered disk:
Download the Ubuntu Server 20.04 Install Image and my libvirt XML template and place the .iso and .xml files in the same folder.
Modify the following elements in the
ubuntu.xmlfile to match your your VM preferences and file paths. Save, then run
virsh define ubuntu.xmlfollowed by
virsh start ubuntu.
Start RealVNC Viewer and connect to
localhost. Click the
Ctrl+Alt+Delbutton to reboot the machine, and quickly press
Escto get into the boot menu. Evernote 10. Press the number that matches the Ubuntu Server image.
Install Ubuntu Server normally, making sure to enable the SSH server. Once it restarts you can connect to the VM from your terminal by running
ssh -p 2222 [email protected].
To send a shutdown signal to your VM, run
virsh shutdown ubuntu. To force shutdown, run
virsh destroy ubuntu.
To forward a port, e.g. port 443 from the VM to port 8443 locally, run the following:
ssh -p 2222 -L8443:localhost:443 [email protected]
Ubuntu Vmware Macos Unlocker
If you want to create multiple VMs, create an XML file for each machine with a unique UUID, VM name, and VNC port. Also, change the
hostfwd argument so that each VM exposes a different port for SSH, e.g.
2223 instead of
2222. After you have defined them all, you can get a list of the VMs that are currently running with
Macos Virtualbox Ubuntu
Macos Vm On Macos
Note: More discussion on Hacker News