diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-09-24 18:13:14 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-09-24 19:59:44 +0200 |
commit | 9d92bd7845a0fcf895a1e7c4ae95c908be673060 (patch) | |
tree | a5c0990def36969e3bc19d4aa9fc97f7dadcc846 /nixos/tests | |
parent | f40c7ed1435d9507868337ae7509fe6d0392498b (diff) | |
download | nixlib-9d92bd7845a0fcf895a1e7c4ae95c908be673060.tar nixlib-9d92bd7845a0fcf895a1e7c4ae95c908be673060.tar.gz nixlib-9d92bd7845a0fcf895a1e7c4ae95c908be673060.tar.bz2 nixlib-9d92bd7845a0fcf895a1e7c4ae95c908be673060.tar.lz nixlib-9d92bd7845a0fcf895a1e7c4ae95c908be673060.tar.xz nixlib-9d92bd7845a0fcf895a1e7c4ae95c908be673060.tar.zst nixlib-9d92bd7845a0fcf895a1e7c4ae95c908be673060.zip |
Add filesystem option to automatically grow to the maximum size
This is primarily for EC2 and other cloud environments, where the disk may be bigger than the original image.
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/make-test.nix | 2 | ||||
-rw-r--r-- | nixos/tests/resize-root.nix | 36 |
2 files changed, 37 insertions, 1 deletions
diff --git a/nixos/tests/make-test.nix b/nixos/tests/make-test.nix index 285ca5b71d6e..f3e26aa7e74d 100644 --- a/nixos/tests/make-test.nix +++ b/nixos/tests/make-test.nix @@ -2,4 +2,4 @@ f: { system ? builtins.currentSystem, ... } @ args: with import ../lib/testing.nix { inherit system; }; -makeTest (if builtins.isFunction f then f (args // { inherit pkgs; }) else f) +makeTest (if builtins.isFunction f then f (args // { inherit pkgs; inherit (pkgs) lib; }) else f) diff --git a/nixos/tests/resize-root.nix b/nixos/tests/resize-root.nix new file mode 100644 index 000000000000..c8ccab38ab6f --- /dev/null +++ b/nixos/tests/resize-root.nix @@ -0,0 +1,36 @@ +import ./make-test.nix ({ pkgs, lib, ...} : { + + meta.maintainers = [ lib.maintainers.eelco ]; + + machine = { config, pkgs, ... }: { + virtualisation.diskSize = 512; + fileSystems = lib.mkVMOverride { + "/".autoResize = true; + }; + }; + + testScript = + '' + # Create a VM with a 512 MiB disk. + $machine->start; + $machine->waitForUnit("multi-user.target"); + my $blocks = $machine->succeed("stat -c %b -f /"); + my $bsize = $machine->succeed("stat -c %S -f /"); + my $size = $blocks * $bsize; + die "wrong free space $size" if $size < 480 * 1024 * 1024 || $size > 512 * 1024 * 1024; + $machine->succeed("touch /marker"); + $machine->shutdown; + + # Grow the disk to 1024 MiB. + system("qemu-img resize vm-state-machine/machine.qcow2 1024M") == 0 or die; + + # Start the VM again and check whether the initrd has correctly + # grown the root filesystem. + $machine->start; + $machine->waitForUnit("multi-user.target"); + $machine->succeed("[ -e /marker ]"); + my $blocks = $machine->succeed("stat -c %b -f /"); + my $size = $blocks * $bsize; + die "wrong free space $size" if $size < 980 * 1024 * 1024 || $size > 1024 * 1024 * 1024; + ''; +}) |