summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2026-01-23 16:15:03 -0500
committerBruce Ashfield <bruce.ashfield@gmail.com>2026-01-23 22:29:29 -0500
commit368a238d80da0e971237c154cfafbbf8ca3f85d9 (patch)
tree9e93ba07874075c63b03bba07f438144b33c261d
parent37349fc93bd1e69da1eb54a7aa3344f5c11f2e12 (diff)
downloadmeta-virtualization-368a238d80da0e971237c154cfafbbf8ca3f85d9.tar.gz
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 <bruce.ashfield@gmail.com>
-rw-r--r--recipes-containers/vcontainer/vcontainer-initramfs-create.inc109
-rw-r--r--recipes-containers/vcontainer/vdkr-initramfs-create_1.0.bb2
-rw-r--r--recipes-containers/vcontainer/vpdmn-initramfs-create_1.0.bb2
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 @@
4# 4#
5# vcontainer-initramfs-create.inc 5# vcontainer-initramfs-create.inc
6# =========================================================================== 6# ===========================================================================
7# Shared code for building QEMU boot blobs (vdkr/vpdmn) 7# Shared code for building QEMU boot blobs (vdkr/vpdmn) - Image-based approach
8# =========================================================================== 8# ===========================================================================
9# 9#
10# This .inc file contains common code for building boot blobs. 10# This .inc file contains common code for building boot blobs using
11# Individual recipes (vdkr-initramfs-create, vpdmn-initramfs-create) 11# a proper Yocto image-based initramfs instead of extracting files.
12# set VCONTAINER_RUNTIME and include this file.
13# 12#
14# Required variables from including recipe: 13# Required variables from including recipe:
15# VCONTAINER_RUNTIME - "vdkr" or "vpdmn" 14# VCONTAINER_RUNTIME - "vdkr" or "vpdmn"
16# 15#
17# Boot flow: 16# Boot flow:
18# QEMU boots kernel + tiny initramfs 17# QEMU boots kernel + tiny initramfs (cpio.gz from image recipe)
19# -> preinit mounts rootfs.img from /dev/vda 18# -> preinit mounts rootfs.img from /dev/vda
20# -> switch_root into rootfs.img 19# -> switch_root into rootfs.img
21# -> ${VCONTAINER_RUNTIME}-init.sh runs 20# -> ${VCONTAINER_RUNTIME}-init.sh runs
@@ -31,11 +30,10 @@ inherit deploy
31# Not built by default - user must explicitly request via bitbake or vcontainer-native 30# Not built by default - user must explicitly request via bitbake or vcontainer-native
32EXCLUDE_FROM_WORLD = "1" 31EXCLUDE_FROM_WORLD = "1"
33 32
34# Need squashfs-tools-native for unsquashfs to extract files from rootfs.img 33# No extraction tools needed - we use pre-built images
35DEPENDS = "squashfs-tools-native" 34DEPENDS = ""
36 35
37# Always rebuild - no sstate caching for this recipe 36# Always rebuild - no sstate caching for this recipe
38# This ensures source file changes (like init scripts in the rootfs) are picked up
39SSTATE_SKIP_CREATION = "1" 37SSTATE_SKIP_CREATION = "1"
40do_compile[nostamp] = "1" 38do_compile[nostamp] = "1"
41do_deploy[nostamp] = "1" 39do_deploy[nostamp] = "1"
@@ -44,17 +42,15 @@ do_deploy[nostamp] = "1"
44INHIBIT_DEFAULT_DEPS = "1" 42INHIBIT_DEFAULT_DEPS = "1"
45 43
46# Dependencies: 44# Dependencies:
47# 1. The multiconfig rootfs image from same vruntime-* multiconfig 45# 1. The tiny initramfs image (produces cpio.gz)
48# 2. The kernel from main build (not multiconfig) 46# 2. The multiconfig rootfs image (produces squashfs)
47# 3. The kernel from main build
49# 48#
50# Use regular depends for rootfs-image since both recipes are in the same multiconfig 49# Both initramfs and rootfs images are in the same multiconfig
51# Use mcdepends for kernel since it's from the main (default) config 50do_compile[depends] = "${VCONTAINER_RUNTIME}-tiny-initramfs-image:do_image_complete"
52do_compile[depends] = "${VCONTAINER_RUNTIME}-rootfs-image:do_image_complete" 51do_compile[depends] += "${VCONTAINER_RUNTIME}-rootfs-image:do_image_complete"
53do_compile[mcdepends] = "mc:${VCONTAINER_MULTICONFIG}::virtual/kernel:do_deploy" 52do_compile[mcdepends] = "mc:${VCONTAINER_MULTICONFIG}::virtual/kernel:do_deploy"
54 53
55# Preinit is shared between vdkr and vpdmn
56SRC_URI = "file://vdkr-preinit.sh"
57
58S = "${UNPACKDIR}" 54S = "${UNPACKDIR}"
59B = "${WORKDIR}/build" 55B = "${WORKDIR}/build"
60 56
@@ -95,78 +91,35 @@ VCONTAINER_MC_DEPLOY = "${TOPDIR}/tmp-${VCONTAINER_MULTICONFIG}/deploy/images/${
95do_compile() { 91do_compile() {
96 mkdir -p ${B} 92 mkdir -p ${B}
97 93
98 # =========================================================================
99 # PART 1: BUILD TINY INITRAMFS (just for switch_root)
100 # =========================================================================
101 INITRAMFS_DIR="${B}/initramfs"
102 rm -rf ${INITRAMFS_DIR}
103 mkdir -p ${INITRAMFS_DIR}/bin
104 mkdir -p ${INITRAMFS_DIR}/proc
105 mkdir -p ${INITRAMFS_DIR}/sys
106 mkdir -p ${INITRAMFS_DIR}/dev
107 mkdir -p ${INITRAMFS_DIR}/mnt/root
108
109 bbnote "Building tiny initramfs for switch_root..."
110
111 # Extract busybox from the multiconfig rootfs image (squashfs)
112 MC_TMPDIR="${TOPDIR}/tmp-${VCONTAINER_MULTICONFIG}" 94 MC_TMPDIR="${TOPDIR}/tmp-${VCONTAINER_MULTICONFIG}"
113 ROOTFS_SRC="${MC_TMPDIR}/deploy/images/${MACHINE}/${VCONTAINER_RUNTIME}-rootfs-image-${MACHINE}.rootfs.squashfs" 95 MC_DEPLOY="${MC_TMPDIR}/deploy/images/${MACHINE}"
114
115 if [ ! -f "${ROOTFS_SRC}" ]; then
116 bbfatal "Rootfs image not found at ${ROOTFS_SRC}. Build it first with: bitbake mc:${VCONTAINER_MULTICONFIG}:${VCONTAINER_RUNTIME}-rootfs-image"
117 fi
118
119 # Extract busybox from rootfs using unsquashfs
120 # In usrmerge layouts, busybox is at usr/bin/busybox
121 BUSYBOX_PATH="usr/bin/busybox"
122 EXTRACT_DIR="${B}/squashfs-extract"
123 96
124 bbnote "Extracting busybox from $BUSYBOX_PATH" 97 # =========================================================================
125 # Try native sysroot first, fall back to system unsquashfs 98 # PART 1: COPY TINY INITRAMFS (cpio.gz from image recipe)
126 UNSQUASHFS="${WORKDIR}/recipe-sysroot-native/usr/bin/unsquashfs" 99 # =========================================================================
127 if [ ! -x "$UNSQUASHFS" ]; then 100 bbnote "Copying tiny initramfs from image build..."
128 UNSQUASHFS="/usr/bin/unsquashfs"
129 fi
130 if [ ! -x "$UNSQUASHFS" ]; then
131 bbfatal "unsquashfs not found in native sysroot or at /usr/bin/unsquashfs"
132 fi
133 bbnote "Using unsquashfs: $UNSQUASHFS"
134 101
135 rm -rf "${EXTRACT_DIR}" 102 INITRAMFS_SRC="${MC_DEPLOY}/${VCONTAINER_RUNTIME}-tiny-initramfs-image-${MACHINE}.cpio.gz"
136 $UNSQUASHFS -d "${EXTRACT_DIR}" "${ROOTFS_SRC}" "$BUSYBOX_PATH"
137 103
138 if [ ! -f "${EXTRACT_DIR}/${BUSYBOX_PATH}" ]; then 104 if [ ! -f "${INITRAMFS_SRC}" ]; then
139 bbfatal "Failed to extract busybox from rootfs image" 105 bbfatal "Initramfs not found at ${INITRAMFS_SRC}. Build it first with: bitbake mc:${VCONTAINER_MULTICONFIG}:${VCONTAINER_RUNTIME}-tiny-initramfs-image"
140 fi 106 fi
141 cp "${EXTRACT_DIR}/${BUSYBOX_PATH}" "${INITRAMFS_DIR}/bin/busybox"
142 chmod +x ${INITRAMFS_DIR}/bin/busybox
143
144 # Create minimal symlinks
145 cd ${INITRAMFS_DIR}/bin
146 for cmd in sh mount umount mkdir ls cat echo sleep switch_root reboot; do
147 ln -sf busybox $cmd 2>/dev/null || true
148 done
149 cd -
150
151 # Install preinit script as /init
152 cp ${S}/vdkr-preinit.sh ${INITRAMFS_DIR}/init
153 chmod +x ${INITRAMFS_DIR}/init
154
155 # Create tiny initramfs cpio
156 bbnote "Creating tiny initramfs cpio archive..."
157 cd ${INITRAMFS_DIR}
158 find . | cpio -o -H newc 2>/dev/null | gzip -9 > ${B}/initramfs.cpio.gz
159 cd -
160 107
108 cp "${INITRAMFS_SRC}" ${B}/initramfs.cpio.gz
161 INITRAMFS_SIZE=$(stat -c%s ${B}/initramfs.cpio.gz) 109 INITRAMFS_SIZE=$(stat -c%s ${B}/initramfs.cpio.gz)
162 bbnote "Tiny initramfs created: ${INITRAMFS_SIZE} bytes ($(expr ${INITRAMFS_SIZE} / 1024)KB)" 110 bbnote "Initramfs copied: ${INITRAMFS_SIZE} bytes ($(expr ${INITRAMFS_SIZE} / 1024)KB)"
163 111
164 # ========================================================================= 112 # =========================================================================
165 # PART 2: COPY ROOTFS FROM MULTICONFIG BUILD 113 # PART 2: COPY ROOTFS (squashfs from image recipe)
166 # ========================================================================= 114 # =========================================================================
167 bbnote "Looking for multiconfig rootfs at: ${MC_TMPDIR}/deploy/images/${MACHINE}" 115 bbnote "Copying rootfs from image build..."
116
117 ROOTFS_SRC="${MC_DEPLOY}/${VCONTAINER_RUNTIME}-rootfs-image-${MACHINE}.rootfs.squashfs"
118
119 if [ ! -f "${ROOTFS_SRC}" ]; then
120 bbfatal "Rootfs image not found at ${ROOTFS_SRC}. Build it first with: bitbake mc:${VCONTAINER_MULTICONFIG}:${VCONTAINER_RUNTIME}-rootfs-image"
121 fi
168 122
169 # ROOTFS_SRC already set above when extracting busybox
170 cp "${ROOTFS_SRC}" ${B}/rootfs.img 123 cp "${ROOTFS_SRC}" ${B}/rootfs.img
171 ROOTFS_SIZE=$(stat -c%s ${B}/rootfs.img) 124 ROOTFS_SIZE=$(stat -c%s ${B}/rootfs.img)
172 bbnote "Rootfs image copied: ${ROOTFS_SIZE} bytes ($(expr ${ROOTFS_SIZE} / 1024 / 1024)MB)" 125 bbnote "Rootfs image copied: ${ROOTFS_SIZE} bytes ($(expr ${ROOTFS_SIZE} / 1024 / 1024)MB)"
@@ -223,7 +176,7 @@ Date: $(date)
223 176
224Files: 177Files:
225 ${KERNEL_IMAGETYPE_INITRAMFS} - Kernel image for QEMU 178 ${KERNEL_IMAGETYPE_INITRAMFS} - Kernel image for QEMU
226 initramfs.cpio.gz - Tiny initramfs (switch_root only) 179 initramfs.cpio.gz - Tiny initramfs (busybox + preinit)
227 rootfs.img - Root filesystem with container tools 180 rootfs.img - Root filesystem with container tools
228 181
229Boot flow: 182Boot 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 @@
32# Blobs are deployed to: tmp-vruntime-*/deploy/images/${MACHINE}/vdkr/ 32# Blobs are deployed to: tmp-vruntime-*/deploy/images/${MACHINE}/vdkr/
33# 33#
34# To build the complete standalone tarball (recommended): 34# To build the complete standalone tarball (recommended):
35# MACHINE=qemux86-64 bitbake vcontainer-native -c create_tarball 35# bitbake vcontainer-tarball
36# 36#
37# =========================================================================== 37# ===========================================================================
38 38
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 @@
32# Blobs are deployed to: tmp-vruntime-*/deploy/images/${MACHINE}/vpdmn/ 32# Blobs are deployed to: tmp-vruntime-*/deploy/images/${MACHINE}/vpdmn/
33# 33#
34# To build the complete standalone tarball (recommended): 34# To build the complete standalone tarball (recommended):
35# MACHINE=qemux86-64 bitbake vcontainer-native -c create_tarball 35# bitbake vcontainer-tarball
36# 36#
37# =========================================================================== 37# ===========================================================================
38 38