From adc92a61b4ffe61c9c1deb152fdaf38a64f578f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Lindahl?= Date: Fri, 30 Jan 2026 23:48:30 +0100 Subject: [PATCH] Fix initramfs hook integration - copy custom configs before chroot and build with proper mounts --- build-image.sh | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/build-image.sh b/build-image.sh index 766fac9..a683b1c 100755 --- a/build-image.sh +++ b/build-image.sh @@ -25,6 +25,15 @@ fi rm -rf $BUILD_DIR/rootfs mkdir -p $BUILD_DIR/rootfs +# Copy custom initramfs config into rootfs BEFORE debootstrap, so it's available during chroot +echo "Setting up custom initramfs configuration..." +INITRAMFS_CONFIG="$SCRIPT_DIR/initramfs" +if [ ! -d "$INITRAMFS_CONFIG" ]; then + echo "ERROR: Custom initramfs config not found at $INITRAMFS_CONFIG" + exit 1 +fi +# These dirs will be created by debootstrap, so we'll copy after that + # Create base Ubuntu system echo "Running debootstrap (this will take several minutes)..." debootstrap --arch=amd64 --variant=minbase --components=main,universe,multiverse \ @@ -202,21 +211,20 @@ umount -l $BUILD_DIR/rootfs/proc rm $BUILD_DIR/rootfs/setup.sh -# Build initramfs with custom netboot hooks/scripts +# Copy custom initramfs config into rootfs while /proc is mounted +echo "Installing custom initramfs hooks and scripts..." +INITRAMFS_CONFIG="$SCRIPT_DIR/initramfs" +cp "$INITRAMFS_CONFIG/initramfs.conf" "$BUILD_DIR/rootfs/etc/initramfs-tools/" +cp "$INITRAMFS_CONFIG/modules" "$BUILD_DIR/rootfs/etc/initramfs-tools/" +cp -r "$INITRAMFS_CONFIG/hooks/"* "$BUILD_DIR/rootfs/usr/share/initramfs-tools/hooks/" +cp -r "$INITRAMFS_CONFIG/scripts/"* "$BUILD_DIR/rootfs/usr/share/initramfs-tools/scripts/" + +# Build initramfs while /proc/sys/dev are still mounted echo "Building custom netboot initramfs..." KERNEL_VERSION=$(ls -1 $BUILD_DIR/rootfs/boot/vmlinuz-* | sed 's|.*/vmlinuz-||' | head -1) - -# Use mkinitramfs with custom initramfs directory -INITRAMFS_CONFIG="$SCRIPT_DIR/initramfs" -if [ -d "$INITRAMFS_CONFIG" ]; then - mkinitramfs -d "$INITRAMFS_CONFIG" \ - -k "$KERNEL_VERSION" \ - -o $BUILD_DIR/rootfs/boot/initrd-netboot.img - echo "Initramfs build complete. Size: $(du -h $BUILD_DIR/rootfs/boot/initrd-netboot.img | cut -f1)" -else - echo "ERROR: Custom initramfs config not found at $INITRAMFS_CONFIG" - exit 1 -fi +chroot $BUILD_DIR/rootfs mkinitramfs -v -o /boot/initrd-netboot.img $KERNEL_VERSION +INITRAMFS_OUTPUT="$BUILD_DIR/rootfs/boot/initrd-netboot.img" +echo "Initramfs build complete. Size: $(du -h $INITRAMFS_OUTPUT | cut -f1)" # Copy kernel and netboot initramfs mkdir -p $IMAGE_DIR/$VERSION