From c24e91732598f088acdb49129002fa437ec33192 Mon Sep 17 00:00:00 2001 From: Victor Shlein Date: Tue, 19 Jun 2018 01:25:00 +0300 Subject: [PATCH 1/7] nixos/stage-1: added F2FS resizing F2FS is used on Raspberry Pi-like devices to enhance SD card performance. Allowing F2FS resizing would help in automatic deploying of SD card images without a Linux box to resize the file system offline. --- nixos/modules/system/boot/stage-1-init.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index de8451bbe31..227ab450002 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -336,6 +336,10 @@ mountFS() { echo "resizing $device..." e2fsck -fp "$device" resize2fs "$device" + else [ "$fsType" = f2fs ]; then + echo "resizing $device..." + fsck.f2fs -fp "$device" + resize.f2fs "$device" fi ;; esac From b44d3045421bfd9857a4cecae4250e88a973f015 Mon Sep 17 00:00:00 2001 From: Victor Shlein Date: Tue, 19 Jun 2018 01:36:12 +0300 Subject: [PATCH 2/7] nixos/stage-1: added f2fs-tools' tools for resizing --- nixos/modules/system/boot/stage-1.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index 55bb6d3449c..21f2fdb4158 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -126,6 +126,10 @@ let ${optionalString (any (fs: fs.autoResize) fileSystems) '' # We need mke2fs in the initrd. copy_bin_and_libs ${pkgs.e2fsprogs}/sbin/resize2fs + # Copy also f2fs-tools' fsck and resize + # TODO: separate these in case no f2fs fs are present + copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/fsck.f2fs + copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/resize.f2fs ''} # Copy secrets if needed. From 0b9b7be5bfb85fc549146a36130cdd874a2381af Mon Sep 17 00:00:00 2001 From: kisik21 Date: Tue, 19 Jun 2018 01:59:08 +0300 Subject: [PATCH 3/7] nixos/stage-1: fixed if-else block --- nixos/modules/system/boot/stage-1-init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index 227ab450002..f2084842db8 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -336,7 +336,7 @@ mountFS() { echo "resizing $device..." e2fsck -fp "$device" resize2fs "$device" - else [ "$fsType" = f2fs ]; then + elif [ "$fsType" = f2fs ]; then echo "resizing $device..." fsck.f2fs -fp "$device" resize.f2fs "$device" From 577483738c602581b3688a136dd9dea988e4ecd7 Mon Sep 17 00:00:00 2001 From: Victor Shlein Date: Tue, 19 Jun 2018 13:53:34 +0300 Subject: [PATCH 4/7] nixos/stage-1: implemented separate check for f2fs filesystems in need of resizing --- nixos/modules/system/boot/stage-1.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index 21f2fdb4158..b1fddf8dd7f 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -126,8 +126,11 @@ let ${optionalString (any (fs: fs.autoResize) fileSystems) '' # We need mke2fs in the initrd. copy_bin_and_libs ${pkgs.e2fsprogs}/sbin/resize2fs - # Copy also f2fs-tools' fsck and resize - # TODO: separate these in case no f2fs fs are present + ''} + + # Copy f2fs-tools' fsck and resize if needed + ${optionalString (any (fs: fs.autoResize) (filter (x: x.fsType == "f2fs") fileSystems)) '' + # We need f2fs-tools' tools to resize filesystems copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/fsck.f2fs copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/resize.f2fs ''} From 34234dcb511066dd1e4fe75d80ee89519a8c8001 Mon Sep 17 00:00:00 2001 From: Victor Shlein Date: Tue, 19 Jun 2018 14:23:39 +0300 Subject: [PATCH 5/7] nixos/stage-1: new separate conditionals for ext4 and f2fs resizing tools --- nixos/modules/system/boot/stage-1.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index b1fddf8dd7f..c7ea408f595 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -122,14 +122,14 @@ let copy_bin_and_libs ${pkgs.kmod}/bin/kmod ln -sf kmod $out/bin/modprobe - # Copy resize2fs if needed. - ${optionalString (any (fs: fs.autoResize) fileSystems) '' + # Copy resize2fs if any ext* filesystems are to be resized + ${optionalString (any (fs: fs.autoResize && (lib.hasPrefix "ext" fs.fsType)) fileSystems) '' # We need mke2fs in the initrd. copy_bin_and_libs ${pkgs.e2fsprogs}/sbin/resize2fs ''} # Copy f2fs-tools' fsck and resize if needed - ${optionalString (any (fs: fs.autoResize) (filter (x: x.fsType == "f2fs") fileSystems)) '' + ${optionalString (any (fs: fs.autoResize && fs.fsType = "f2fs") fileSystems) '' # We need f2fs-tools' tools to resize filesystems copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/fsck.f2fs copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/resize.f2fs From 4fa88fcecb4c57550837484cc6f371e77b53459a Mon Sep 17 00:00:00 2001 From: Victor Shlein Date: Tue, 19 Jun 2018 14:27:36 +0300 Subject: [PATCH 6/7] nixos/stage-1, nixos/f2fs: moved f2fs resizing tools include in f2fs module --- nixos/modules/system/boot/stage-1.nix | 7 ------- nixos/modules/tasks/filesystems/f2fs.nix | 5 +++++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index c7ea408f595..d66533fa067 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -128,13 +128,6 @@ let copy_bin_and_libs ${pkgs.e2fsprogs}/sbin/resize2fs ''} - # Copy f2fs-tools' fsck and resize if needed - ${optionalString (any (fs: fs.autoResize && fs.fsType = "f2fs") fileSystems) '' - # We need f2fs-tools' tools to resize filesystems - copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/fsck.f2fs - copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/resize.f2fs - ''} - # Copy secrets if needed. ${optionalString (!config.boot.loader.supportsInitrdSecrets) (concatStringsSep "\n" (mapAttrsToList (dest: source: diff --git a/nixos/modules/tasks/filesystems/f2fs.nix b/nixos/modules/tasks/filesystems/f2fs.nix index d103ff1a57b..df803535aa4 100644 --- a/nixos/modules/tasks/filesystems/f2fs.nix +++ b/nixos/modules/tasks/filesystems/f2fs.nix @@ -14,6 +14,11 @@ in boot.initrd.extraUtilsCommands = mkIf inInitrd '' copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/fsck.f2fs + ${optionalString (any (fs: fs.autoResize && fs.fsType = "f2fs") fileSystems) '' + # We need f2fs-tools' tools to resize filesystems + copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/resize.f2fs + ''} + ''; }; } From 62d21f251194ba93541239adc22afd0fb4f38f71 Mon Sep 17 00:00:00 2001 From: Victor Shlein Date: Tue, 19 Jun 2018 14:31:06 +0300 Subject: [PATCH 7/7] nixos/f2fs: fixed autoresize check --- nixos/modules/tasks/filesystems/f2fs.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/tasks/filesystems/f2fs.nix b/nixos/modules/tasks/filesystems/f2fs.nix index df803535aa4..a305235979a 100644 --- a/nixos/modules/tasks/filesystems/f2fs.nix +++ b/nixos/modules/tasks/filesystems/f2fs.nix @@ -4,6 +4,7 @@ with lib; let inInitrd = any (fs: fs == "f2fs") config.boot.initrd.supportedFilesystems; + fileSystems = filter (x: x.fsType == "f2fs") config.system.build.fileSystems; in { config = mkIf (any (fs: fs == "f2fs") config.boot.supportedFilesystems) { @@ -14,7 +15,7 @@ in boot.initrd.extraUtilsCommands = mkIf inInitrd '' copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/fsck.f2fs - ${optionalString (any (fs: fs.autoResize && fs.fsType = "f2fs") fileSystems) '' + ${optionalString (any (fs: fs.autoResize) fileSystems) '' # We need f2fs-tools' tools to resize filesystems copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/resize.f2fs ''}