QEMU Guide: How to Create and Start Virtual Machines the Quickest and Easiest Way

QEMU

To install and run virtual machines, many use VirtualBox. It is free software from Oracle, and partly owes its fame to the fact that it is for Windows and macOS, in addition to Linux. On systems that use the Torvalds kernel we also have other options such as GNOME Boxes, which in turn is based on QEMU. What we are going to explain here is how to use the root, that QEMU which, among other things, can facilitate the task of moving the images of our virtualized systems.

If we go to GNOME Boxes page, we see a list of things you can do. For example, create virtual machines from operating system images with a few mouse clicks, limit memory resources, redirect USB devices to the machine... All of that is a way of saying that it is an interface or frontend for other software. If that's what you're looking for, Cajas is fine. If you want to use more terminal or for any other reason, QEMU may be better.

How to create a virtual machine with QEMU

The process of creating a virtual machine with QEMU It's not so direct like the one from GNOME Boxes. You have to be clear about what QEMU can be used for, and the best thing I can think of is that it will eliminate potential problems that the user interface may cause, since they do not exist in QEMU. The process would look more or less like this:

  1. First we have to install QEMU. It is in the repositories of most Linux distributions, so it is easily installed with the distribution command. In Debian/Ubuntu “sudo apt install qemu”, in Fedora and derivatives “sudo dnf install qemu”, in Arch and its descendants “sudo pacman -S qemu”… The same as always.
  2. We locate the ISO image that we want to run, either for a live session or to install it.
  3. In the terminal, we write the following, with "image.img" being the name of the image we want to create and "20G" being the size we will give it:
qemu-img create -f qcow2 image.img 20G
  1. The previous command will have created an IMG file that will initially take up very little. It is in that file that the operating system will be loaded/installed. To do this, in the terminal we write:
qemu-system-x86_64 -enable-kvm -cdrom ubuntu.iso -boot menu=on -drive file=ubuntu.img -m 8G

Explaining the command

From the above:

  • qemu-system-x86_64 is the type of system.
  • -enable-kvm will activate KVM.
  • -cdrom ubuntu.iso indicates that the CD player will have that image inside. For this example, not to vary, we will use one from Ubuntu. And a few hours ago they launched the first Daily and I had it in the trash.
  • -boot menu=on It is to bring up the selection menu. You can use "order=D" if you want to change the order and try to boot from drive D first, but for most cases it is better to bring up the menu that allows you to choose the drive by pressing ESC.
  • -drive file=ubuntu.img It is to indicate the hard disk, specifically the virtual hard disk.
  • -m 8G It is to leave you 8GB of RAM. You can leave less, of course, but I have 32GB and I always give my virtual machines a minimum of 8, sometimes more.
  1. We press Enter and it will start, initially in Live mode.

We can install the operating system, and everything will remain in ubuntu.img. We can move that file wherever we want and then launch it as we explain in the next point.

Launching virtual machines and other options

To improve the experience, it is better to add a few more things to the above command.

  • If we put "-cpu host" behind the RAM, it will use the CPU of the host system, and this will be reflected even in programs like the now defunct Neofetch.
  • With "-smp" followed by a number, we will be indicating how many cores we leave to the guest system.
  • To improve the graphical resources, the -vga flag will be used accompanied by a couple of options.

The final command would be:

qemu-system-x86_64 -enable-kvm -cdrom ubuntu.iso -boot menu=on -drive file=ubuntu.img -m 8G -cpu host -smp 2 -vga virtio -display sdl, gl=on

"-vga qxl" if we want only 2D emulation. "sdl" can also be "gtk", and ",gl=on" might not work, in which case the quickest thing to do is not to use it. Even "-virtio" is recommended in almost any scenario.

To open a virtual machine once installed, just remove "-cdrom ubuntu.iso" from the previous command and it will boot from the virtual hard drive. If at any time the cursor gets stuck, you can get out with Ctrl+Alt+G. And that would be all. For more comprehensive use, it is worth using the official documentation.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.