diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-19 19:07:25 +0000 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-26 01:05:01 +0000 |
| commit | c118bfe7af02d22efd4f43b19dcb40fbb348d616 (patch) | |
| tree | b1825552e0f893d709c993652acf13ba80e460f5 /recipes-containers/vcontainer | |
| parent | 5c84f660f7f717765b5662fd69c52cacf0ab64d9 (diff) | |
| download | meta-virtualization-c118bfe7af02d22efd4f43b19dcb40fbb348d616.tar.gz | |
vcontainer: generalize init scripts for pluggable hypervisor backends
Make preinit and guest init scripts hypervisor-agnostic:
- vcontainer-preinit.sh: add vcontainer.init= cmdline parameter for
init script selection and vcontainer.blk= for block device prefix
(QEMU uses /dev/vda, Xen uses /dev/xvda)
- vdkr-init.sh, vpdmn-init.sh: use NINE_P_TRANSPORT variable for 9p
mount transport (virtio for QEMU, xen for Xen)
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 | 21 | ||||
| -rwxr-xr-x | recipes-containers/vcontainer/files/vdkr-init.sh | 8 | ||||
| -rwxr-xr-x | recipes-containers/vcontainer/files/vpdmn-init.sh | 8 |
3 files changed, 22 insertions, 15 deletions
diff --git a/recipes-containers/vcontainer/files/vcontainer-preinit.sh b/recipes-containers/vcontainer/files/vcontainer-preinit.sh index 6f1b7e09..7d4e7072 100644 --- a/recipes-containers/vcontainer/files/vcontainer-preinit.sh +++ b/recipes-containers/vcontainer/files/vcontainer-preinit.sh | |||
| @@ -19,11 +19,15 @@ mount -t proc proc /proc | |||
| 19 | mount -t sysfs sysfs /sys | 19 | mount -t sysfs sysfs /sys |
| 20 | mount -t devtmpfs devtmpfs /dev | 20 | mount -t devtmpfs devtmpfs /dev |
| 21 | 21 | ||
| 22 | # Check for quiet mode (interactive) | 22 | # Check for quiet mode, block device prefix, and init script selection |
| 23 | QUIET=0 | 23 | QUIET=0 |
| 24 | BLK_PREFIX="vd" | ||
| 25 | INIT_SCRIPT="/init" | ||
| 24 | for param in $(cat /proc/cmdline 2>/dev/null); do | 26 | for param in $(cat /proc/cmdline 2>/dev/null); do |
| 25 | case "$param" in | 27 | case "$param" in |
| 26 | docker_interactive=1) QUIET=1 ;; | 28 | docker_interactive=1) QUIET=1 ;; |
| 29 | vcontainer.blk=*) BLK_PREFIX="${param#vcontainer.blk=}" ;; | ||
| 30 | vcontainer.init=*) INIT_SCRIPT="${param#vcontainer.init=}" ;; | ||
| 27 | esac | 31 | esac |
| 28 | done | 32 | done |
| 29 | 33 | ||
| @@ -39,11 +43,11 @@ sleep 2 | |||
| 39 | 43 | ||
| 40 | # Show available block devices | 44 | # Show available block devices |
| 41 | log "Block devices:" | 45 | log "Block devices:" |
| 42 | [ "$QUIET" = "0" ] && ls -la /dev/vd* 2>/dev/null || log "No virtio block devices found" | 46 | [ "$QUIET" = "0" ] && ls -la /dev/${BLK_PREFIX}* 2>/dev/null || log "No /dev/${BLK_PREFIX}* block devices found" |
| 43 | 47 | ||
| 44 | # The rootfs.img is always the first virtio-blk device (/dev/vda) | 48 | # The rootfs.img is always the first block device |
| 45 | # Additional devices (input, state) come after | 49 | # QEMU: /dev/vda, Xen: /dev/xvda |
| 46 | ROOTFS_DEV="/dev/vda" | 50 | ROOTFS_DEV="/dev/${BLK_PREFIX}a" |
| 47 | 51 | ||
| 48 | if [ ! -b "$ROOTFS_DEV" ]; then | 52 | if [ ! -b "$ROOTFS_DEV" ]; then |
| 49 | echo "ERROR: Rootfs device $ROOTFS_DEV not found!" | 53 | echo "ERROR: Rootfs device $ROOTFS_DEV not found!" |
| @@ -119,9 +123,12 @@ mount --move /dev /mnt/root/dev | |||
| 119 | # 2. chroot into it | 123 | # 2. chroot into it |
| 120 | # 3. Execute the new init | 124 | # 3. Execute the new init |
| 121 | # 4. Delete everything in the old initramfs | 125 | # 4. Delete everything in the old initramfs |
| 122 | log "Switching to real root..." | 126 | log "Switching to real root (init: $INIT_SCRIPT)..." |
| 123 | 127 | ||
| 124 | if [ -x /mnt/root/init ]; then | 128 | if [ -x "/mnt/root${INIT_SCRIPT}" ]; then |
| 129 | exec switch_root /mnt/root "$INIT_SCRIPT" | ||
| 130 | elif [ -x /mnt/root/init ]; then | ||
| 131 | log "WARNING: $INIT_SCRIPT not found, falling back to /init" | ||
| 125 | exec switch_root /mnt/root /init | 132 | exec switch_root /mnt/root /init |
| 126 | elif [ -x /mnt/root/sbin/init ]; then | 133 | elif [ -x /mnt/root/sbin/init ]; then |
| 127 | exec switch_root /mnt/root /sbin/init | 134 | exec switch_root /mnt/root /sbin/init |
diff --git a/recipes-containers/vcontainer/files/vdkr-init.sh b/recipes-containers/vcontainer/files/vdkr-init.sh index a993aca4..e1e869b2 100755 --- a/recipes-containers/vcontainer/files/vdkr-init.sh +++ b/recipes-containers/vcontainer/files/vdkr-init.sh | |||
| @@ -652,13 +652,13 @@ setup_cgroups | |||
| 652 | # Parse kernel command line | 652 | # Parse kernel command line |
| 653 | parse_cmdline | 653 | parse_cmdline |
| 654 | 654 | ||
| 655 | # Mount virtio-9p share if available (for fast storage output in batch-import mode) | 655 | # Mount 9p share if available (for fast storage output in batch-import mode) |
| 656 | if [ "$RUNTIME_9P" = "1" ]; then | 656 | if [ "$RUNTIME_9P" = "1" ]; then |
| 657 | mkdir -p /mnt/share | 657 | mkdir -p /mnt/share |
| 658 | if mount -t 9p -o trans=virtio,version=9p2000.L,cache=none ${VCONTAINER_SHARE_NAME} /mnt/share 2>/dev/null; then | 658 | if mount -t 9p -o trans=${NINE_P_TRANSPORT},version=9p2000.L,cache=none ${VCONTAINER_SHARE_NAME} /mnt/share 2>/dev/null; then |
| 659 | log "Mounted virtio-9p share at /mnt/share (fast I/O enabled)" | 659 | log "Mounted 9p share at /mnt/share (transport: ${NINE_P_TRANSPORT})" |
| 660 | else | 660 | else |
| 661 | log "WARNING: Could not mount virtio-9p share, falling back to console output" | 661 | log "WARNING: Could not mount 9p share, falling back to console output" |
| 662 | RUNTIME_9P="0" | 662 | RUNTIME_9P="0" |
| 663 | fi | 663 | fi |
| 664 | fi | 664 | fi |
diff --git a/recipes-containers/vcontainer/files/vpdmn-init.sh b/recipes-containers/vcontainer/files/vpdmn-init.sh index 70acd8af..7f661102 100755 --- a/recipes-containers/vcontainer/files/vpdmn-init.sh +++ b/recipes-containers/vcontainer/files/vpdmn-init.sh | |||
| @@ -164,13 +164,13 @@ setup_cgroups | |||
| 164 | # Parse kernel command line | 164 | # Parse kernel command line |
| 165 | parse_cmdline | 165 | parse_cmdline |
| 166 | 166 | ||
| 167 | # Mount virtio-9p share if available (for fast storage output in batch-import mode) | 167 | # Mount 9p share if available (for fast storage output in batch-import mode) |
| 168 | if [ "$RUNTIME_9P" = "1" ]; then | 168 | if [ "$RUNTIME_9P" = "1" ]; then |
| 169 | mkdir -p /mnt/share | 169 | mkdir -p /mnt/share |
| 170 | if mount -t 9p -o trans=virtio,version=9p2000.L,cache=none ${VCONTAINER_SHARE_NAME} /mnt/share 2>/dev/null; then | 170 | if mount -t 9p -o trans=${NINE_P_TRANSPORT},version=9p2000.L,cache=none ${VCONTAINER_SHARE_NAME} /mnt/share 2>/dev/null; then |
| 171 | log "Mounted virtio-9p share at /mnt/share (fast I/O enabled)" | 171 | log "Mounted 9p share at /mnt/share (transport: ${NINE_P_TRANSPORT})" |
| 172 | else | 172 | else |
| 173 | log "WARNING: Could not mount virtio-9p share, falling back to console output" | 173 | log "WARNING: Could not mount 9p share, falling back to console output" |
| 174 | RUNTIME_9P="0" | 174 | RUNTIME_9P="0" |
| 175 | fi | 175 | fi |
| 176 | fi | 176 | fi |
