From a611aa6005ae56139f8ee704966e80ed4f7f2a31 Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Tue, 28 Sep 2021 22:47:26 +0100 Subject: [PATCH] Add disk preallocation support preallocation=metadata is now the default as it offers the best size/performance. --- README.md | 14 ++++++++++++++ quickemu | 12 +++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d3e53b7..556e333 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,20 @@ Add additional lines to your virtual machine configuration: * `cpu_cores="4"` - Specify the number of CPU cores allocated to the VM * `ram="4G"` - Specify the amount of RAM to allocate to the VM * `disk="16G"` - Specify the size of the virtual disk allocated to the VM + + +## Disk preallocation + +Preallocation mode (allowed values: `off`, `metadata` (default), `falloc`, `full`). +An image with preallocated metadata is initially larger but can improve performance +when the image needs to grow. `falloc` and `full` preallocations are like the +same options of raw format, but sets up metadata also. + +Specify what disk preallocation should be used, if any, when creating the system +disk image by adding a line like this to your VM configuration. + + * `preallocation="metadata"` + ## Floppy disks If you're like [Alan Pope](https://popey.com) you'll probably want to mount a diff --git a/quickemu b/quickemu index 3fe1044..71e1ed3 100755 --- a/quickemu +++ b/quickemu @@ -235,10 +235,19 @@ function vm_boot() { if [ ! -f "${disk_img}" ]; then # If there is no disk image, create a new image. mkdir -p "${VMDIR}" 2>/dev/null - if ! ${QEMU_IMG} create -q -f qcow2 "${disk_img}" "${disk}"; then + case ${preallocation} in + off|metadata|falloc|full) true;; + *) + echo "ERROR! ${preallocation} is an unsupported disk preallocation option." + exit 1;; + esac + + # https://blog.programster.org/qcow2-performance + if ! ${QEMU_IMG} create -q -f qcow2 -o lazy_refcounts=on,preallocation="${preallocation}" "${disk_img}" "${disk}"; then echo "ERROR! Failed to create ${disk_img}" exit 1 fi + if [ -z "${iso}" ] && [ -z "${img}" ]; then echo "ERROR! You haven't specified a .iso or .img image to boot from." exit 1 @@ -618,6 +627,7 @@ guest_os="linux" img="" iso="" port_forwards=() +preallocation="metadata" ram="" usb_devices=() virtio_blk="on"