summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-02-21 22:59:07 +0000
committerAlyssa Ross <hi@alyssa.is>2023-02-21 22:59:07 +0000
commita96f09dfa6a247e2ba8068a348522a48b885dec3 (patch)
tree88b3b60ae492e24f5e6ba66f148f77bf76d3277b
parent97cceff243d988b91258dbf1b6cf1f0a4bd65f5c (diff)
downloadspectrum-a96f09dfa6a247e2ba8068a348522a48b885dec3.tar
spectrum-a96f09dfa6a247e2ba8068a348522a48b885dec3.tar.gz
spectrum-a96f09dfa6a247e2ba8068a348522a48b885dec3.tar.bz2
spectrum-a96f09dfa6a247e2ba8068a348522a48b885dec3.tar.lz
spectrum-a96f09dfa6a247e2ba8068a348522a48b885dec3.tar.xz
spectrum-a96f09dfa6a247e2ba8068a348522a48b885dec3.tar.zst
spectrum-a96f09dfa6a247e2ba8068a348522a48b885dec3.zip
host/initramfs: enable testing booting from loop
Previously, the only way to test the logic in etc/probe for booting
from a loop device (as used in the combined image) was to build a
whole combined image, which is slow because it's huge and involves
building several intermediary images.

Now, it's possible to test this configuration from within the
initramfs development environment, with just

	  make run RUN_IMAGE=build/loop.img

Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rw-r--r--host/initramfs/Makefile20
-rw-r--r--host/initramfs/shell.nix2
2 files changed, 19 insertions, 3 deletions
diff --git a/host/initramfs/Makefile b/host/initramfs/Makefile
index 602b5b3..63e24ef 100644
--- a/host/initramfs/Makefile
+++ b/host/initramfs/Makefile
@@ -9,8 +9,12 @@ QEMU_KVM = qemu-kvm
 CPIO = cpio
 CPIOFLAGS = --reproducible -R +0:+0 -H newc
 SCRIPTS = ../../scripts
+TAR = tar
+TAR2EXT4 = tar2ext4
 VERITYSETUP = veritysetup
 
+RUN_IMAGE = build/live.img
+
 build/initramfs: $(MICROCODE) build/local.cpio $(PACKAGES_CPIO)
 	cat $(MICROCODE) > $@
 	cat build/local.cpio $(PACKAGES_CPIO) | gzip -9n >> $@
@@ -59,11 +63,23 @@ build/live.img: $(SCRIPTS)/format-uuid.sh $(SCRIPTS)/make-gpt.sh build/rootfs.ve
 	    $(ROOT_FS):4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$($(SCRIPTS)/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)")
 	mv $@.tmp $@
 
+build/loop.tar: build/live.img
+	$(TAR) -cf $@ build/live.img
+
+.SUFFIXES: .ext4 .tar
+.tar.ext4:
+	$(TAR2EXT4) -i $< -o $@
+
+build/loop.img: $(SCRIPTS)/make-gpt.sh build/loop.ext4
+	$(SCRIPTS)/make-gpt.sh $@.tmp \
+	    build/loop.ext4:56a3bbc3-aefa-43d9-a64d-7b3fd59bbc4e
+	mv $@.tmp $@
+
 clean:
 	rm -rf build
 .PHONY: clean
 
-run: build/initramfs build/rootfs.verity.roothash build/live.img
+run: build/initramfs build/rootfs.verity.roothash $(RUN_IMAGE)
 	$(QEMU_KVM) -m 4G \
 	    -kernel $(KERNEL) \
 	    -initrd build/initramfs \
@@ -75,6 +91,6 @@ run: build/initramfs build/rootfs.verity.roothash build/live.img
 	    -device virtio-vga-gl \
 	    -device qemu-xhci \
 	    -device usb-storage,drive=drive1,removable=true \
-	    -drive file=build/live.img,id=drive1,format=raw,if=none,readonly=true \
+	    -drive file=$(RUN_IMAGE),id=drive1,format=raw,if=none,readonly=true \
 	    -drive file=$(EXT_FS),format=raw,if=virtio,readonly=true
 .PHONY: run
diff --git a/host/initramfs/shell.nix b/host/initramfs/shell.nix
index cbd2c60..5745b98 100644
--- a/host/initramfs/shell.nix
+++ b/host/initramfs/shell.nix
@@ -18,7 +18,7 @@ with pkgs;
 
 initramfs.overrideAttrs ({ nativeBuildInputs ? [], ... }: {
   nativeBuildInputs = nativeBuildInputs ++ [
-    cryptsetup qemu_kvm util-linux
+    cryptsetup qemu_kvm tar2ext4 util-linux
   ];
 
   EXT_FS = extfs;