From 1d0da378fc1e229f15e7df20219bb23f10209fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Sun, 30 May 2021 11:03:43 +0000 Subject: [PATCH] Switch to drive snapshots --- README.md | 4 ++-- docker-compose.yml | 2 +- entrypoint.sh | 15 ++------------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 7ba39f3..7d14380 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ Dockerized QEMU image for reproducibly testing stuff on Windows. Prepare OS image as described below. -If OS image is mounted to the Docker container as read-only -it is first copied during Docker container launch. +Disk image is used as read-only using the QEMU disk snapshot option, +all local changes are lost after Docker container restart. Specify MAC address via environment variable `MAC`. For more example see `docker-compose.yml` You probably need the machines to come up with diff --git a/docker-compose.yml b/docker-compose.yml index 5fbbb35..8442de5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,4 +15,4 @@ services: tmpfs: - /tmp environment: - - MAC=52:54:00:5e:00:05 + - MAC=52:54:00:12:34:56 diff --git a/entrypoint.sh b/entrypoint.sh index 5770a25..93dd32e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,16 +2,6 @@ set -x set -e -# Source image path -IMAGE=/data/image.bin - -# TODO: With QEMU snapshots instead -if [ ! -w $IMAGE ]; then - echo "Data volume is not writable, assuming discardable VM and copying to tmpfs" - cp $IMAGE /tmp/image.bin - IMAGE=/tmp/image.bin -fi - # Create macvlan interface on Docker's eth0 ip link add link eth0 name macvtap0 type macvtap mode bridge ip link set dev macvtap0 address ${MAC:?} @@ -26,11 +16,10 @@ mknod "/dev/tap$(cat /sys/class/net/macvtap0/ifindex)" c $major $minor -machine pc-i440fx-4.2,accel=kvm \ -m 8192 \ -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x6 \ - -blockdev "{\"driver\":\"file\",\"filename\":\"$IMAGE\",\"node-name\":\"libvirt-1-storage\",\"auto-read-only\":true,\"discard\":\"unmap\"}" \ - -blockdev "{\"node-name\":\"libvirt-1-format\",\"read-only\":false,\"driver\":\"raw\",\"file\":\"libvirt-1-storage\"}" \ - -device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-1-format,id=scsi0-0-0-0,bootindex=2 \ -device virtio-net-pci,netdev=hostnet0,id=net0,mac=$(cat /sys/class/net/macvtap0/address) \ -device virtio-balloon-pci \ + -drive if=none,id=hd,file=/data/image.bin,snapshot=on,format=raw \ + -device scsi-hd,drive=hd \ -usb \ -device usb-ehci,id=ehci \ -device usb-tablet,bus=usb-bus.0 \