diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-01-23 15:46:16 -0500 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-09 03:34:12 +0000 |
| commit | abf81c8c676bb8997efe4d92a6e4369dcdd6961a (patch) | |
| tree | 9d87667bc28e50d1594fb147c7f8b8d3dd3c028f /recipes-containers/vcontainer | |
| parent | 60b7b35234926f690913ad3d83df35d73a69b61f (diff) | |
| download | meta-virtualization-abf81c8c676bb8997efe4d92a6e4369dcdd6961a.tar.gz | |
vcontainer: add tiny initramfs image infrastructure
Add proper Yocto image recipes for the tiny initramfs used by
vdkr/vpdmn in the switch_root boot flow:
- vcontainer-tiny-initramfs-image.inc: Shared image configuration
- vcontainer-preinit_1.0.bb: Preinit script package (shared)
- vdkr-tiny-initramfs-image.bb: Tiny initramfs for vdkr
- vpdmn-tiny-initramfs-image.bb: Tiny initramfs for vpdmn
The tiny initramfs contains only busybox and a preinit script that:
1. Mounts devtmpfs, proc, sysfs
2. Mounts the squashfs rootfs.img from /dev/vda
3. Creates tmpfs overlay for writes
4. Performs switch_root to the real rootfs
This replaces ad-hoc file extraction with proper image-based builds,
improving reproducibility and maintainability.
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'recipes-containers/vcontainer')
| -rw-r--r-- | recipes-containers/vcontainer/files/vcontainer-preinit.sh (renamed from recipes-containers/vcontainer/files/vdkr-preinit.sh) | 6 | ||||
| -rw-r--r-- | recipes-containers/vcontainer/vcontainer-preinit_1.0.bb | 43 | ||||
| -rw-r--r-- | recipes-containers/vcontainer/vcontainer-tiny-initramfs-image.inc | 70 | ||||
| -rw-r--r-- | recipes-containers/vcontainer/vdkr-tiny-initramfs-image.bb | 13 | ||||
| -rw-r--r-- | recipes-containers/vcontainer/vpdmn-tiny-initramfs-image.bb | 13 |
5 files changed, 142 insertions, 3 deletions
diff --git a/recipes-containers/vcontainer/files/vdkr-preinit.sh b/recipes-containers/vcontainer/files/vcontainer-preinit.sh index 08738022..6f1b7e09 100644 --- a/recipes-containers/vcontainer/files/vdkr-preinit.sh +++ b/recipes-containers/vcontainer/files/vcontainer-preinit.sh | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | # | 3 | # |
| 4 | # SPDX-License-Identifier: GPL-2.0-only | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # | 5 | # |
| 6 | # vdkr-preinit.sh | 6 | # vcontainer-preinit.sh |
| 7 | # Minimal init for initramfs - mounts rootfs and does switch_root | 7 | # Minimal init for initramfs - mounts rootfs and does switch_root |
| 8 | # | 8 | # |
| 9 | # This script runs from the initramfs and: | 9 | # This script runs from the initramfs and: |
| @@ -12,7 +12,7 @@ | |||
| 12 | # 3. Creates overlayfs with tmpfs for writes | 12 | # 3. Creates overlayfs with tmpfs for writes |
| 13 | # 4. Executes switch_root to the overlay root filesystem | 13 | # 4. Executes switch_root to the overlay root filesystem |
| 14 | # | 14 | # |
| 15 | # The real init (/init or /sbin/init on rootfs) then runs vdkr-init.sh logic | 15 | # The real init (/init or /sbin/init on rootfs) then continues boot |
| 16 | 16 | ||
| 17 | # Mount essential filesystems first (needed to check cmdline) | 17 | # Mount essential filesystems first (needed to check cmdline) |
| 18 | mount -t proc proc /proc | 18 | mount -t proc proc /proc |
| @@ -31,7 +31,7 @@ log() { | |||
| 31 | [ "$QUIET" = "0" ] && echo "$@" | 31 | [ "$QUIET" = "0" ] && echo "$@" |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | log "=== vdkr preinit (squashfs) ===" | 34 | log "=== vcontainer preinit (squashfs) ===" |
| 35 | 35 | ||
| 36 | # Wait for block devices to appear | 36 | # Wait for block devices to appear |
| 37 | log "Waiting for block devices..." | 37 | log "Waiting for block devices..." |
diff --git a/recipes-containers/vcontainer/vcontainer-preinit_1.0.bb b/recipes-containers/vcontainer/vcontainer-preinit_1.0.bb new file mode 100644 index 00000000..078a5617 --- /dev/null +++ b/recipes-containers/vcontainer/vcontainer-preinit_1.0.bb | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | # SPDX-FileCopyrightText: Copyright (C) 2025 Bruce Ashfield | ||
| 2 | # | ||
| 3 | # SPDX-License-Identifier: MIT | ||
| 4 | # | ||
| 5 | # vcontainer-preinit_1.0.bb | ||
| 6 | # =========================================================================== | ||
| 7 | # Package containing the preinit script for vcontainer tiny initramfs | ||
| 8 | # =========================================================================== | ||
| 9 | # | ||
| 10 | # This package installs the preinit script as /init for use in a tiny | ||
| 11 | # initramfs. The script: | ||
| 12 | # 1. Mounts essential filesystems (/proc, /sys, /dev) | ||
| 13 | # 2. Mounts the squashfs rootfs from /dev/vda with overlayfs | ||
| 14 | # 3. Executes switch_root to the real root filesystem | ||
| 15 | # | ||
| 16 | # Used by: vdkr-tiny-initramfs-image.bb, vpdmn-tiny-initramfs-image.bb | ||
| 17 | # | ||
| 18 | |||
| 19 | SUMMARY = "Preinit script for vcontainer initramfs" | ||
| 20 | DESCRIPTION = "Minimal init script that mounts squashfs rootfs with overlayfs \ | ||
| 21 | and performs switch_root for vcontainer QEMU environment." | ||
| 22 | HOMEPAGE = "https://git.yoctoproject.org/meta-virtualization/" | ||
| 23 | LICENSE = "GPL-2.0-only" | ||
| 24 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6" | ||
| 25 | |||
| 26 | SRC_URI = "file://vcontainer-preinit.sh" | ||
| 27 | |||
| 28 | S = "${UNPACKDIR}" | ||
| 29 | |||
| 30 | # This package only provides the init script - no dependencies | ||
| 31 | # The initramfs image will pull in busybox separately | ||
| 32 | RDEPENDS:${PN} = "" | ||
| 33 | |||
| 34 | do_install() { | ||
| 35 | install -d ${D} | ||
| 36 | install -m 0755 ${S}/vcontainer-preinit.sh ${D}/init | ||
| 37 | } | ||
| 38 | |||
| 39 | # Package the /init script | ||
| 40 | FILES:${PN} = "/init" | ||
| 41 | |||
| 42 | # Prevent QA warnings about /init location | ||
| 43 | INSANE_SKIP:${PN} += "file-rdeps" | ||
diff --git a/recipes-containers/vcontainer/vcontainer-tiny-initramfs-image.inc b/recipes-containers/vcontainer/vcontainer-tiny-initramfs-image.inc new file mode 100644 index 00000000..1fef7822 --- /dev/null +++ b/recipes-containers/vcontainer/vcontainer-tiny-initramfs-image.inc | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | # SPDX-FileCopyrightText: Copyright (C) 2025 Bruce Ashfield | ||
| 2 | # | ||
| 3 | # SPDX-License-Identifier: MIT | ||
| 4 | # | ||
| 5 | # vcontainer-tiny-initramfs-image.inc | ||
| 6 | # =========================================================================== | ||
| 7 | # Shared tiny initramfs image for vdkr/vpdmn switch_root boot flow | ||
| 8 | # =========================================================================== | ||
| 9 | # | ||
| 10 | # This produces a minimal cpio.gz initramfs containing only: | ||
| 11 | # - busybox (for mount, switch_root, sh, etc.) | ||
| 12 | # - vcontainer-preinit (the /init script) | ||
| 13 | # | ||
| 14 | # Boot flow: | ||
| 15 | # QEMU boots kernel + this initramfs | ||
| 16 | # -> /init (vcontainer-preinit) mounts squashfs rootfs.img from /dev/vda | ||
| 17 | # -> switch_root into rootfs.img with overlayfs | ||
| 18 | # -> ${runtime}-init.sh runs with full container tools | ||
| 19 | # | ||
| 20 | |||
| 21 | SUMMARY = "Tiny initramfs for vcontainer switch_root" | ||
| 22 | DESCRIPTION = "Minimal initramfs containing busybox and preinit script for \ | ||
| 23 | mounting squashfs rootfs and performing switch_root." | ||
| 24 | LICENSE = "MIT" | ||
| 25 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" | ||
| 26 | |||
| 27 | inherit core-image | ||
| 28 | |||
| 29 | # Minimal packages: just busybox and the preinit script | ||
| 30 | # busybox provides: mount, switch_root, sh, mkdir, sleep, cat, ls, echo, reboot | ||
| 31 | PACKAGE_INSTALL = "busybox vcontainer-preinit" | ||
| 32 | |||
| 33 | # No extra features - keep it tiny | ||
| 34 | IMAGE_FEATURES = "" | ||
| 35 | |||
| 36 | # Don't include kernel in initramfs | ||
| 37 | PACKAGE_EXCLUDE = "kernel-image-*" | ||
| 38 | |||
| 39 | # Output as cpio.gz (standard initramfs format) | ||
| 40 | IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}" | ||
| 41 | |||
| 42 | # Keep the image small | ||
| 43 | IMAGE_ROOTFS_SIZE = "8192" | ||
| 44 | IMAGE_ROOTFS_EXTRA_SPACE = "0" | ||
| 45 | |||
| 46 | # No locales needed | ||
| 47 | IMAGE_LINGUAS = "" | ||
| 48 | |||
| 49 | # Suppress the suffix for cleaner naming | ||
| 50 | IMAGE_NAME_SUFFIX = "" | ||
| 51 | |||
| 52 | # Compatible with x86_64 and aarch64 targets | ||
| 53 | COMPATIBLE_HOST = "(x86_64|aarch64).*-linux" | ||
| 54 | |||
| 55 | # Create required directories that busybox/preinit expect | ||
| 56 | ROOTFS_POSTPROCESS_COMMAND += "create_initramfs_dirs;" | ||
| 57 | |||
| 58 | create_initramfs_dirs() { | ||
| 59 | # Create mount points used by preinit | ||
| 60 | install -d ${IMAGE_ROOTFS}/proc | ||
| 61 | install -d ${IMAGE_ROOTFS}/sys | ||
| 62 | install -d ${IMAGE_ROOTFS}/dev | ||
| 63 | install -d ${IMAGE_ROOTFS}/mnt/lower | ||
| 64 | install -d ${IMAGE_ROOTFS}/mnt/upper | ||
| 65 | install -d ${IMAGE_ROOTFS}/mnt/work | ||
| 66 | install -d ${IMAGE_ROOTFS}/mnt/root | ||
| 67 | |||
| 68 | # Create console device node (needed before /dev is mounted) | ||
| 69 | mknod -m 622 ${IMAGE_ROOTFS}/dev/console c 5 1 2>/dev/null || true | ||
| 70 | } | ||
diff --git a/recipes-containers/vcontainer/vdkr-tiny-initramfs-image.bb b/recipes-containers/vcontainer/vdkr-tiny-initramfs-image.bb new file mode 100644 index 00000000..42aa8637 --- /dev/null +++ b/recipes-containers/vcontainer/vdkr-tiny-initramfs-image.bb | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | # SPDX-FileCopyrightText: Copyright (C) 2025 Bruce Ashfield | ||
| 2 | # | ||
| 3 | # SPDX-License-Identifier: MIT | ||
| 4 | # | ||
| 5 | # vdkr-tiny-initramfs-image.bb - Tiny initramfs for vdkr | ||
| 6 | # | ||
| 7 | # Build with: | ||
| 8 | # bitbake mc:vruntime-aarch64:vdkr-tiny-initramfs-image | ||
| 9 | # bitbake mc:vruntime-x86-64:vdkr-tiny-initramfs-image | ||
| 10 | # | ||
| 11 | # Output: ${DEPLOY_DIR_IMAGE}/vdkr-tiny-initramfs-image-${MACHINE}.cpio.gz | ||
| 12 | |||
| 13 | require vcontainer-tiny-initramfs-image.inc | ||
diff --git a/recipes-containers/vcontainer/vpdmn-tiny-initramfs-image.bb b/recipes-containers/vcontainer/vpdmn-tiny-initramfs-image.bb new file mode 100644 index 00000000..c407f013 --- /dev/null +++ b/recipes-containers/vcontainer/vpdmn-tiny-initramfs-image.bb | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | # SPDX-FileCopyrightText: Copyright (C) 2025 Bruce Ashfield | ||
| 2 | # | ||
| 3 | # SPDX-License-Identifier: MIT | ||
| 4 | # | ||
| 5 | # vpdmn-tiny-initramfs-image.bb - Tiny initramfs for vpdmn | ||
| 6 | # | ||
| 7 | # Build with: | ||
| 8 | # bitbake mc:vruntime-aarch64:vpdmn-tiny-initramfs-image | ||
| 9 | # bitbake mc:vruntime-x86-64:vpdmn-tiny-initramfs-image | ||
| 10 | # | ||
| 11 | # Output: ${DEPLOY_DIR_IMAGE}/vpdmn-tiny-initramfs-image-${MACHINE}.cpio.gz | ||
| 12 | |||
| 13 | require vcontainer-tiny-initramfs-image.inc | ||
