Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rootfs to expand to the backing partition #61

Merged
merged 3 commits into from Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/initrd-devices.nix
Expand Up @@ -28,6 +28,10 @@ in

mkdir -p /etc/udev /tmp /run /lib /mnt /var/log

# Some tools, notably extfs tools, will bark angrily
# when they cannot determine if the device is mounted.
ln -s /proc/mounts /etc/mtab

mkdir -p /dev/pts
mount -t devpts devpts /dev/pts

Expand Down
26 changes: 26 additions & 0 deletions modules/initrd-growpart.nix
@@ -0,0 +1,26 @@
# This builds a rootfs image (ext4) from the current configuration.
{ config, lib, pkgs, ... }:

let
inherit (config.boot) growPartition;
inherit (lib) mkIf mkOrder optionalString;
inherit (import ./initrd-order.nix) BEFORE_SWITCH_ROOT_INIT;
root = config.fileSystems."/";
in
{

mobile.boot.stage-1.init = mkIf growPartition (mkOrder BEFORE_SWITCH_ROOT_INIT ''
(
${optionalString growPartition ''
${optionalString (root.fsType == "ext4") ''
e2fsck -fp ${root.device}
resize2fs -f ${root.device}
''}
''}
)
'');

mobile.boot.stage-1.extraUtils = with pkgs; [
{ package = e2fsprogs; extraCommand = ""; }
];
}
1 change: 1 addition & 0 deletions modules/module-list.nix
Expand Up @@ -17,6 +17,7 @@
./initrd-devices.nix
./initrd-fbterm.nix
./initrd-framebuffer.nix
./initrd-growpart.nix
./initrd-kernel.nix
./initrd-logger.nix
./initrd-loop.nix
Expand Down
27 changes: 9 additions & 18 deletions systems/rootfs.nix
@@ -1,10 +1,16 @@
# This builds a rootfs image (ext4) from the current configuration.
{ config, lib, pkgs, ... }:

let
inherit (config.boot) growPartition;
inherit (lib) optionalString;
in
{
boot.loader.grub.enable = false;
boot.loader.generic-extlinux-compatible.enable = false;

boot.growPartition = lib.mkDefault true;

system.build.rootfs =
pkgs.imageBuilder.fileSystem.makeExt4 {
name = "NIXOS_SYSTEM";
Expand All @@ -23,8 +29,9 @@
echo "Done copying system closure..."
cp -v ${closureInfo}/registration ./nix-path-registration
'';
# FIXME : fixup the partition autoexpand.
extraPadding = pkgs.imageBuilder.size.MiB 500;

# Give some headroom for initial mounting.
extraPadding = pkgs.imageBuilder.size.MiB 20;
}
;

Expand All @@ -40,25 +47,9 @@
}
;

#pkgs.runCommandNoCC "mobile-nixos-rootfs" {} ''
# echo "${config.system.build.toplevel}" > $out
#'';

boot.postBootCommands = ''
# On the first boot do some maintenance tasks
if [ -f /nix-path-registration ]; then
${""
# TODO : optionally resize NIXOS_SYSTEM, depending on the target.
# # Figure out device names for the boot device and root filesystem.
# rootPart=$(readlink -f /dev/disk/by-label/NIXOS_SYSTEM)
# bootDevice=$(lsblk -npo PKNAME $rootPart)

# # Resize the root partition and the filesystem to fit the disk
# echo ",+," | sfdisk -N2 --no-reread $bootDevice
# ${pkgs.parted}/bin/partprobe
# ${pkgs.e2fsprogs}/bin/resize2fs $rootPart
}

# Register the contents of the initial Nix store
${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration

Expand Down