Fix initramfs hook integration - copy custom configs before chroot and build with proper mounts
This commit is contained in:
@@ -25,6 +25,15 @@ fi
|
|||||||
rm -rf $BUILD_DIR/rootfs
|
rm -rf $BUILD_DIR/rootfs
|
||||||
mkdir -p $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
|
# Create base Ubuntu system
|
||||||
echo "Running debootstrap (this will take several minutes)..."
|
echo "Running debootstrap (this will take several minutes)..."
|
||||||
debootstrap --arch=amd64 --variant=minbase --components=main,universe,multiverse \
|
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
|
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..."
|
echo "Building custom netboot initramfs..."
|
||||||
KERNEL_VERSION=$(ls -1 $BUILD_DIR/rootfs/boot/vmlinuz-* | sed 's|.*/vmlinuz-||' | head -1)
|
KERNEL_VERSION=$(ls -1 $BUILD_DIR/rootfs/boot/vmlinuz-* | sed 's|.*/vmlinuz-||' | head -1)
|
||||||
|
chroot $BUILD_DIR/rootfs mkinitramfs -v -o /boot/initrd-netboot.img $KERNEL_VERSION
|
||||||
# Use mkinitramfs with custom initramfs directory
|
INITRAMFS_OUTPUT="$BUILD_DIR/rootfs/boot/initrd-netboot.img"
|
||||||
INITRAMFS_CONFIG="$SCRIPT_DIR/initramfs"
|
echo "Initramfs build complete. Size: $(du -h $INITRAMFS_OUTPUT | cut -f1)"
|
||||||
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
|
|
||||||
|
|
||||||
# Copy kernel and netboot initramfs
|
# Copy kernel and netboot initramfs
|
||||||
mkdir -p $IMAGE_DIR/$VERSION
|
mkdir -p $IMAGE_DIR/$VERSION
|
||||||
|
|||||||
Reference in New Issue
Block a user