I have tried Virtualbox and Gnome Boxes in Linux and would have to say I am far from satisfied with the experience. So I decided to have a look at qemu.
Browsing around looking at help documents for qemu is a rather frightening experience. They tend to lay out all the options ( and there are many, it is like rsync) and delve into a range of sophisticated applications, without giving a novice the slightest idea where to start.
I finally found a document which gets you started with only half a page of instructions. It is here
https://drewdevault.com/2018/09/10/Getting-started-with-qemu.html
So I am going to follow that and see if I can find what the bare minimum is to get a qemu virtual machine started
First I have to install qemu. I am in Void Linux so I do
[nevj@trinity qemu]$ xbps-query -Rs qemu
[-] aqemu-0.9.4_1 GUI to QEMU and KVM emulators, written in Qt4
[-] novaboot-20191023_2 Tool that automates booting of operating systems...
[-] qemu-7.1.0_2 Open Source Processor Emulator
[-] qemu-ga-7.1.0_2 QEMU Guest Agent
[-] qemu-user-static-7.1.0_3 QEMU User-mode emulators (statically compiled)
[-] qemuconf-0.2.1_3 Simple qemu launcher with config file support
[-] virtme-0.1.1_5 Easy way to test your kernel changes in qemu/kvm
Those are all the packages that involve qemu. I am only going to install qemu
so
# xbps-install qemu
and we are ready to go.
One has to decide where (on disk) to put images of virtual machines. I decided to dedicate a spare 350Gb partition called /dev/sdb14. It has an ext4 filesystem. So I made a mount point and mounted it
# cd /
# mkdir qemuvm
# chmod 777 qemuvm
# mount /dev/sdb14 /qemuvm
I now need to make, in that /qemuvm filesystem a file to contain the virtual hard disk for a Debian VM. II am going to make a Debian 11 VM).
$ qemu-img create -f qcow2 /qemuvm/debian.qcow2 30G
Formatting '/qemuvm/debian.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=32212254720 lazy_refcounts=off refcount_bits=16
So it makes a 30Gb file in qcow2
format
Now I simply follow the help doocument and give the qemu command to install Debian in a VM
[nevj@trinity Downloads]$ qemu-system-x86_64 -enable-kvm -m 1G -nic user,model=virtio -drive file=/qemuvm/debian.qcow2,media=disk,if=virtio -cdrom debian-live-11.6.0-amd64-gnome+nonfree.iso -sdl
qemu-system-x86_64: -sdl: invalid option
So there is some problem with -sdl option.
I used qemu-system-x86_64 --help
to find out that sdl
is a display option
-display spice-app[,gl=on|off]
-display sdl[,gl=on|core|es|off][,grab-mod=<mod>][,show-cursor=on|off]
[,window-close=on|off]
-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]
[,show-tabs=on|off][,show-cursor=on|off][,window-close=on|off]
-display vnc=<display>[,<optargs>]
-display curses[,charset=<encoding>]
-display egl-headless[,rendernode=<file>]
-display none
and after a few trials and errors I settled on
qemu-system-x86_64 -enable-kvm -m 5G -nic user,model=virtio -drive file=/qemuvm/debian.qcow2,media=disk,if=virtio -cdrom debian-live-11.6.0-amd64-gnome+nonfree.iso -display sdl,gl=on,show-cursor=on
If you want to understand the options, look at the document link.
Now I get a screen from the Debian live .iso offering a few options including, Live System, Install, Graphical Install, …
I choose Live System , and Debian runs… I get a conventional Gnome screen.
OK, so having seen the live system will work, I click the install button and get the Calamares installer.
So I answer all the install questions, let it write Debian to the virtual hard disk setup, shut it down, and restart with
qemu-system-x86_64 -enable-kvm -m 5G -nic user,model=virtio -drive file=/qemuvm/debian.qcow2,media=disk,if=virtio -display sdl,gl=on,show-cursor=on
That is you leave out the -cdrom option to tell it to boot from the created VM.
Now it boots first to a grub screen, then goes straight to a full screen window with the login manager, then when you login it goes to a full screen window with Debian/Gnome booted.
It looks like this
I can start up a terminal window and run Firefox straight away,
So there is Firefox looking at the FOSS site, and the terminal window has an
ip
command showing that the network interface is ens3
.
So how easy is that for a first try? The only hitch was the startup document had one error ( the sdl option)
Now, that is the way to learn some complicated command… start with the absolute minimum working system.
It is far from ideal. Here are some things I have to address
- there is no root user. Calamares did not offer me the chance to setup a root password. I can use sudo, but I cant su because I dont know the password. Not sure if this is Calamares, or if the VM is suppressing root.
- Firefox has internet connectivity… but I cant ping anything.
- I cant see any of the Void hosts interfaces. I need to learn how to build a link to my local ethernet to access printers. I think I may need a bridge?
- I cant see Void hosts devices. So I cant access a usb stick or a memory card or a DVD.
- I cant see the Void hosts filesystems or any of the unmounted partitions on my disks.
The way to deal with that is to attack issues one at a time and build on my minimal system.
There are other help documents
https://www.qemu.org/docs/master/
What is interesting to me is that I can now run Debian in this virtual machine, when it will not run natively in the computer because of graphics driver issues.
How does qemu compare with Vbox or Boxes? Well it is early days but I did not encounter anything like the Vbox Guest Additions nonsense. Boxes is just qemu with a gui anyway.
I would welcome any help or comments. It is going to be a long road getting qemu configured the way I need. I need to know about all the shortcuts and traps.