Return to site

Qemu Ubuntu For Mac

broken image


QEMU is a fast, cross-platform open source machine emulator which can emulate a huge number of hardware architectures for you. QEMU, a generic open source machine emulator, it runs Cisco ASA, PIX and IPS. Then install macOS in that image using the '/usr/libexec/qemu-kvm' command in the original post. Ubuntu/arm64 can run inside the QEMU emulator. You can either do this fully emulated (e.g. On an x86 host) or, accelerated w/ KVM if you have an arm64 host. This page describes how to do both. Recent versions of Ubuntu (at least 14.04) have a qemu symlink that defaults to qemu-system-i386. That can be changed with sudo update-alternatives -config qemu. – Lekensteyn Apr 5 '14 at 11:14. For Mac developer, this meant a choice of VMWare or Parallels and now you can also use Linux with KVM / QEMU and Clover/OVMF. Here are the high level steps and instructions required to get macOS (OS X) up and running on Ubuntu with KVM / QEMU. Get Ubuntu running with virtualisation enabled Install KVM / QEMU software. Download latest build of QEMU for Mac (on top-right corner) Installation Installation - QEMU 1. Double-click on QEMU installer for Mac. Follow the instructions of QEMU installer. QEMU for Mac provides a graphical interface launcher for virtual machines. Create a new virtual machine configuration on QEMU launcher for Mac.

In this blog post we're going to create a Ubuntu 20.04 VM using QEMU on MacOS.

QEMU is a hardware emulator which can make use of different accelerators when running VMs. The most popular accelerator is KVM which is built into the Linux kernel and allows Linux hosts to run VMs with native performance.

Using QEMU on macOS used to be very slow as no accelerator was available. This changed 2 years ago when the project added support for the macOS native hypervisor with Hypervisor.framework (HVF) as an accelerator.

Before we begin with the setup I assume that the Ubuntu 20.04 Desktop ISO has been downloaded in the current working directory.

Qemu mac os 9

QEMU Installation

We can use Homebrew to install QEMU. The version we're using in this tutorial is 5.1.0:

It will pull in a few dependencies (the package depends on 14 other packages) and the installation can take a few minutes.

Create the disk image

Qemu ubuntu for mac high sierra

Once the installation is done, we can create the disk image that we're going to install Ubuntu on.

We're using the QCOW2 format to create a 20GB image. This can be resized later on if needed. The Ubuntu installation took around 5GB of space when I installed it.

Boot machine with Ubuntu ISO mounted

We can now boot up the machine with the Ubuntu ISO attached as a

In this step we boot up the machine with the Ubuntu ISO mounted in the CD drive:

The options are:

  • -machine: The emulated machine and the accelerator. q35 is the newest machine type and HVF is the macOS native hypervisor.
  • -cpu: The CPU architecture. The value host will use the HVF processor with all supported host features
  • -smp: Number of CPUs to use
  • -m: Amount of memory to use
  • -hda: Disk drive (the one we created earlier)
  • -cdrom: The ISO image to put into the CD drive
  • -vga: The graphic card to use. I found virtio (based on Virgil to have the best performance
  • -usb: Enable USB host controller
  • -device Adding a 'usb-tablet' as an input device. I'm running this on a laptop and without this setting the mouse did not work.
  • -display: To show the mouse cursor (disabled by default)

During testing I had problems with the Linux kernel as it would panic during the boot process. The issue was the -cpu host parameter. I fixed it by specifying the CPU architecture manually (see qemu-system-x86_64 -cpu help for a list of all available architectures).

My machine has an IvyBridge processor (Core i7):

And using -cpu IvyBridge would fail. However when using -cpu Nehalem (also an i7 CPU) everything worked well.

Now after the machine is booted up the Ubuntu installer will run. Follow the installation steps and don't restart the VM at the end of the installation, instead shut it down by stopping the qemu process with CTRL-C on the host.

Boot without ISO mounted

When running the VM we don't need the Ubuntu ISO mounted and can remove it by leaving out the -cdrom option:

Conclusion

In my experience QEMU is faster, more responsive and uses less CPU/RAM than VirtualBox. I didn't have to configure any display scaling for HiDPI screens as it worked out of the box. The only thing I'm missing are shared clipboards and drag-and-drop of files (which are available when installing the VirtualBox Guest Additions).

I first learned about libvirt and 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 libvirt and QEMU with macOS.

Why is libvirt and 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 Nfpa fire protection handbook 20th edition pdf. on the other hand has had support for Hypervisor.Framework since 2018. Just say no to kexts!

Qemu

QEMU Installation

We can use Homebrew to install QEMU. The version we're using in this tutorial is 5.1.0:

It will pull in a few dependencies (the package depends on 14 other packages) and the installation can take a few minutes.

Create the disk image

Once the installation is done, we can create the disk image that we're going to install Ubuntu on.

We're using the QCOW2 format to create a 20GB image. This can be resized later on if needed. The Ubuntu installation took around 5GB of space when I installed it.

Boot machine with Ubuntu ISO mounted

We can now boot up the machine with the Ubuntu ISO attached as a

In this step we boot up the machine with the Ubuntu ISO mounted in the CD drive:

The options are:

  • -machine: The emulated machine and the accelerator. q35 is the newest machine type and HVF is the macOS native hypervisor.
  • -cpu: The CPU architecture. The value host will use the HVF processor with all supported host features
  • -smp: Number of CPUs to use
  • -m: Amount of memory to use
  • -hda: Disk drive (the one we created earlier)
  • -cdrom: The ISO image to put into the CD drive
  • -vga: The graphic card to use. I found virtio (based on Virgil to have the best performance
  • -usb: Enable USB host controller
  • -device Adding a 'usb-tablet' as an input device. I'm running this on a laptop and without this setting the mouse did not work.
  • -display: To show the mouse cursor (disabled by default)

During testing I had problems with the Linux kernel as it would panic during the boot process. The issue was the -cpu host parameter. I fixed it by specifying the CPU architecture manually (see qemu-system-x86_64 -cpu help for a list of all available architectures).

My machine has an IvyBridge processor (Core i7):

And using -cpu IvyBridge would fail. However when using -cpu Nehalem (also an i7 CPU) everything worked well.

Now after the machine is booted up the Ubuntu installer will run. Follow the installation steps and don't restart the VM at the end of the installation, instead shut it down by stopping the qemu process with CTRL-C on the host.

Boot without ISO mounted

When running the VM we don't need the Ubuntu ISO mounted and can remove it by leaving out the -cdrom option:

Conclusion

In my experience QEMU is faster, more responsive and uses less CPU/RAM than VirtualBox. I didn't have to configure any display scaling for HiDPI screens as it worked out of the box. The only thing I'm missing are shared clipboards and drag-and-drop of files (which are available when installing the VirtualBox Guest Additions).

I first learned about libvirt and 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 libvirt and QEMU with macOS.

Why is libvirt and 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 Nfpa fire protection handbook 20th edition pdf. on the other hand has had support for Hypervisor.Framework since 2018. Just say no to kexts!

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

  1. First, install homebrew, which is a package manager for macOS.
  2. Run brew install qemu gcc libvirt.
  3. Since macOS doesn't support QEMU security features, we need to disable them:
  4. 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.

  1. Create a vms folder in your home directory, and generate a disk image. Change 50g to the size of your prefered disk:

  2. Download the Ubuntu Server 20.04 Install Image and my libvirt XML template and place the .iso and .xml files in the same folder.

  3. Modify the following elements in the ubuntu.xml file to match your your VM preferences and file paths. Save, then run virsh define ubuntu.xml followed by virsh start ubuntu.

  4. Start RealVNC Viewer and connect to localhost. Click the Ctrl+Alt+Del button to reboot the machine, and quickly press Esc to get into the boot menu. Press the number that matches the Ubuntu Server image.

  5. 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 user@localhost.

  6. To send a shutdown signal to your VM, run virsh shutdown ubuntu. To force shutdown, run virsh destroy ubuntu.

  7. To forward a port, e.g. port 443 from the VM to port 8443 locally, run the following: ssh -p 2222 -L8443:localhost:443 user@localhost

Qemu Gui Mac

Multiple VMs

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 virsh list.

References:

Qemu Gui Mac Os

Note: More discussion on Hacker News





broken image