rewrite based on reference project from github
This commit is contained in:
@@ -199,26 +199,21 @@ umount -l $BUILD_DIR/rootfs/proc
|
|||||||
|
|
||||||
rm $BUILD_DIR/rootfs/setup.sh
|
rm $BUILD_DIR/rootfs/setup.sh
|
||||||
|
|
||||||
# Build initramfs with dracut using the rootfs modules
|
# Build initramfs with custom netboot hooks/scripts
|
||||||
echo "Building initramfs with dracut using rootfs kernel and modules..."
|
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)
|
||||||
|
|
||||||
# Mount proc/sys temporarily for dracut if needed
|
# Use mkinitramfs with custom initramfs directory
|
||||||
mount -t proc proc $BUILD_DIR/rootfs/proc 2>/dev/null || true
|
INITRAMFS_CONFIG="/srv/netboot/initramfs"
|
||||||
|
if [ -d "$INITRAMFS_CONFIG" ]; then
|
||||||
dracut -f \
|
mkinitramfs -d "$INITRAMFS_CONFIG" \
|
||||||
--add "network" \
|
-k "$KERNEL_VERSION" \
|
||||||
--hostonly \
|
-o $BUILD_DIR/rootfs/boot/initrd-netboot.img
|
||||||
--hostonly-cmdline \
|
echo "Initramfs build complete. Size: $(du -h $BUILD_DIR/rootfs/boot/initrd-netboot.img | cut -f1)"
|
||||||
--include "/usr/share/initramfs-tools/hooks/rooturl" "/usr/share/initramfs-tools/hooks/" \
|
else
|
||||||
--include "/usr/share/initramfs-tools/scripts/local-top/rooturl" "/usr/share/initramfs-tools/scripts/local-top/" \
|
echo "ERROR: Custom initramfs config not found at $INITRAMFS_CONFIG"
|
||||||
-k $KERNEL_VERSION \
|
exit 1
|
||||||
-r $BUILD_DIR/rootfs \
|
fi
|
||||||
$BUILD_DIR/rootfs/boot/initrd-netboot.img
|
|
||||||
|
|
||||||
umount -l $BUILD_DIR/rootfs/proc 2>/dev/null || true
|
|
||||||
|
|
||||||
echo "Initramfs build complete. Size: $(du -h $BUILD_DIR/rootfs/boot/initrd-netboot.img | cut -f1)"
|
|
||||||
|
|
||||||
# Copy kernel and netboot initramfs
|
# Copy kernel and netboot initramfs
|
||||||
mkdir -p $IMAGE_DIR/$VERSION
|
mkdir -p $IMAGE_DIR/$VERSION
|
||||||
|
|||||||
16
dracut-module/90netboot/module-setup.sh
Executable file
16
dracut-module/90netboot/module-setup.sh
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
check() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
depends() {
|
||||||
|
echo network url-lib
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
install() {
|
||||||
|
inst_hook cmdline 90 "$moddir/parse-netboot.sh"
|
||||||
|
inst_hook pre-mount 90 "$moddir/mount-netboot.sh"
|
||||||
|
inst_multiple wget curl
|
||||||
|
}
|
||||||
32
dracut-module/90netboot/mount-netboot.sh
Executable file
32
dracut-module/90netboot/mount-netboot.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Download and mount squashfs root with overlay
|
||||||
|
|
||||||
|
. /tmp/netboot.conf
|
||||||
|
|
||||||
|
info "Downloading root filesystem from http://${BOOT_SERVER}/${IMAGE_VERSION}/filesystem.squashfs"
|
||||||
|
|
||||||
|
mkdir -p /run/netboot
|
||||||
|
wget -O /run/netboot/root.squashfs \
|
||||||
|
"http://${BOOT_SERVER}/${IMAGE_VERSION}/filesystem.squashfs" || \
|
||||||
|
die "Failed to download root filesystem from $BOOT_SERVER"
|
||||||
|
|
||||||
|
info "Download complete, mounting filesystems..."
|
||||||
|
|
||||||
|
# Mount squashfs (read-only base)
|
||||||
|
mkdir -p /run/rootfs/lower
|
||||||
|
mount -t squashfs /run/netboot/root.squashfs /run/rootfs/lower || \
|
||||||
|
die "Failed to mount squashfs"
|
||||||
|
|
||||||
|
# Create tmpfs for overlay (writable layer)
|
||||||
|
mkdir -p /run/rootfs/upper /run/rootfs/work
|
||||||
|
mount -t tmpfs -o size=4G tmpfs /run/rootfs/upper || \
|
||||||
|
die "Failed to create tmpfs overlay"
|
||||||
|
mkdir -p /run/rootfs/upper/upper /run/rootfs/upper/work
|
||||||
|
|
||||||
|
# Mount overlay (combines read-only base + writable tmpfs)
|
||||||
|
mount -t overlay overlay \
|
||||||
|
-o lowerdir=/run/rootfs/lower,upperdir=/run/rootfs/upper/upper,workdir=/run/rootfs/upper/work \
|
||||||
|
/sysroot || \
|
||||||
|
die "Failed to mount overlay"
|
||||||
|
|
||||||
|
info "Root filesystem mounted successfully"
|
||||||
13
dracut-module/90netboot/parse-netboot.sh
Executable file
13
dracut-module/90netboot/parse-netboot.sh
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Parse netboot parameters from kernel command line
|
||||||
|
|
||||||
|
BOOT_SERVER=$(getarg boot_server=)
|
||||||
|
IMAGE_VERSION=$(getarg image_version=)
|
||||||
|
|
||||||
|
[ -z "$BOOT_SERVER" ] && BOOT_SERVER="192.168.100.1"
|
||||||
|
[ -z "$IMAGE_VERSION" ] && IMAGE_VERSION="latest"
|
||||||
|
|
||||||
|
echo "BOOT_SERVER=$BOOT_SERVER" > /tmp/netboot.conf
|
||||||
|
echo "IMAGE_VERSION=$IMAGE_VERSION" >> /tmp/netboot.conf
|
||||||
|
|
||||||
|
info "Netboot: server=$BOOT_SERVER version=$IMAGE_VERSION"
|
||||||
Reference in New Issue
Block a user