From 368a238d80da0e971237c154cfafbbf8ca3f85d9 Mon Sep 17 00:00:00 2001 From: Bruce Ashfield Date: Fri, 23 Jan 2026 16:15:03 -0500 Subject: vcontainer: consolidate initramfs-create recipes Update vcontainer-initramfs-create.inc to use the image-based approach: - Depend on tiny-initramfs-image for cpio.gz (replaces file extraction) - Depend on rootfs-image for squashfs (unchanged) - Remove DEPENDS on squashfs-tools-native (no longer extracting files) Update recipe files to use the consolidated inc: - vdkr-initramfs-create_1.0.bb - vpdmn-initramfs-create_1.0.bb Boot flow remains unchanged: QEMU boots kernel + tiny initramfs -> preinit mounts rootfs.img from /dev/vda -> switch_root into rootfs.img -> vdkr-init.sh or vpdmn-init.sh runs Signed-off-by: Bruce Ashfield --- .../vcontainer/vcontainer-initramfs-create.inc | 109 ++++++--------------- .../vcontainer/vdkr-initramfs-create_1.0.bb | 2 +- .../vcontainer/vpdmn-initramfs-create_1.0.bb | 2 +- 3 files changed, 33 insertions(+), 80 deletions(-) diff --git a/recipes-containers/vcontainer/vcontainer-initramfs-create.inc b/recipes-containers/vcontainer/vcontainer-initramfs-create.inc index a0930a68..00ae5332 100644 --- a/recipes-containers/vcontainer/vcontainer-initramfs-create.inc +++ b/recipes-containers/vcontainer/vcontainer-initramfs-create.inc @@ -4,18 +4,17 @@ # # vcontainer-initramfs-create.inc # =========================================================================== -# Shared code for building QEMU boot blobs (vdkr/vpdmn) +# Shared code for building QEMU boot blobs (vdkr/vpdmn) - Image-based approach # =========================================================================== # -# This .inc file contains common code for building boot blobs. -# Individual recipes (vdkr-initramfs-create, vpdmn-initramfs-create) -# set VCONTAINER_RUNTIME and include this file. +# This .inc file contains common code for building boot blobs using +# a proper Yocto image-based initramfs instead of extracting files. # # Required variables from including recipe: # VCONTAINER_RUNTIME - "vdkr" or "vpdmn" # # Boot flow: -# QEMU boots kernel + tiny initramfs +# QEMU boots kernel + tiny initramfs (cpio.gz from image recipe) # -> preinit mounts rootfs.img from /dev/vda # -> switch_root into rootfs.img # -> ${VCONTAINER_RUNTIME}-init.sh runs @@ -31,11 +30,10 @@ inherit deploy # Not built by default - user must explicitly request via bitbake or vcontainer-native EXCLUDE_FROM_WORLD = "1" -# Need squashfs-tools-native for unsquashfs to extract files from rootfs.img -DEPENDS = "squashfs-tools-native" +# No extraction tools needed - we use pre-built images +DEPENDS = "" # Always rebuild - no sstate caching for this recipe -# This ensures source file changes (like init scripts in the rootfs) are picked up SSTATE_SKIP_CREATION = "1" do_compile[nostamp] = "1" do_deploy[nostamp] = "1" @@ -44,17 +42,15 @@ do_deploy[nostamp] = "1" INHIBIT_DEFAULT_DEPS = "1" # Dependencies: -# 1. The multiconfig rootfs image from same vruntime-* multiconfig -# 2. The kernel from main build (not multiconfig) +# 1. The tiny initramfs image (produces cpio.gz) +# 2. The multiconfig rootfs image (produces squashfs) +# 3. The kernel from main build # -# Use regular depends for rootfs-image since both recipes are in the same multiconfig -# Use mcdepends for kernel since it's from the main (default) config -do_compile[depends] = "${VCONTAINER_RUNTIME}-rootfs-image:do_image_complete" +# Both initramfs and rootfs images are in the same multiconfig +do_compile[depends] = "${VCONTAINER_RUNTIME}-tiny-initramfs-image:do_image_complete" +do_compile[depends] += "${VCONTAINER_RUNTIME}-rootfs-image:do_image_complete" do_compile[mcdepends] = "mc:${VCONTAINER_MULTICONFIG}::virtual/kernel:do_deploy" -# Preinit is shared between vdkr and vpdmn -SRC_URI = "file://vdkr-preinit.sh" - S = "${UNPACKDIR}" B = "${WORKDIR}/build" @@ -95,78 +91,35 @@ VCONTAINER_MC_DEPLOY = "${TOPDIR}/tmp-${VCONTAINER_MULTICONFIG}/deploy/images/${ do_compile() { mkdir -p ${B} - # ========================================================================= - # PART 1: BUILD TINY INITRAMFS (just for switch_root) - # ========================================================================= - INITRAMFS_DIR="${B}/initramfs" - rm -rf ${INITRAMFS_DIR} - mkdir -p ${INITRAMFS_DIR}/bin - mkdir -p ${INITRAMFS_DIR}/proc - mkdir -p ${INITRAMFS_DIR}/sys - mkdir -p ${INITRAMFS_DIR}/dev - mkdir -p ${INITRAMFS_DIR}/mnt/root - - bbnote "Building tiny initramfs for switch_root..." - - # Extract busybox from the multiconfig rootfs image (squashfs) MC_TMPDIR="${TOPDIR}/tmp-${VCONTAINER_MULTICONFIG}" - ROOTFS_SRC="${MC_TMPDIR}/deploy/images/${MACHINE}/${VCONTAINER_RUNTIME}-rootfs-image-${MACHINE}.rootfs.squashfs" - - if [ ! -f "${ROOTFS_SRC}" ]; then - bbfatal "Rootfs image not found at ${ROOTFS_SRC}. Build it first with: bitbake mc:${VCONTAINER_MULTICONFIG}:${VCONTAINER_RUNTIME}-rootfs-image" - fi - - # Extract busybox from rootfs using unsquashfs - # In usrmerge layouts, busybox is at usr/bin/busybox - BUSYBOX_PATH="usr/bin/busybox" - EXTRACT_DIR="${B}/squashfs-extract" + MC_DEPLOY="${MC_TMPDIR}/deploy/images/${MACHINE}" - bbnote "Extracting busybox from $BUSYBOX_PATH" - # Try native sysroot first, fall back to system unsquashfs - UNSQUASHFS="${WORKDIR}/recipe-sysroot-native/usr/bin/unsquashfs" - if [ ! -x "$UNSQUASHFS" ]; then - UNSQUASHFS="/usr/bin/unsquashfs" - fi - if [ ! -x "$UNSQUASHFS" ]; then - bbfatal "unsquashfs not found in native sysroot or at /usr/bin/unsquashfs" - fi - bbnote "Using unsquashfs: $UNSQUASHFS" + # ========================================================================= + # PART 1: COPY TINY INITRAMFS (cpio.gz from image recipe) + # ========================================================================= + bbnote "Copying tiny initramfs from image build..." - rm -rf "${EXTRACT_DIR}" - $UNSQUASHFS -d "${EXTRACT_DIR}" "${ROOTFS_SRC}" "$BUSYBOX_PATH" + INITRAMFS_SRC="${MC_DEPLOY}/${VCONTAINER_RUNTIME}-tiny-initramfs-image-${MACHINE}.cpio.gz" - if [ ! -f "${EXTRACT_DIR}/${BUSYBOX_PATH}" ]; then - bbfatal "Failed to extract busybox from rootfs image" + if [ ! -f "${INITRAMFS_SRC}" ]; then + bbfatal "Initramfs not found at ${INITRAMFS_SRC}. Build it first with: bitbake mc:${VCONTAINER_MULTICONFIG}:${VCONTAINER_RUNTIME}-tiny-initramfs-image" fi - cp "${EXTRACT_DIR}/${BUSYBOX_PATH}" "${INITRAMFS_DIR}/bin/busybox" - chmod +x ${INITRAMFS_DIR}/bin/busybox - - # Create minimal symlinks - cd ${INITRAMFS_DIR}/bin - for cmd in sh mount umount mkdir ls cat echo sleep switch_root reboot; do - ln -sf busybox $cmd 2>/dev/null || true - done - cd - - - # Install preinit script as /init - cp ${S}/vdkr-preinit.sh ${INITRAMFS_DIR}/init - chmod +x ${INITRAMFS_DIR}/init - - # Create tiny initramfs cpio - bbnote "Creating tiny initramfs cpio archive..." - cd ${INITRAMFS_DIR} - find . | cpio -o -H newc 2>/dev/null | gzip -9 > ${B}/initramfs.cpio.gz - cd - + cp "${INITRAMFS_SRC}" ${B}/initramfs.cpio.gz INITRAMFS_SIZE=$(stat -c%s ${B}/initramfs.cpio.gz) - bbnote "Tiny initramfs created: ${INITRAMFS_SIZE} bytes ($(expr ${INITRAMFS_SIZE} / 1024)KB)" + bbnote "Initramfs copied: ${INITRAMFS_SIZE} bytes ($(expr ${INITRAMFS_SIZE} / 1024)KB)" # ========================================================================= - # PART 2: COPY ROOTFS FROM MULTICONFIG BUILD + # PART 2: COPY ROOTFS (squashfs from image recipe) # ========================================================================= - bbnote "Looking for multiconfig rootfs at: ${MC_TMPDIR}/deploy/images/${MACHINE}" + bbnote "Copying rootfs from image build..." + + ROOTFS_SRC="${MC_DEPLOY}/${VCONTAINER_RUNTIME}-rootfs-image-${MACHINE}.rootfs.squashfs" + + if [ ! -f "${ROOTFS_SRC}" ]; then + bbfatal "Rootfs image not found at ${ROOTFS_SRC}. Build it first with: bitbake mc:${VCONTAINER_MULTICONFIG}:${VCONTAINER_RUNTIME}-rootfs-image" + fi - # ROOTFS_SRC already set above when extracting busybox cp "${ROOTFS_SRC}" ${B}/rootfs.img ROOTFS_SIZE=$(stat -c%s ${B}/rootfs.img) bbnote "Rootfs image copied: ${ROOTFS_SIZE} bytes ($(expr ${ROOTFS_SIZE} / 1024 / 1024)MB)" @@ -223,7 +176,7 @@ Date: $(date) Files: ${KERNEL_IMAGETYPE_INITRAMFS} - Kernel image for QEMU - initramfs.cpio.gz - Tiny initramfs (switch_root only) + initramfs.cpio.gz - Tiny initramfs (busybox + preinit) rootfs.img - Root filesystem with container tools Boot flow: diff --git a/recipes-containers/vcontainer/vdkr-initramfs-create_1.0.bb b/recipes-containers/vcontainer/vdkr-initramfs-create_1.0.bb index 0d665f4a..5eb881e7 100644 --- a/recipes-containers/vcontainer/vdkr-initramfs-create_1.0.bb +++ b/recipes-containers/vcontainer/vdkr-initramfs-create_1.0.bb @@ -32,7 +32,7 @@ # Blobs are deployed to: tmp-vruntime-*/deploy/images/${MACHINE}/vdkr/ # # To build the complete standalone tarball (recommended): -# MACHINE=qemux86-64 bitbake vcontainer-native -c create_tarball +# bitbake vcontainer-tarball # # =========================================================================== diff --git a/recipes-containers/vcontainer/vpdmn-initramfs-create_1.0.bb b/recipes-containers/vcontainer/vpdmn-initramfs-create_1.0.bb index 2c500b30..660e1259 100644 --- a/recipes-containers/vcontainer/vpdmn-initramfs-create_1.0.bb +++ b/recipes-containers/vcontainer/vpdmn-initramfs-create_1.0.bb @@ -32,7 +32,7 @@ # Blobs are deployed to: tmp-vruntime-*/deploy/images/${MACHINE}/vpdmn/ # # To build the complete standalone tarball (recommended): -# MACHINE=qemux86-64 bitbake vcontainer-native -c create_tarball +# bitbake vcontainer-tarball # # =========================================================================== -- cgit v1.2.3-54-g00ecf