Qemu: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(→Boot using host filesystem over 9p: security_model=none) |
(creating/mounting disk images) |
||
Line 1: | Line 1: | ||
=== Creating disk images === |
|||
<source lang="Bash"> |
|||
qemu-img create -f qcow2 disk.qcow2 1G |
|||
</source> |
|||
=== Mounting disk images on the host === |
|||
<source lang="Bash"> |
|||
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 |
|||
</source> |
|||
=== Boot using host filesystem over 9p === |
=== Boot using host filesystem over 9p === |
||
Latest revision as of 06:38, 15 December 2019
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_VIRTIO_PCI=y
- CONFIG_NET_9P=y
- CONFIG_NET_9P_VIRTIO=y
- 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.