summaryrefslogtreecommitdiffstats
path: root/recipes-containers/vcontainer
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2026-02-19 19:07:25 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2026-02-26 01:05:01 +0000
commitc118bfe7af02d22efd4f43b19dcb40fbb348d616 (patch)
treeb1825552e0f893d709c993652acf13ba80e460f5 /recipes-containers/vcontainer
parent5c84f660f7f717765b5662fd69c52cacf0ab64d9 (diff)
downloadmeta-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.sh21
-rwxr-xr-xrecipes-containers/vcontainer/files/vdkr-init.sh8
-rwxr-xr-xrecipes-containers/vcontainer/files/vpdmn-init.sh8
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
19mount -t sysfs sysfs /sys 19mount -t sysfs sysfs /sys
20mount -t devtmpfs devtmpfs /dev 20mount -t devtmpfs devtmpfs /dev
21 21
22# Check for quiet mode (interactive) 22# Check for quiet mode, block device prefix, and init script selection
23QUIET=0 23QUIET=0
24BLK_PREFIX="vd"
25INIT_SCRIPT="/init"
24for param in $(cat /proc/cmdline 2>/dev/null); do 26for 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
28done 32done
29 33
@@ -39,11 +43,11 @@ sleep 2
39 43
40# Show available block devices 44# Show available block devices
41log "Block devices:" 45log "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
46ROOTFS_DEV="/dev/vda" 50ROOTFS_DEV="/dev/${BLK_PREFIX}a"
47 51
48if [ ! -b "$ROOTFS_DEV" ]; then 52if [ ! -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
122log "Switching to real root..." 126log "Switching to real root (init: $INIT_SCRIPT)..."
123 127
124if [ -x /mnt/root/init ]; then 128if [ -x "/mnt/root${INIT_SCRIPT}" ]; then
129 exec switch_root /mnt/root "$INIT_SCRIPT"
130elif [ -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
126elif [ -x /mnt/root/sbin/init ]; then 133elif [ -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
653parse_cmdline 653parse_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)
656if [ "$RUNTIME_9P" = "1" ]; then 656if [ "$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
664fi 664fi
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
165parse_cmdline 165parse_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)
168if [ "$RUNTIME_9P" = "1" ]; then 168if [ "$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
176fi 176fi