aboutsummaryrefslogtreecommitdiff
path: root/scripts/disk_image
diff options
context:
space:
mode:
authorStefano Stabellini2021-04-16 12:40:36 -0700
committerStefano Stabellini2021-05-17 14:50:56 -0700
commita2f45232345c4e111651e3f809a3da8fd95f05bf (patch)
treec97b58263d349afc28fd300e554a9eaa3573739f /scripts/disk_image
parenta2b5ba41fed282f50b34f80e72e1a3d6c8ee3b4d (diff)
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 <stefano.stabellini@xilinx.com> Reviewed-by: Brian Woods <brian.woods@xilinx.com>
Diffstat (limited to 'scripts/disk_image')
-rwxr-xr-xscripts/disk_image101
1 files changed, 101 insertions, 0 deletions
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