I use VirtualBox [1] a lot as (local) virtualization software. It is a full-featured virtualization host, and supports multiple underlying disk image file types for guests.
One of those is VirtualBox' native Virtual Disk Image or VDI file type. An advantage of this type is that one can create a dynamically allocated image. This image will initially be very small and not occupy any space for unused virtual disk sectors, but will grow when a disk sector is written to for the first time. VirtualBox does this by checking for unused sectors.
However, this poses issues for disks with multiple partitions. If the last partition is say a (unused) swap partition, then VirtualBox does not automatically grow the underlying image. Even though the first partition is full, VirtualBox will not grow and therefore the host disk will be full without having reached its full potential.
To solve this issue, the machine needs to be partitioned using one big happy partition. Then VirtualBox will dynamically resize according to expectations.
I use packer [2] to prepare disk images for Debian, together with a preseed [3] file.
Using preseeding to partition the disk is limited to what is supported by the
partition tool,
partman
. The standard mode of operation for partitioning
is
atomic
, and according to the documentation, "All files will be in
one partition". This is not entirely true, as an additional partition will be
created for swap space - and this poses the dynamically resize issue.
So therefore one needs to instruct
partman
to specifically create one
partition only, and not an additional swap partition.
This can be done by adding a recipe to the packer preseed file that will use all available space for one partition only, and by disabling the warning message of not configuring a swap partition.
### Partitioning
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-auto/method string regular
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman-basicfilesystems/no_swap boolean false
d-i partman-auto/expert_recipe string myroot :: 1000 50 -1 ext4 \
$primary{ } $bootable{ } method{ format } format{ } use_filesystem{ } \
filesystem{ ext4 } mountpoint{ / } .
d-i partman-auto/choose_recipe select myroot
The
1000
value in the recipe sets the minimus size for the partition.
The
50
value sets the priority, but as there will only be one partition
created, this is not used. The
-1
is a special value and instructs
partman
to use all available disk space (unlimited partition size),
which is what we're after...
Thanks to an answer on superuser.com [4], which pointed me in the right direction. Sharing the knowledge is the way to go :)
[1] | https://www.virtualbox.org/ |
[2] | https://www.packer.io |
[3] | https://wiki.debian.org/DebianInstaller/Preseed |
[4] | https://superuser.com/questions/458672/ubuntu-preseed-use-whole-disk-space-but-no-swap#920957 |
Comments
comments powered by Disqus