I'm just getting my feet wet with Alpine Linux (v3.13.2) running as a VM. (On Hyper-V, but I don't think that should matter here.) I'm wondering why, after install, Alpine Linux appears to only use the expected "0-700MB", but during install it writes enough that the .vhdx file grows out to almost 4GiB?
Story
I downloaded and used the "virtual" .iso to install into a new, blank VM. I created a single 127GiB, dynamically-expanding vhdx for the drive; it starts life as a 4MiB .vhdx file, like always. The VM was given 1GiB RAM, 4 vCPU, and a NIC. During setup-alpine
, I chose defaults almost exclusively ('cept the keyboard, and timezone, IIRC), but I installed in "sys" mode to "sda".
At the point where it actually makes the filesystem, that .vhdx file grows from 4MiB to ~1.7GiB at one point, then again up to ~3.5GiB by the time I'm told to reboot.
After dismounting the .iso, rebooting and logging in, I'm finally looking at a 3.72GiB .vhdx file. But df
shows I'm not using nearly that much:
# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 10240 0 10240 0% /dev
shm 505164 0 505164 0% /dev/shm
/dev/sda3 128048328 189800 121310972 0% /
tmpfs 101036 108 100928 0% /run
/dev/sda1 523248 272 522976 0% /boot/efi
It's not all contiguous "zeros", because I tried to do my usual Optimize-Vhd
routine (Powershell), and it didn't reduce the size of the .vhdx. I'm expecting that I'll have to figure out how to defrag from within the Alpine Linux instance before Optimize-Vhd
would shrink the .vhdx file.
Thoughts?
/tmp
or/var
before installing them. After install, the content is "deleted", but the damage has been done and the virtual disk expanded because it was used. You might consider mounting/var
to another virtual disk during installation, then move its contents to your main disk post installation. Another option is figuring out where this unpacking directory is (/var/lib/apk/cache
or something like that) and mounting that astmpfs
or to another virtual disk which can be discarded later. – Stewart Feb 20 '21 at 16:55qcow2
files of KVM virtual machines getting larger because of this behaviour. Difference: When XFS notices that those blocks are not required, it releases them, which then also shrinks theqcow2
file. – berndbausch Feb 21 '21 at 03:01fstrim
had no effect. But I did note that the .vhdx increases in size ~30MiB every time it boots. – Granger Feb 22 '21 at 15:56