From bfddad6582f4123023bb74d43f4cc7e3d68c16a9 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 15 Jan 2023 13:03:31 +0100 Subject: Support kernel links in /boot (Ubuntu) --- bin/debvm-run | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/debvm-run b/bin/debvm-run index 6ed47c4..1b59158 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -195,8 +195,12 @@ case "$VMARCH" in ;; esac -KERNELNAME=$(/sbin/debugfs "$IMAGE" -R "stat $KERNELLINK" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') -INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat initrd.img" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') +KERNELPREFIX="" +KERNELNAME=$(/sbin/debugfs "$IMAGE" -R "stat $KERNELLINK") +test -n "$KERNELNAME" || KERNELPREFIX=boot/ + +KERNELNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${KERNELPREFIX}$KERNELLINK" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') +INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${KERNELPREFIX}initrd.img" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') test -n "$KERNELNAME" || die "failed to discover kernel image" test -n "$INITRDNAME" || die "failed to discover initrd image" @@ -286,7 +290,7 @@ set -- \ set -ex -/sbin/debugfs "$IMAGE" -R "cat $KERNELNAME" > "$KERNELTMP" -/sbin/debugfs "$IMAGE" -R "cat $INITRDNAME" > "$INITRDTMP" +/sbin/debugfs "$IMAGE" -R "cat ${KERNELPREFIX}$KERNELNAME" > "$KERNELTMP" +/sbin/debugfs "$IMAGE" -R "cat ${KERNELPREFIX}$INITRDNAME" > "$INITRDTMP" "$QEMU" "$@" -- cgit v1.2.3 From 37893004236be9c9885cec066e16c23b122d2ad1 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 15 Jan 2023 18:16:34 +0100 Subject: Avoid unnecessary debugfs call Reported-by: Helmut Grohne --- bin/debvm-run | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/debvm-run b/bin/debvm-run index 1b59158..5740a02 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -196,10 +196,13 @@ case "$VMARCH" in esac KERNELPREFIX="" -KERNELNAME=$(/sbin/debugfs "$IMAGE" -R "stat $KERNELLINK") -test -n "$KERNELNAME" || KERNELPREFIX=boot/ +KERNELLINKFILE=$(/sbin/debugfs "$IMAGE" -R "stat $KERNELLINK") +if test -z "$KERNELLINKFILE"; then + KERNELPREFIX=boot/ + KERNELLINKFILE=$(/sbin/debugfs "$IMAGE" -R "stat ${KERNELPREFIX}$KERNELLINK") +fi -KERNELNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${KERNELPREFIX}$KERNELLINK" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') +KERNELNAME=$(echo "$KERNELLINKFILE" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${KERNELPREFIX}initrd.img" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') test -n "$KERNELNAME" || die "failed to discover kernel image" -- cgit v1.2.3 From 0a6efea4c00b83fc1d899c0dc868f05308edd26d Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 15 Jan 2023 18:20:51 +0100 Subject: Document additional kernel link names Reported-by: Helmut Grohne --- README.md | 2 +- bin/debvm-run | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/README.md b/README.md index 6f042d7..870e26d 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ contains the root filesystem of a (Debian) installation including an init system and a kernel. There is no partition table or bootloader. The following paths are assumed inside: * `/bin/true` is used to detect the architecture of an image - * `/vmlinuz` or `/vmlinux` (depending on the architecture) must be a symbolic + * `(|/boot)/vmlinu[xz]` (depending on the architecture) must be a symbolic link pointing to a regular file containing the kernel. * `/initrd.img` must be a symbolic link pointing to a regular file containing the initrd image. diff --git a/bin/debvm-run b/bin/debvm-run index 5740a02..65eb65c 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -16,7 +16,7 @@ B [B<-g>] [B<-i> F] [B<-s> I] [B<--> I] B is essentially a thin wrapper around B for running a virtual machine image created by B or something compatible. The virtual machine image is expected to be a raw ext4 image with file system label B. The architecture of the machine is detected from the contained F. -It must contain a symbolic link pointing to a kernel image at F or F depending on the architecture and a symbolic link pointing to an initrd image at F. +It must contain a symbolic link pointing to a kernel image at F<(|/boot)/vmlinu[xz]> depending on the architecture and a symbolic link pointing to an initrd image at F. Both are extracted and passed to B. A net interface configured for user mode is added automatically. -- cgit v1.2.3 From f48cc92c8c187b92e8072a10a256695879e3bd43 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 15 Jan 2023 19:46:58 +0100 Subject: debvm-run: guess the location of the kernel --- README.md | 8 ++++---- bin/debvm-run | 36 +++++++++++++++--------------------- 2 files changed, 19 insertions(+), 25 deletions(-) (limited to 'bin') diff --git a/README.md b/README.md index 870e26d..ec1fcb3 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,10 @@ contains the root filesystem of a (Debian) installation including an init system and a kernel. There is no partition table or bootloader. The following paths are assumed inside: * `/bin/true` is used to detect the architecture of an image - * `(|/boot)/vmlinu[xz]` (depending on the architecture) must be a symbolic - link pointing to a regular file containing the kernel. - * `/initrd.img` must be a symbolic link pointing to a regular file containing - the initrd image. + * `(|/boot)/vmlinu[xz]` must be a symbolic link pointing to a regular file + containing the kernel. + * `initrd.img` must be a symbolic link in the same directory as the kernel + image pointing to a regular file containing the initrd image. Why? ==== diff --git a/bin/debvm-run b/bin/debvm-run index 65eb65c..39928d2 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -16,7 +16,7 @@ B [B<-g>] [B<-i> F] [B<-s> I] [B<--> I] B is essentially a thin wrapper around B for running a virtual machine image created by B or something compatible. The virtual machine image is expected to be a raw ext4 image with file system label B. The architecture of the machine is detected from the contained F. -It must contain a symbolic link pointing to a kernel image at F<(|/boot)/vmlinu[xz]> depending on the architecture and a symbolic link pointing to an initrd image at F. +It must contain a symbolic link pointing to a kernel image at one of F<(|/boot)/vmlinu[xz]> a symbolic link pointing to an initrd image at F in the same directory as the kernel image. Both are extracted and passed to B. A net interface configured for user mode is added automatically. @@ -186,26 +186,20 @@ if command -v elf-arch >/dev/null 2>&1; then /sbin/debugfs "$IMAGE" -R "cat /bin/true" > "$KERNELTMP" VMARCH=$(elf-arch "$KERNELTMP") fi -case "$VMARCH" in - mips*|ppc64el) - KERNELLINK=vmlinux - ;; - *) - KERNELLINK=vmlinuz - ;; -esac - -KERNELPREFIX="" -KERNELLINKFILE=$(/sbin/debugfs "$IMAGE" -R "stat $KERNELLINK") -if test -z "$KERNELLINKFILE"; then - KERNELPREFIX=boot/ - KERNELLINKFILE=$(/sbin/debugfs "$IMAGE" -R "stat ${KERNELPREFIX}$KERNELLINK") -fi - -KERNELNAME=$(echo "$KERNELLINKFILE" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') -INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${KERNELPREFIX}initrd.img" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') +for KERNELLINK in vmlinuz vmlinux boot/vmlinuz boot/vmlinux; do + KERNELNAME=$(/sbin/debugfs "$IMAGE" -R "stat $KERNELLINK" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') + test -n "$KERNELNAME" && break +done test -n "$KERNELNAME" || die "failed to discover kernel image" + +if test "${KERNELLINK#boot/}" = "$KERNELLINK"; then + INITRDLINK=initrd.img +else + INITRDLINK=boot/initrd.img +fi +INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat $INITRDLINK" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') + test -n "$INITRDNAME" || die "failed to discover initrd image" KERNEL_CMDLINE="root=LABEL=debvm rw" @@ -293,7 +287,7 @@ set -- \ set -ex -/sbin/debugfs "$IMAGE" -R "cat ${KERNELPREFIX}$KERNELNAME" > "$KERNELTMP" -/sbin/debugfs "$IMAGE" -R "cat ${KERNELPREFIX}$INITRDNAME" > "$INITRDTMP" +/sbin/debugfs "$IMAGE" -R "cat $KERNELNAME" > "$KERNELTMP" +/sbin/debugfs "$IMAGE" -R "cat $INITRDNAME" > "$INITRDTMP" "$QEMU" "$@" -- cgit v1.2.3 From f9d8f3551a47535c1e30afb28c42c8d6034ba59b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 15 Jan 2023 20:56:50 +0100 Subject: debvm-run: fix for relative symlinks below boot/ Reported-by: Jochen Sprickerhof --- bin/debvm-run | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'bin') diff --git a/bin/debvm-run b/bin/debvm-run index 39928d2..ee94003 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -191,16 +191,17 @@ for KERNELLINK in vmlinuz vmlinux boot/vmlinuz boot/vmlinux; do KERNELNAME=$(/sbin/debugfs "$IMAGE" -R "stat $KERNELLINK" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') test -n "$KERNELNAME" && break done -test -n "$KERNELNAME" || die "failed to discover kernel image" - -if test "${KERNELLINK#boot/}" = "$KERNELLINK"; then - INITRDLINK=initrd.img +if test "${KERNELLINK%/*}" = "$KERNELLINK"; then + BOOTDIR= else - INITRDLINK=boot/initrd.img + BOOTDIR="${KERNELLINK%/*}/" fi -INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat $INITRDLINK" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') +test -n "$KERNELNAME" || die "failed to discover kernel image" +test "${KERNELNAME#/}" = "$KERNELNAME" || KERNELNAME="$BOOTDIR$KERNELNAME" +INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${BOOTDIR}initrd.img" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') test -n "$INITRDNAME" || die "failed to discover initrd image" +test "${INITRDNAME#/}" = "$INITRDNAME" || INITRDNAME="$BOOTDIR$INITRDNAME" KERNEL_CMDLINE="root=LABEL=debvm rw" NETDEV="user,id=net0" -- cgit v1.2.3 From 4f085d1e4bad9990671fb5d953c9aba2c9b51902 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 15 Jan 2023 21:09:21 +0100 Subject: debvm-run: fix logic inversion in parent commit Reported-by: Jochen Sprickerhof --- bin/debvm-run | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/debvm-run b/bin/debvm-run index ee94003..e36ea60 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -197,11 +197,11 @@ else BOOTDIR="${KERNELLINK%/*}/" fi test -n "$KERNELNAME" || die "failed to discover kernel image" -test "${KERNELNAME#/}" = "$KERNELNAME" || KERNELNAME="$BOOTDIR$KERNELNAME" +test "${KERNELNAME#/}" = "$KERNELNAME" && KERNELNAME="$BOOTDIR$KERNELNAME" INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${BOOTDIR}initrd.img" | sed 's/Fast link dest: "\(.*\)"/\1/;t;d') test -n "$INITRDNAME" || die "failed to discover initrd image" -test "${INITRDNAME#/}" = "$INITRDNAME" || INITRDNAME="$BOOTDIR$INITRDNAME" +test "${INITRDNAME#/}" = "$INITRDNAME" && INITRDNAME="$BOOTDIR$INITRDNAME" KERNEL_CMDLINE="root=LABEL=debvm rw" NETDEV="user,id=net0" -- cgit v1.2.3