Disk size too small when generating qcow2 image

Hi! I been using NixOS together with nixos-generators to build a qcow2 vm image to do some pentest stuff, it was working fine until I added some packages and now I can´t get rid of this error when I run nix build #qcow:

error: builder for '/nix/store/70vy3x5spcq7ar8v4vs7slbqpziax7ni-nixos-disk-image.drv' failed with exit code 1;
       last 10 log lines:
       > [   12.043272] EXT4-fs error (device vda3): ext4_check_bdev_write_error:215: comm kworker/u2:1: Error while async write back metadata
       > [   12.211279] EXT4-fs error (device vda3): ext4_validate_inode_bitmap:105: comm host1: Corrupt inode bitmap - block_group = 100, inode_bitma
p = 3145748
       > [   12.214880] EXT4-fs error (device vda3): ext4_dx_find_entry:1725: inode #783362: block 22: comm host1: Directory block failed checksum
       > unable to create directory /mnt/0000fe03///nix/store/v2f831ivqqmhsfw0ywc58r1cwdi9x3sg-firmware: Success
       > error processing entry /build/root/nix/store/v2f831ivqqmhsfw0ywc58r1cwdi9x3sg-firmware, aborting
       > error processing entry /build/root/nix/store, aborting
       > error processing entry /build/root/nix, aborting
       > [   12.220749] Aborting journal on device vda3-8.
       > [   12.228411] reboot: Restarting system
       > ERROR: cptofs failed. diskSize might be too small for closure.
       For full logs, run 'nix log /nix/store/70vy3x5spcq7ar8v4vs7slbqpziax7ni-nixos-disk-image.drv'.
       note: build failure may have been caused by lack of free disk space

I already tried to increase the disk size with this snippet in my configuration.nix :

 system.build.qcow = lib.mkForce (import "${toString modulesPath}/../lib/make-disk-image.nix" {
    inherit lib config pkgs;
    diskSize = "auto";
    additionalSpace = "10G";
    format = "qcow2";
    partitionTableType = "hybrid";

By running the build with very little packages installed I was able to confirm that the disk inside the VM indeed gets bigger, but that apparently has no effect and the error keeps happening, it seems that something goes wrong after the installed packages go beyond 8GB, does anyone know what can I do to fix this?

The whole code can be seen in this repo: GitHub - vncsb/haxos

If someone comes across this, I found out what was happening, my /tmp was getting full because nix uses it when building, I had 17G on my /tmp but it was not enough because I’m building an entire VM, kind of obvious looking back, oh well.
I just increased the directory size and it worked!

Command used for increasing /tmp size temporarily:

mount -o remount,size=5G /tmp

1 Like

Alternatively, set writableStoreUseTmpfs = false; to use that increased disk space