Skip to content

Commit 0d53e2a

Browse files
authored
Merge pull request #4310 from flatcar/t-lo/qemu-wrapper-add-snapshot-mode
qemu_template: add -S flag for snapshot mode
2 parents a9005e0 + 7235073 commit 0d53e2a

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎build_library/qemu_template.sh‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SAFE_ARGS=0
2222
FORWARDED_PORTS=""
2323
PRIMARY_DISK_OPTS=""
2424
DISKS=()
25+
SNAPSHOT="off"
2526
USAGE="Usage: $0 [-a authorized_keys] [--] [qemu options...]
2627
Options:
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
5458
This 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
269276
fi
270277

271278
if [ -n "${CONFIG_IMAGE}" ]; then
272-
set -- -drive if=virtio,file="${CONFIG_IMAGE}" "$@"
279+
set -- -drive if=virtio,file="${CONFIG_IMAGE}",snapshot="${SNAPSHOT}" "$@"
273280
fi
274281

275282
if [ -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:-} "$@"
281288
fi
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
"${@}"
298305
done
@@ -317,7 +324,7 @@ fi
317324
if [ -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}" "$@"
321328
fi
322329

323330
if [ -n "${IGNITION_CONFIG_FILE}" ]; then

0 commit comments

Comments
 (0)