at 16.09-beta 1.1 kB view raw
1# This module automatically grows the root partition on virtual machines. 2# This allows an instance to be created with a bigger root filesystem 3# than provided by the machine image. 4 5{ config, lib, pkgs, ... }: 6 7with lib; 8 9{ 10 11 options = { 12 13 virtualisation.growPartition = mkOption { 14 type = types.bool; 15 default = true; 16 }; 17 18 }; 19 20 config = mkIf config.virtualisation.growPartition { 21 22 boot.initrd.extraUtilsCommands = '' 23 copy_bin_and_libs ${pkgs.gawk}/bin/gawk 24 copy_bin_and_libs ${pkgs.gnused}/bin/sed 25 copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk 26 copy_bin_and_libs ${pkgs.utillinux}/sbin/lsblk 27 cp -v ${pkgs.cloud-utils}/bin/growpart $out/bin/growpart 28 ln -s sed $out/bin/gnused 29 ''; 30 31 boot.initrd.postDeviceCommands = '' 32 rootDevice="${config.fileSystems."/".device}" 33 if [ -e "$rootDevice" ]; then 34 rootDevice="$(readlink -f "$rootDevice")" 35 parentDevice="$(lsblk -npo PKNAME "$rootDevice")" 36 TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}" 37 udevadm settle 38 fi 39 ''; 40 41 }; 42 43}