From vegard.wiki
Jump to navigation Jump to search

Creating disk images

qemu-img create -f qcow2 disk.qcow2 1G

Mounting disk images on the host

sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 image.qcow2
sudo mkfs.ext4 /dev/nbd0
sudo mount /dev/nbd0 /mnt/...
# ...
sudo umount /dev/nbd0
sudo qemu-nbd -d /dev/nbd0

Boot using host filesystem over 9p

kvm \
  -cpu host \
  -m 1G \
  -kernel arch/x86/boot/bzImage \
  -append "rootfstype=9p root=/dev/root rootflags=trans=virtio,version=9p2000.L rw console=ttyS0 init=/bin/bash" \
  -serial stdio \
  -fsdev local,id=fsdev0,path=/,security_model=passthrough \
  -device virtio-9p-pci,fsdev=fsdev0,mount_tag=/dev/root \
  -no-reboot \
  -display none

Remember to set the following variables in your kernel config (in order):

  • CONFIG_9P_FS=y

Sometimes it will be useful to use security_model=none rather than passthrough. From the man page: In "passthrough" security model, files are stored using the same credentials as they are created on the guest. This requires QEMU to run as root. [...] "none" security model is same as passthrough except the sever won't report failures if it fails to set file attributes like ownership.