summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-10-10 23:28:54 +0000
committerAlyssa Ross <hi@alyssa.is>2022-11-13 23:59:27 +0000
commit395346bd3341fd0468bc4f8a9c427440c5d05438 (patch)
tree5b8e4246a8aa4d627c6b48263fcdad4d4a942687
parent87d1c2a5a5eff07b398135ee83f4299f09b83227 (diff)
downloadspectrum-395346bd3341fd0468bc4f8a9c427440c5d05438.tar
spectrum-395346bd3341fd0468bc4f8a9c427440c5d05438.tar.gz
spectrum-395346bd3341fd0468bc4f8a9c427440c5d05438.tar.bz2
spectrum-395346bd3341fd0468bc4f8a9c427440c5d05438.tar.lz
spectrum-395346bd3341fd0468bc4f8a9c427440c5d05438.tar.xz
spectrum-395346bd3341fd0468bc4f8a9c427440c5d05438.tar.zst
spectrum-395346bd3341fd0468bc4f8a9c427440c5d05438.zip
host/initramfs/extfs.nix: tar2ext4 -> mkfs.ext4 -d
tar2ext4 is designed for making read-only, minimally-sized ext4
images.  That's great for the Spectrum host system's root filesystem,
but it doesn't make sense for the user data partition, because even if
we mark it read/write after running tar2ext4, there will be very few
inodes available, so it won't be very useful for storing data.

To fix this, we use the normal tools for creating an ext4 filesystem.
We create a sparse image of an extremely large size to ensure there's
enough space available for metadata and things for the partition to
grow to fit any disk a user might want to to use Spectrum on, then
shrink the image down to its minimum size.

Doing it this way assumes that the build environment will always
support sparse files.  If this turns out not to be the case, we can
use mkfs.ext4's -E resize= option to set the maximum expected disk
size, and use a smaller size for the initial image size.  I haven't
done that here to avoid having to pick that smaller number.

Now that the filesystem is no longer marked as read-only, we need to
fsck it before every mount, or it won't mount any more after the first
time.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
Message-Id: <20221010232909.1953738-15-hi@alyssa.is>
-rw-r--r--host/initramfs/extfs.nix16
-rw-r--r--host/rootfs/etc/s6-rc/ext/up1
2 files changed, 12 insertions, 5 deletions
diff --git a/host/initramfs/extfs.nix b/host/initramfs/extfs.nix
index dec4017..5c5850f 100644
--- a/host/initramfs/extfs.nix
+++ b/host/initramfs/extfs.nix
@@ -1,7 +1,7 @@
 # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>
 # SPDX-License-Identifier: MIT
 
-{ config, runCommand, tar2ext4 }:
+{ config, runCommand, e2fsprogs, tar2ext4 }:
 
 let
   netvm = import ../../vm/sys/net {
@@ -14,9 +14,10 @@ let
 in
 
 runCommand "ext.ext4" {
-  nativeBuildInputs = [ tar2ext4 ];
+  nativeBuildInputs = [ e2fsprogs ];
 } ''
-  mkdir -p svc/data/appvm-{catgirl,lynx}
+  mkdir -p root/svc/data/appvm-{catgirl,lynx}
+  cd root
 
   tar -C ${netvm} -c data | tar -C svc -x
   chmod +w svc/data
@@ -24,6 +25,11 @@ runCommand "ext.ext4" {
   tar -C ${appvm-catgirl} -c . | tar -C svc/data/appvm-catgirl -x
   tar -C ${appvm-lynx} -c . | tar -C svc/data/appvm-lynx -x
 
-  tar -cf ext.tar svc
-  tar2ext4 -i ext.tar -o $out
+  mkfs.ext4 -d . $out 16T
+  resize2fs -M $out
+
+  # The generated image will have all files owned by the uid and gid
+  # mkfs.ext4 was run as, so we need to normalize ownership to root.
+  find -exec echo $'set_inode_field {} uid 0\nset_inode_field {} gid 0' ';' |
+      debugfs -wf - $out
 ''
diff --git a/host/rootfs/etc/s6-rc/ext/up b/host/rootfs/etc/s6-rc/ext/up
index c189471..78b2637 100644
--- a/host/rootfs/etc/s6-rc/ext/up
+++ b/host/rootfs/etc/s6-rc/ext/up
@@ -2,5 +2,6 @@
 # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>
 
 if { /etc/mdev/wait ext }
+foreground { fsck.ext4 -fp /dev/ext }
 if { resize2fs /dev/ext }
 mount /dev/ext /ext