From 6830fa9e8a766347ed73128502c38a5c3e6ef67c Mon Sep 17 00:00:00 2001 From: Roman Penyaev Date: Sun, 22 Oct 2023 13:23:47 +0200 Subject: [PATCH] xen-tools: add `eve-enter-container` script Once terminal is attached to the Vm console which hosts a container user can execute `eve-enter-container` script and enter corresponding container. Script uses `nsenter -t $pid` and pid is extracted from the /mnt/entrypoint-pid file, created by the chroot2 utility. Signed-off-by: Roman Penyaev --- pkg/xen-tools/Dockerfile | 1 + pkg/xen-tools/initrd/base.files | 1 + pkg/xen-tools/initrd/eve-enter-container | 13 +++++++++++++ 3 files changed, 15 insertions(+) create mode 100755 pkg/xen-tools/initrd/eve-enter-container diff --git a/pkg/xen-tools/Dockerfile b/pkg/xen-tools/Dockerfile index cdb6a4f8af..cd25679cd6 100644 --- a/pkg/xen-tools/Dockerfile +++ b/pkg/xen-tools/Dockerfile @@ -12,6 +12,7 @@ COPY initrd/init-initrd initrd/mount_disk.sh initrd/udhcpc_script.sh / COPY initrd/poweroff /sbin/poweroff COPY initrd/chroot2.c initrd/hacf.c /tmp/ COPY initrd/00000080 /etc/acpi/PWRF/ +COPY initrd/eve-enter-container /bin/ RUN gcc -s -o /chroot2 /tmp/chroot2.c RUN gcc -s -o /hacf /tmp/hacf.c RUN mkinitfs -n -F base -i /init-initrd -o /runx-initrd diff --git a/pkg/xen-tools/initrd/base.files b/pkg/xen-tools/initrd/base.files index 1d9c141e37..e812f44d03 100644 --- a/pkg/xen-tools/initrd/base.files +++ b/pkg/xen-tools/initrd/base.files @@ -1,4 +1,5 @@ /bin/busybox +/bin/eve-enter-container /sbin/agetty /sbin/mke2fs /lib/libext2fs.so.2* diff --git a/pkg/xen-tools/initrd/eve-enter-container b/pkg/xen-tools/initrd/eve-enter-container new file mode 100755 index 0000000000..952f3b6954 --- /dev/null +++ b/pkg/xen-tools/initrd/eve-enter-container @@ -0,0 +1,13 @@ +#!/bin/sh + +# PID of the started entrypoint container process. +# PID file is created from the `init-initrd` script. +PID_FILE="/mnt/entrypoint-pid" + +if [ ! -f "$PID_FILE" ]; then + echo "Error: PID file '$PID_FILE' not found. Container did not start?" + exit 1 +fi + +PID=$(cat "$PID_FILE") +nsenter -t "$PID" -m -u -i -n -p -r/mnt/rootfs -w/mnt/rootfs