From a2f45232345c4e111651e3f809a3da8fd95f05bf Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Fri, 16 Apr 2021 12:40:36 -0700 Subject: Generate xl config files to create DomUs from Dom0 disk_image generates xl config files to start DomUs from Dom0. The files are added to dom0 rootfs partition under /etc/xen for your convenience. They refer to kernels and ramdisks stored on the first partition. It is recommended to mount the first partition under /boot in Dom0 to use them. Signed-off-by: Stefano Stabellini Reviewed-by: Brian Woods --- README.md | 9 +++++ scripts/disk_image | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/README.md b/README.md index 4adb9dc..14cfc8e 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,10 @@ Where: - DOMU_KERNEL[number] specifies the DomU kernel to use. +- DOMU_CMD[number] specifies the command line arguments for Dom0's Linux + kernel. If "root=" isn't set, imagebuilder will try to determine it. + If not set at all, the default one is used. + - DOMU_RAMDISK[number] specifies the DomU ramdisk to use. - DOMU_PASSTHROUGH_DTB[number] specifies the device assignment @@ -145,3 +149,8 @@ Where:\ "scsi" are shorthands for "tftpb", "load mmc 0:1" and "load scsi 0:1", but actually any arbitrary command can be used, for instance -t "fatload" is valid. + + +disk_image also generates on the fly a xl config file for each domU and +adds them to the dom0 rootfs partition under /etc/xen. It makes it +easier to start those domUs from dom0. diff --git a/scripts/disk_image b/scripts/disk_image index eeb888f..8bc1312 100755 --- a/scripts/disk_image +++ b/scripts/disk_image @@ -17,6 +17,92 @@ function check_depends() done } +function add_rootfs() +{ + local dev=${LOAD_CMD%:*} + dev=${dev##* } + local par=${LOAD_CMD#*:} + local j=$1 + + if [ -z "$dev" ] || [ -z "$par" ] + then + echo "Could not parse device and partition." + exit 1 + fi + + par=$(( $par + $j )) + + if [[ $LOAD_CMD =~ mmc ]] + then + retval="/dev/mmcblk${dev}p${par}" + elif [[ $LOAD_CMD =~ scsi ]] + then + # converts number to a scsi device character + dev=$((dev + 97)) + dev=$(printf %x $dev) + dev=$(printf "\x$dev") + + retval="/dev/sd${dev}${par}" + else + echo "Only mmc and scsi are supported for automatically setting the root partition." + echo "Manually set DOM0_CMD with the root device in the config file to bypass this." + exit 1 + fi +} + +function generate_domU_configs() +{ + local i=0 + local j=$1 + # $j + 1 - 1 as it is starting from 0 + local n=$1 + local dest + + mount -t ext4 /dev/mapper/diskimage$j $DESTDIR/part/disk$j + mkdir -p $DESTDIR/part/disk$j/etc/xen + add_rootfs 0 + first_part=$retval + + while test $i -lt $NUM_DOMUS + do + dest="$DESTDIR/part/disk$j/etc/xen/domU$i.cfg" + echo "name=\"domU$i\"" >> $dest + echo "memory=${DOMU_MEM[$i]}" >> $dest + echo "vcpus=${DOMU_VCPUS[$i]}" >> $dest + echo "# mount $first_part /boot" >> $dest + echo "kernel=\"/boot/${DOMU_KERNEL[$i]}\"" >> $dest + if test "${DOMU_RAMDISK[$i]}" + then + echo "ramdisk=\"/boot/${DOMU_RAMDISK[$i]}\"" >> $dest + fi + + if [ -z "${DOMU_CMD[$i]}" ] + then + DOMU_CMD[$i]="console=hvc0" + fi + if [[ ! ${DOMU_CMD[$i]} =~ root= ]] + then + if test -z "${DOMU_ROOTFS[$i]}" + then + DOMU_CMD[$i]="${DOMU_CMD[$i]} root=/dev/ram0" >> $dest + else + DOMU_CMD[$i]="${DOMU_CMD[$i]} root=/dev/xvda" >> $dest + fi + fi + echo "extra=\"${DOMU_CMD[$i]}\"" >> $dest + if test "${DOMU_ROOTFS[$i]}" + then + add_rootfs $n + echo "disk=[\"$retval,,xvda\"]" >> $dest + fi + + n=$(( $n + 1 )) + i=$(( $i + 1 )) + done + + umount $DESTDIR/part/disk$j +} + function add_partition() { local rootfs="$1" @@ -157,6 +243,20 @@ check_depends source "$CFG_FILE" +i=0 +while test $i -lt $NUM_DOMUS +do + if test -z "${DOMU_MEM[$i]}" + then + DOMU_MEM[$i]=512 + fi + if test -z "${DOMU_VCPUS[$i]}" + then + DOMU_VCPUS[$i]=1 + fi + i=$(( $i + 1 )) +done + offset=$((2*1024*1024)) _part1_size=`stat -L --printf="%s" $UBOOT_OUT/$XEN` _part1_size=$(( $_part1_size + `stat -L --printf="%s" $UBOOT_OUT/$DOM0_KERNEL` )) @@ -294,6 +394,7 @@ j=2 if test "$DOM0_ROOTFS" then write_rootfs 2 "$DOM0_ROOTFS" + generate_domU_configs 2 j=$(( $j + 1 )) fi -- cgit v1.2.3