QEMU-img Workstation Cheat Sheet
Unlock the full potential of QEMU-img workstation with these essential commands and configuration tips. Learn how to create and resize disk images, install firmware, and manage drivers for your virtual machines.
Install OVMF Binary to get EFI Firmware File For libvirtd/libvirtd-guets
In order to use the firmware you can run qemu the following way
Install the drivers on a Windows guest machine
Pass the ISO file to the guest machine and mount it as a CD-ROM image. Then, in the Windows guest, open the Device Manager and start the driver update wizard. Locate the appropriate device and click to update its driver. In the pop-up window, click to browse in the guest machine to locate the ISO image, and select the driver(s) from it to install.
By testing any livecd quickly you can add following to ~/.bbashrc and then you just have to type qq livecd.iso
qq() {
local iso
iso="$1"
if [[ -z "$iso" || ! -f "$iso" ]]; then
echo "Usage: qq /path/to/live.iso" >&2
return 2
fi
qemu-system-x86_64 \
-machine q35,accel=kvm \
-cpu host \
-smp 4 \
-m 8192 \
-boot order=d \
-cdrom "$iso" \
-nic user,model=virtio-net-pci \
-device qemu-xhci,id=xhci \
-device usb-tablet,bus=xhci.0 \
-display gtk,gl=on \
-device virtio-vga \
-audiodev pipewire,id=snd0 \
-device ich9-intel-hda \
-device hda-duplex,audiodev=snd0 \
-snapshot
}
Creating an Encrypted File Container Using LUKS and a Loop Device
# 1) Create a raw container file (acts like a virtual disk file)
# truncate creates a sparse file (uses space only as data is written)
truncate -s 100G vault.img
# Alternatively, fallocate usually preallocates the full space immediately
# (better for performance, worse for disk space flexibility)
# fallocate -l 100G vault.img
# 2) Attach the file to a loop device (exposes the file as a block device)
# --find finds the first free loop device
# --show prints the allocated loop device (e.g. /dev/loop0)
sudo losetup --find --show vault.img
# Example output: /dev/loop0
# 3) Initialize LUKS encryption on the loop device
# This encrypts the entire virtual disk
sudo cryptsetup luksFormat /dev/loop0
# Open (decrypt) the LUKS container and map it as /dev/mapper/vault
sudo cryptsetup open /dev/loop0 vault
# 4) Create a filesystem INSIDE the decrypted LUKS mapping
# The filesystem will be encrypted at rest
sudo mkfs.ext4 /dev/mapper/vault
# 5) Mount the encrypted filesystem
sudo mkdir -p /mnt/vault
sudo mount /dev/mapper/vault /mnt/vault