From 1de8e1b02ef9bd5e65382f0b3998106ffc328094 Mon Sep 17 00:00:00 2001 From: Nathan Zadoks Date: Wed, 17 Feb 2016 12:59:51 +0100 Subject: [PATCH 1/3] amazon-grow-partition module: autodetect the root device --- nixos/modules/virtualisation/amazon-grow-partition.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nixos/modules/virtualisation/amazon-grow-partition.nix b/nixos/modules/virtualisation/amazon-grow-partition.nix index 69b80d900bad..02a0dd65fdc0 100644 --- a/nixos/modules/virtualisation/amazon-grow-partition.nix +++ b/nixos/modules/virtualisation/amazon-grow-partition.nix @@ -10,13 +10,17 @@ copy_bin_and_libs ${pkgs.gawk}/bin/gawk copy_bin_and_libs ${pkgs.gnused}/bin/sed copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk + copy_bin_and_libs ${pkgs.utillinux}/sbin/lsblk cp -v ${pkgs.cloud-utils}/bin/growpart $out/bin/growpart ln -s sed $out/bin/gnused ''; boot.initrd.postDeviceCommands = '' - if [ -e /dev/xvda ] && [ -e /dev/xvda1 ]; then - TMPDIR=/run sh $(type -P growpart) /dev/xvda 1 + rootDevice="${config.fileSystems."/".device}" + if [ -e "$rootDevice" ]; then + rootDevice="$(readlink -f "$rootDevice")" + parentDevice="$(lsblk -npo PKNAME "$rootDevice")" + TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}" udevadm settle fi ''; From 346c31000bebfec7cbcf4dbc3276d0af90544351 Mon Sep 17 00:00:00 2001 From: Nathan Zadoks Date: Wed, 17 Feb 2016 13:02:59 +0100 Subject: [PATCH 2/3] amazon-grow-partition module: rename to grow-partition --- nixos/modules/virtualisation/amazon-image.nix | 4 +++- ...-grow-partition.nix => grow-partition.nix} | 21 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) rename nixos/modules/virtualisation/{amazon-grow-partition.nix => grow-partition.nix} (67%) diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix index ebf398fa266f..f9c3f2e53adc 100644 --- a/nixos/modules/virtualisation/amazon-image.nix +++ b/nixos/modules/virtualisation/amazon-image.nix @@ -11,10 +11,12 @@ with lib; let cfg = config.ec2; in { - imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-grow-partition.nix ./amazon-init.nix ]; + imports = [ ../profiles/headless.nix ./ec2-data.nix ./grow-partition.nix ./amazon-init.nix ]; config = { + virtualisation.growPartition = cfg.hvm; + fileSystems."/" = { device = "/dev/disk/by-label/nixos"; autoResize = true; diff --git a/nixos/modules/virtualisation/amazon-grow-partition.nix b/nixos/modules/virtualisation/grow-partition.nix similarity index 67% rename from nixos/modules/virtualisation/amazon-grow-partition.nix rename to nixos/modules/virtualisation/grow-partition.nix index 02a0dd65fdc0..345479051664 100644 --- a/nixos/modules/virtualisation/amazon-grow-partition.nix +++ b/nixos/modules/virtualisation/grow-partition.nix @@ -1,11 +1,22 @@ -# This module automatically grows the root partition on Amazon EC2 HVM -# instances. This allows an instance to be created with a bigger root -# filesystem than provided by the AMI. +# This module automatically grows the root partition on virtual machines. +# This allows an instance to be created with a bigger root filesystem +# than provided by the machine image. { config, lib, pkgs, ... }: { - config = lib.mkIf config.ec2.hvm { + + options = { + + virtualisation.growPartition = mkOption { + type = types.bool; + default = true; + }; + + }; + + config = mkIf config.virtualisation.growPartition { + boot.initrd.extraUtilsCommands = '' copy_bin_and_libs ${pkgs.gawk}/bin/gawk copy_bin_and_libs ${pkgs.gnused}/bin/sed @@ -24,5 +35,7 @@ udevadm settle fi ''; + }; + } From f503f648b3b980d38418eff2516112d60e067bc8 Mon Sep 17 00:00:00 2001 From: Nathan Zadoks Date: Tue, 26 Jan 2016 12:21:42 +0100 Subject: [PATCH 3/3] virtualbox-image module: enable partition / filesystem growth --- nixos/modules/virtualisation/virtualbox-image.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nixos/modules/virtualisation/virtualbox-image.nix b/nixos/modules/virtualisation/virtualbox-image.nix index 3a598a1c7dc5..b6a5b3e4788d 100644 --- a/nixos/modules/virtualisation/virtualbox-image.nix +++ b/nixos/modules/virtualisation/virtualbox-image.nix @@ -8,6 +8,8 @@ let in { + imports = [ ./grow-partition.nix ]; + options = { virtualbox = { baseImageSize = mkOption { @@ -64,7 +66,10 @@ in { ''; }; - fileSystems."/".device = "/dev/disk/by-label/nixos"; + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + autoResize = true; + }; boot.loader.grub.device = "/dev/sda";