Guide to QEMU as a Virtual Machine
Using QEMU as a Virtual Machine
· 2 min read · 363 words
Why QEMU? #
There are lots of virtual machine software like VirtualBox and VMWare. But why specifically QEMU?
So, firstly, QEMU can emulate any software hardware:
- ARM
- AArch
- RISC-V
- MIPS
- PowerPC
It does full system emulation like CPU, timers, interrupts, UART, SPI/I2C. VMWare and VirtualBox do not emulate real hardware, they virtualise generic PC hardware. QEMU gives you near native performance and deeper kernel intergration and is highly scalable.
There are many customisation that is possible with QEMU, it has virt-manager which provides a GUI to manage the VMs or we can use the normal command line.
They can easily be automated with either scripts or Makefiles.
They have really advanced I/O and storage features like Copy on Write (CoW), qcow snapshots and backing up files.
This is really useful when it comes to building Operating systems for different architecture while working in a system with another architecture and its really useful for baremetal embedded systems projects and experimenting with other architectures.
Using QEMU to boot an ISO #
To create a VM, we have to initialise a virtual hard disk.
qemu-imgis used to create and convert virtual hard disk files.createflags tellsqemu-imgto create a virtual hard disk.-f qcow2(QEMU Copy on Write) is the file format for QEMU, it is the native format for QEMU.Then
os_image.imgis the name of the image that we are going to create and10Gis the size allocation, this can be set according to user preference.
qemu-img create -f qcow2 os_image.img 10G
Next up, to launch the VM from a iso
qemu-system-x86_64runs the qemu emulator for 64 bit x86 systems, this is available for almost all the other architectures too.-enable-kvmis to enable hardware acceleration using KVM (Kernel-based Virtual Machine).-cdrom <iso_name>specify the iso file as the CDROM file.-boot menu=onis enables a small boot menu at VM startup so you can choose boot device-drive file=os_image.imgis attached.-m 2Gis the RAM that we are going to allocate for the virtual machince to function. This is dependant on user preferences and the system capability.
qemu-system-x86_64 -enable-kvm -cdrom os.iso -boot menu=on -drive file=alpine.img -m 2G