runqemu: support full-disk images

This makes it possible to boot images with multiple partitions (the
ones ending in .hddimg or .hdddirect) in several ways:
   runqemu qemux86 core-image-minimal hddimg
   runqemu tmp/deploy/images/qemux86/core-image-minimal-qemux86.hddimg
   VM=tmp-glibc/deploy/images/qemux86/iot-os-image-qemux86.hddimg FSTYPE=hddimg runqemu

Same for hdddirect.

This is useful for testing initramfs scripts, secure boot (when
switching to UEFI), or boot loaders like syslinux. For testing the
content of the rootfs, the ext4 image is better because that approach
is faster (no need to create another large image during build, rootfs
can be read directly instead of reading boot.img through loop device).

When booting a live image, the kernel, initramfs (if any) and kernel
parameters are taken from the image by the virtual machine's BIOS, so any
additional kernel parameters given to runqemu are ignored. This can be
avoided (already without this change) in a slightly hacky runqemu setup:
   ROOTFS=tmp/deploy/images/qemux86/core-image-minimal-qemux86.hddimg \
   FSTYPE=ext4 \
   KERNEL=tmp/deploy/images/qemux86/bzImage-initramfs-qemux86.bin \
   MACHINE=qemux86 \
   runqemu serial kvm nographic 'bootparams=root=/dev/ram0'

The additional bzImage-initramfs-qemux86.bin kernel here was created
by adding this to local.conf:
   INITRAMFS_IMAGE = "core-image-minimal-initramfs"
   INITRAMFS_IMAGE_BUNDLE = "1"

In the code, the new FSTYPE=hddimg resp. hdddirect behaves almost
exactly like the older vmdk FSTYPE. New types were chosen because it
seemed cleaner than using FSTYPE=vmdk when the actual image pointed to
by VM is not in that format. The downside is that several checks for
FSTYPE=vmdk had to be duplicated for FSTYPE=hddimg.

The VM variable now gets interpreted as "virtual machine disk image"
instead of "vmdk image".

(From OE-Core rev: 37741c539f5d3021e59828b49e968cd42b89a368)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Patrick Ohly
2015-09-03 20:42:26 +02:00
committed by Richard Purdie
parent 9337ce26f4
commit 8215c42af1
2 changed files with 19 additions and 15 deletions

View File

@@ -28,7 +28,7 @@ usage() {
echo " MACHINE - the machine name (optional, autodetected from KERNEL filename if unspecified)" echo " MACHINE - the machine name (optional, autodetected from KERNEL filename if unspecified)"
echo " RAMFS - boot a ramfs-based image" echo " RAMFS - boot a ramfs-based image"
echo " ISO - boot an ISO image" echo " ISO - boot an ISO image"
echo " VM - boot a vmdk image" echo " VM - boot a virtual machine image (= a file representing a full disk with boot loader)"
echo " Simplified QEMU command-line options can be passed with:" echo " Simplified QEMU command-line options can be passed with:"
echo " nographic - disables video console" echo " nographic - disables video console"
echo " serial - enables a serial console on /dev/ttyS0" echo " serial - enables a serial console on /dev/ttyS0"
@@ -94,7 +94,7 @@ process_filename() {
error "conflicting FSTYPE types [$FSTYPE] and [$EXT]" error "conflicting FSTYPE types [$FSTYPE] and [$EXT]"
fi fi
;; ;;
/vmdk/) /hddimg/|/hdddirect/|/vmdk/)
FSTYPE=$EXT FSTYPE=$EXT
VM=$filename VM=$filename
;; ;;
@@ -114,7 +114,7 @@ while true; do
[ -z "$MACHINE" ] && MACHINE=$arg || \ [ -z "$MACHINE" ] && MACHINE=$arg || \
error "conflicting MACHINE types [$MACHINE] and [$arg]" error "conflicting MACHINE types [$MACHINE] and [$arg]"
;; ;;
"ext2" | "ext3" | "ext4" | "jffs2" | "nfs" | "btrfs") "ext2" | "ext3" | "ext4" | "jffs2" | "nfs" | "btrfs" | "hddimg" | "hdddirect" )
[ -z "$FSTYPE" -o "$FSTYPE" = "$arg" ] && FSTYPE=$arg || \ [ -z "$FSTYPE" -o "$FSTYPE" = "$arg" ] && FSTYPE=$arg || \
error "conflicting FSTYPE types [$FSTYPE] and [$arg]" error "conflicting FSTYPE types [$FSTYPE] and [$arg]"
;; ;;
@@ -235,12 +235,12 @@ if [ "$FSTYPE" = "nfs" -a -z "$ROOTFS" ]; then
fi fi
if [ -z "$MACHINE" ]; then if [ -z "$MACHINE" ]; then
if [ "x$FSTYPE" = "xvmdk" ]; then if [ "x$FSTYPE" = "xvmdk" ] || [ "x$FSTYPE" = "xhddimg" ] || [ "x$FSTYPE" = "xhdddirect" ]; then
MACHINE=`basename $VM | sed -n 's/.*\(qemux86-64\|qemux86\|qemuarm64\|qemuarm\|qemumips64\|qemumips\|qemuppc\|qemush4\).*/\1/p'` MACHINE=`basename $VM | sed -n 's/.*\(qemux86-64\|qemux86\|qemuarm64\|qemuarm\|qemumips64\|qemumips\|qemuppc\|qemush4\).*/\1/p'`
if [ -z "$MACHINE" ]; then if [ -z "$MACHINE" ]; then
error "Unable to set MACHINE from vmdk filename [$VM]" error "Unable to set MACHINE from image filename [$VM]"
fi fi
echo "Set MACHINE to [$MACHINE] based on vmdk [$VM]" echo "Set MACHINE to [$MACHINE] based on image [$VM]"
else else
MACHINE=`basename $KERNEL | sed -n 's/.*\(qemux86-64\|qemux86\|qemuarm64\|qemuarm\|qemumips64\|qemumips\|qemuppc\|qemush4\).*/\1/p'` MACHINE=`basename $KERNEL | sed -n 's/.*\(qemux86-64\|qemux86\|qemuarm64\|qemuarm\|qemumips64\|qemumips\|qemuppc\|qemush4\).*/\1/p'`
if [ -z "$MACHINE" ]; then if [ -z "$MACHINE" ]; then
@@ -436,7 +436,7 @@ if [ -e "$ROOTFS" -a -z "$FSTYPE" ]; then
fi fi
fi fi
if [ -z "$KERNEL" -a "x$FSTYPE" != "xvmdk" ]; then if [ -z "$KERNEL" -a "x$FSTYPE" != "xvmdk" -a "x$FSTYPE" != "xhddimg" -a "x$FSTYPE" != "xhdddirect" ]; then
setup_path_vars 1 setup_path_vars 1
eval kernel_file=\$${machine2}_DEFAULT_KERNEL eval kernel_file=\$${machine2}_DEFAULT_KERNEL
KERNEL=$DEPLOY_DIR_IMAGE/$kernel_file KERNEL=$DEPLOY_DIR_IMAGE/$kernel_file
@@ -462,10 +462,14 @@ fi
if [ "$LAZY_ROOTFS" = "true" ]; then if [ "$LAZY_ROOTFS" = "true" ]; then
setup_path_vars 1 setup_path_vars 1
echo "Assuming $ROOTFS really means $DEPLOY_DIR_IMAGE/$ROOTFS-$MACHINE.$FSTYPE" echo "Assuming $ROOTFS really means $DEPLOY_DIR_IMAGE/$ROOTFS-$MACHINE.$FSTYPE"
ROOTFS=$DEPLOY_DIR_IMAGE/$ROOTFS-$MACHINE.$FSTYPE if [ "$FSTYPE" = "hddimg" -o "x$FSTYPE" = "xhdddirect" ]; then
VM=$DEPLOY_DIR_IMAGE/$ROOTFS-$MACHINE.$FSTYPE
else
ROOTFS=$DEPLOY_DIR_IMAGE/$ROOTFS-$MACHINE.$FSTYPE
fi
fi fi
if [ -z "$ROOTFS" -a "x$FSTYPE" != "xvmdk" ]; then if [ -z "$ROOTFS" -a "x$FSTYPE" != "xvmdk" -a "x$FSTYPE" != "xhddimg" -a "x$FSTYPE" != "xhdddirect" ]; then
setup_path_vars 1 setup_path_vars 1
T=$DEPLOY_DIR_IMAGE T=$DEPLOY_DIR_IMAGE
eval rootfs_list=\$${machine2}_DEFAULT_ROOTFS eval rootfs_list=\$${machine2}_DEFAULT_ROOTFS
@@ -481,7 +485,7 @@ ROOTFS=`readlink -f $ROOTFS`
echo "" echo ""
echo "Continuing with the following parameters:" echo "Continuing with the following parameters:"
if [ "x$FSTYPE" != "xvmdk" ]; then if [ "x$FSTYPE" != "xvmdk" -a "x$FSTYPE" != "xhddimg" -a "x$FSTYPE" != "xhdddirect" ]; then
echo "KERNEL: [$KERNEL]" echo "KERNEL: [$KERNEL]"
echo "ROOTFS: [$ROOTFS]" echo "ROOTFS: [$ROOTFS]"
else else

View File

@@ -315,13 +315,13 @@ case "$MACHINE" in
;; ;;
esac esac
if [ ! -f "$KERNEL" -a "x$FSTYPE" != "xvmdk" ]; then if [ ! -f "$KERNEL" -a "x$FSTYPE" != "xvmdk" -a "x$FSTYPE" != "xhddimg" -a "x$FSTYPE" != "xhdddirect" ]; then
echo "Error: Kernel image file $KERNEL doesn't exist" echo "Error: Kernel image file $KERNEL doesn't exist"
cleanup cleanup
return 1 return 1
fi fi
if [ "$FSTYPE" != "nfs" -a "$FSTYPE" != "vmdk" -a ! -f "$ROOTFS" ]; then if [ "$FSTYPE" != "nfs" -a "$FSTYPE" != "vmdk" -a "$FSTYPE" != "hddimg" -a "$FSTYPE" != "hdddirect" -a ! -f "$ROOTFS" ]; then
echo "Error: Image file $ROOTFS doesn't exist" echo "Error: Image file $ROOTFS doesn't exist"
cleanup cleanup
return 1 return 1
@@ -440,7 +440,7 @@ if [ "$MACHINE" = "qemux86" ]; then
KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS"
fi fi
if [ "$FSTYPE" = "vmdk" ]; then if [ "$FSTYPE" = "vmdk" -o "$FSTYPE" = "hddimg" -o "$FSTYPE" = "hdddirect" ]; then
QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS"
fi fi
# Currently oprofile's event based interrupt mode doesn't work(Bug #828) in # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in
@@ -476,7 +476,7 @@ if [ "$MACHINE" = "qemux86-64" ]; then
KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE $QEMU_UI_OPTIONS" QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE $QEMU_UI_OPTIONS"
fi fi
if [ "$FSTYPE" = "vmdk" ]; then if [ "$FSTYPE" = "vmdk" -o "$FSTYPE" = "hddimg" -o "$FSTYPE" = "hdddirect" ]; then
QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE $QEMU_UI_OPTIONS" QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE $QEMU_UI_OPTIONS"
fi fi
# Currently oprofile's event based interrupt mode doesn't work(Bug #828) in # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in
@@ -702,7 +702,7 @@ fi
echo "Running $QEMU..." echo "Running $QEMU..."
# -no-reboot is a mandatory option - see bug #100 # -no-reboot is a mandatory option - see bug #100
if [ "$FSTYPE" = "vmdk" ]; then if [ "$FSTYPE" = "vmdk" -o "$FSTYPE" = "hddimg" -o "$FSTYPE" = "hdddirect" ]; then
echo $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT echo $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT
LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT
elif [ "$FSTYPE" = "iso" ]; then elif [ "$FSTYPE" = "iso" ]; then