@@ -22,6 +22,7 @@ SAFE_ARGS=0
2222FORWARDED_PORTS=" "
2323PRIMARY_DISK_OPTS=" "
2424DISKS=()
25+ SNAPSHOT=" off"
2526USAGE=" Usage: $0 [-a authorized_keys] [--] [qemu options...]
2627Options:
2728 -i FILE File containing an Ignition config
@@ -49,6 +50,9 @@ Options:
4950 -K FILE Set kernel for direct boot used to simulate a PXE boot (with -r).
5051 -r FILE Set initrd for direct boot used to simulate a PXE boot (with -K).
5152 -s Safe settings: single simple cpu and no KVM.
53+ -S Use snapshot mode for all drives / pflash devices.
54+ Snapshot mode will never write modifications to disk.
55+ All changes will be discarded when the VM shuts down.
5256 -h this ;-)
5357
5458This script is a wrapper around qemu for starting Flatcar virtual machines.
@@ -128,6 +132,9 @@ while [ $# -ge 1 ]; do
128132 -r|-initrd-file)
129133 VM_INITRD=" $2 "
130134 shift 2 ;;
135+ -S|-snapshot)
136+ SNAPSHOT=" on"
137+ shift ;;
131138 -v|-verbose)
132139 set -x
133140 shift ;;
@@ -269,14 +276,14 @@ if [ -n "${CONFIG_DRIVE}" ]; then
269276fi
270277
271278if [ -n " ${CONFIG_IMAGE} " ]; then
272- set -- -drive if=virtio,file=" ${CONFIG_IMAGE} " " $@ "
279+ set -- -drive if=virtio,file=" ${CONFIG_IMAGE} " ,snapshot= " ${SNAPSHOT} " " $@ "
273280fi
274281
275282if [ -n " ${VM_IMAGE} " ]; then
276283 if [[ ,${PRIMARY_DISK_OPTS} , = * ,drive= * || ,${PRIMARY_DISK_OPTS} , = * ,bootindex= * ]]; then
277284 die " Can't override drive or bootindex options for primary disk"
278285 fi
279- set -- -drive if=none,id=blk,file=" ${VM_IMAGE} " \
286+ set -- -drive if=none,id=blk,file=" ${VM_IMAGE} " ,snapshot= " ${SNAPSHOT} " \
280287 -device virtio-blk-pci,drive=blk,bootindex=1${PRIMARY_DISK_OPTS: +,}${PRIMARY_DISK_OPTS:- } " $@ "
281288fi
282289
@@ -292,7 +299,7 @@ for disk in "${DISKS[@]}"; do
292299 disk_opts=
293300 fi
294301 set -- \
295- -drive " if=none,id=${disk_id} ,file=${disk_path} " \
302+ -drive " if=none,id=${disk_id} ,file=${disk_path} ,snapshot= ${SNAPSHOT} " \
296303 -device " virtio-blk-pci,drive=${disk_id}${disk_opts: +,}${disk_opts:- } " \
297304 " ${@ } "
298305done
317324if [ -n " ${VM_PFLASH_RO} " ] && [ -n " ${VM_PFLASH_RW} " ]; then
318325 set -- \
319326 -drive if=pflash,unit=0,file=" ${VM_PFLASH_RO} " ,format=qcow2,readonly=on \
320- -drive if=pflash,unit=1,file=" ${VM_PFLASH_RW} " ,format=qcow2 " $@ "
327+ -drive if=pflash,unit=1,file=" ${VM_PFLASH_RW} " ,format=qcow2,snapshot= " ${SNAPSHOT} " " $@ "
321328fi
322329
323330if [ -n " ${IGNITION_CONFIG_FILE} " ]; then
0 commit comments