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.
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
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.
Hanny is a computer science & engineering graduate with a master degree, and an open source software developer. He has created a lot of open source programs over the years, and maintains separate online platforms for promoting open source in his local communities.
Hanny is the founder of FOSS Post.
FOSS Post has been providing high-quality content about open source and Linux software for around 7 years now. All of our content is free so that you can enjoy it whenever you like. However, consider buying us a cup of coffee by joining our Patreon campaign or doing a one-time donation to support our efforts!
You can take a number of interesting and exciting quizzes that the FOSS Post team prepared about various open source software from FOSS Quiz.