QEMU is a virtualization technology emulator that allows you to run operating systems and Linux distributions easily on your current system without the need to install them or burn their ISO files. It is like VMware or VirtualBox. You can use it at anytime to emulate running any operating system you want on a lot of devices and architecture.
QEMU is free and open source. And is licensed under GPL 2. it has the ability to run under both KVM and XEN models (if you enabled virtualization technology from your BIOS first) and offers a lot of options and virtualization options. In this article, we’ll explain how to use QEMU and install it.
Table of Contents
How To Install QEMU
Fortunately, QEMU is available to install from almost all the official Linux distributions repositories. Which is a good thing for us since we won’t need to download or install anything from 3rd party repositories.
To install QEMU on Ubuntu/Linux Mint:
sudo apt install qemu qemu-kvm
To install QEMU on Red Hat/CentOS/Fedora (replace dnf with yum for Red Hat/CentOS):
sudo dnf install qemu qemu-kvm
To install QEMU on SUSE/openSUSE
sudo zypper in qemu
To install QEMU on Arch Linux:
sudo pacman -S qemu
How To Use QEMU
QEMU provides a lot of options, architectures and formats to use. And we’ll see many different examples in order to understand the possible ways to achieve our goals using QEMU.
First, we have to create a virtual hard drive image if we want to install our virtual operating system somewhere. This image file will contain all the data and files of the operating system after installation. To do this, we can use the “qemu-img” tool.
To create an image file with the size of 10GB and qcow2 format (default format for QEMU images), run:
qemu-img create -f qcow2 testing-image.img 10G
Note that a new file called “testing-image.img” is now created at your home folder (or the place where you run the terminal). Note also that the size of this file is not 10 Gigabytes, it’s around 150KB only; QEMU won’t use any space unless needed by the virtual operating system, but it will set the maximum allowed space for that image to 10 Gigabytes only
Now that we’ve created our image file, if we have an ISO file for a Linux distribution or any other operating system and we want to test it using QEMU and use the new image file we created as a hard drive, we can run:
qemu-system-x86_64 -m 1024 -boot d -enable-kvm -smp 3 -net nic -net user -hda testing-image.img -cdrom ubuntu-16.04.iso
Let’s explain the previous command part by part:
- [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-m 1024: Here we chose the RAM amount that we want to provide for QEMU when running the ISO file. We chose 1024MB here. You can change it if you like according to your needs.
- [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-boot -d: The boot option allows us to specify the boot order, which device should be booted first? [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-d means that the CD-ROM will be the first, then QEMU will boot normally to the hard drive image. We have used the [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-cdrom option as you can see at the end of the command. You can use [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-c if you want to boot the hard drive image first.
- [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-enable-kvm: This is a very important option. It allows us to use the KVM technology to emulate the architecture we want. Without it, QEMU will use software rendering which is very slow. That’s why we must use this option, just make sure that the virtualization options are enabled from your computer BIOS.
-smp 3:
If we want to use more than 1 core for the emulated operating system, we can use this option. We chose to use 3 cores to run the virtual image which will make it faster. You should change this number according to your computer’s CPU.- [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-net nic -net user: By using these options, we will enable an Ethernet Internet connection to be available in the running virtual machine by default.
- [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-hda testing-image.img: Here we specified the path for the hard drive which will be used. In our case, it was the testing-image.img file which we created before.
- [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-cdrom ubuntu-16.04.iso: Finally we told QEMU that we want to boot our ISO file “ubuntu-16.04.iso”.
After you run the previous command, QEMU will start for you as a standalone window:
Now, if you want to just boot from the image file without the ISO file (for example if you have finished installing and now you always want to boot the installed system), you can just remove the [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]-cdrom option:
qemu-system-x86_64 -m 1024 -boot d -enable-kvm -smp 3 -net nic -net user -hda testing-image.img
Note that in this tutorial, we used the [highlight bgcolor=”#fce0e0″ txtcolor=”#dd3333″]x86_64 architecture to run QEMU. If you want, you can choose from a lot of other available architectures to test your systems on:
ls /usr/bin | grep qemu-system*
qemu-system-aarch64 qemu-system-alpha qemu-system-arm qemu-system-cris qemu-system-i386 qemu-system-lm32 qemu-system-m68k qemu-system-microblaze qemu-system-microblazeel qemu-system-mips qemu-system-mips64 qemu-system-mips64el qemu-system-mipsel qemu-system-moxie qemu-system-or32 qemu-system-ppc qemu-system-ppc64 qemu-system-ppc64le qemu-system-ppcemb qemu-system-sh4 qemu-system-sh4eb qemu-system-sparc qemu-system-sparc64 qemu-system-tricore qemu-system-unicore32 qemu-system-x86_64 qemu-system-x86_64-spice qemu-system-xtensa qemu-system-xtensaeb
For example, if you want to emulate the i386 architecture, you should run the following command:
qemu-system-i386 -m 1024 -boot d -enable-kvm -smp 3 -net nic -net user -hda testing-image.img
Just make sure that the ISO file for Linux distributions and other operating systems you use are for the same architecture that you use on QEMU. If they are different, you may not be able to boot it up or install it.
If you want to use QEMU to boot from a CD / DVD inserted at your disk drive, then you can easily do:
qemu-system-x86_64 -m 1024 -boot d -enable-kvm -smp 3 -net nic -net user -hda testing-image.img -cdrom /dev/cdrom
Conclusion
QEMU is a very effective technology to emulate virtual operating systems. It offers huge possibilities for using and testing operating systems, and gives a very nice performance. It’s free and open source and available in all major Linux distributions’ repositories, which makes it one of the best emulating and virtualization software on the Linux desktop.
For further reading, we recommend checking the official documentation and the wiki page for QEMU.
Nice article, Hanny. Sometimes I use QEMU from the command line. But because I like the comfort of a GUI, sometimes I use Virt-Manager, which relies on libvirt, which can be problematic. Ideally, I would use something more like AQEMU, which is a Qt4 graphical interface used for directly managing QEMU, if I could get it configured properly. I wonder, have you ever managed to get AQEMU working on a recent release of Ubuntu or any other popular distribution? I’ve tried installing AQEMU on Ubuntu, but at least for me, following the setup wizard doesn’t result in a working installation… Read more »
Hi there. Yes AQEMU may be a good choice, I have personally tested it before and it worked with me for Ubuntu 16.10. Glad it worked with you too!
isn’t dnf for Fedora only?
Redhat and Centos still use yum
Oh.. You are definitely right. Meant that they use the same package names (and actually same code) but you are right. The package manager is different. Fixed, thank you!
I think it’s “apt-get install” not “apt install” in this section “sudo apt install qemu qemu-kvm libvirt-bin” to be “sudo apt-get install qemu qemu-kvm libvirt-bin”
No. Ubuntu switched to using “apt” instead of “apt-get” in 16.04. No change is required.
thanks for the options explanations 🙂 I am brand new to using the program the machine was dragging until I saw the -smp option
Nice tutorial and explanations, thank you! Everything worked perfectly the first time around. I now have Win10 contained in a VM, where it belongs. 🙂
You are welcome!
whatever the kvm is on this program mine wont allow it to run got that far and couldn’t get any farther i guess i will keep searching
warning: host doesn’t support requested feature: CPUID.01H:ECX.vmx [bit 5]
getting the same error msg
warning: host doesn’t support requested feature: CPUID.01H:ECX.vmx [bit 5]