arm-autonomy/xenguest-mkimage: fix DISK_DEVICE setting
PATCH 1/5 arm-autonomy/xenguest-mkimage: fix DISK_DEVICE setting
Previously '--disk-device' was set according to DISK_SIZE value, set with '--disk-size' option, which was not quite accurate, because disk device is more likely to be '/dev/sda2' rather than '1'. This patch also fixes typo in help message.
--- .../recipes-extended/xenguest/files/xenguest-mkimage | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-mkimage +2 -2
@@ -127,7 +127,7 @@ Disk configuration --disk-rm-part=ID remove partition ID from the guest disk --disk-add-file=SRC:DST add file SRC as disk file DST in the xenguest image. DST can then be used as a partition CONTENT. ---disk--rm-file=DST remove disk file DST from the xenguest image. +--disk-rm-file=DST remove disk file DST from the xenguest image. EOF }
@@ -746,7 +746,7 @@ for arg in "${@}"; do ${IMAGE_TMPDIR}/disk.cfg ;; --disk-device=*) - sed -i "s/DISK_DEVICE=.*/DISK_SIZE=\"${optarg}\"/" \ + sed -i "s@DISK_DEVICE=.*@DISK_DEVICE=\"${optarg}\"@" \ ${IMAGE_TMPDIR}/disk.cfg ;; --disk-add-part=*)
Signature · 1 line
2.17.1
PATCH 2/5 arm-autonomy/xenguest-tools: set guest disk and partition sizes in MB or GB
This patch brings following improvements:
* Allow user to set guest disk and partition sizes in MB or GB.
* Documentation update about this improvement.
Change-Id: I0a1a2945022efcd9d32bb39404b4a85721e28e19
Issue-Id: SCM-1515
--- .../classes/xenguest-image.bbclass | 39 ++++++------- .../documentation/xenguest-mkimage.md | 18 +++--- .../xenguest/files/xenguest-manager | 56 +++++++++++++++++-- .../xenguest/files/xenguest-mkimage | 48 +++++++++++++++- 4 files changed, 126 insertions(+), 35 deletions(-)
meta-arm-autonomy/classes/xenguest-image.bbclass +20 -19
@@ -44,13 +44,13 @@ XENGUEST_IMAGE_KERNEL ??= "Image" XENGUEST_IMAGE_DISK_SIZE ??= "${@ '4' if not d.getVar('INITRAMFS_IMAGE') else '0'}" # -# XENGUEST_IMAGE_DISK PARTITIONS is used to describe the partitions to setup +# XENGUEST_IMAGE_DISK_PARTITIONS is used to describe the partitions to setup # and their content. # It must be set to a space separated list of entries with each entry having -# the format num:sz:fs:[file] where: +# the format num:sz:[fs]:[file] where: # - num is a partition number -# - sz is the partition size in Gigabit -# - fs is the filesystem to use for the partition +# - sz is the partition size in MB or GB(default), e.g 1000M or 1[G] +# - fs is optional filesystem to use for the partition # - file is optionally pointing to a file to use as content of the partition # Please check image_types_xenguest.bbclass for rootfs handling of files #
@@ -129,21 +129,22 @@ xenguest_image_create() { # create disk if needed disksize="${XENGUEST_IMAGE_DISK_SIZE}" - if [ -z "$disksize" ]; then - disksize="0" - fi - if [ $disksize -gt 0 ]; then - # setup disk size - call_xenguest_mkimage update --disk-reset-config --disk-size=$disksize - - diskparts="${XENGUEST_IMAGE_DISK_PARTITIONS}" - if [ -n "$diskparts" ]; then - for arg in $diskparts; do - call_xenguest_mkimage update --disk-add-part=$arg - partnum="$(expr $partnum + 1)" - done - fi - fi + case ${disksize:=0} in + 0|0M|0G) + ;; + *) + # setup disk size + call_xenguest_mkimage update --disk-reset-config --disk-size=$disksize + + diskparts="${XENGUEST_IMAGE_DISK_PARTITIONS}" + if [ -n "$diskparts" ]; then + for arg in $diskparts; do + call_xenguest_mkimage update --disk-add-part=$arg + done + fi + ;; + esac + if [ "${XENGUEST_IMAGE_AUTOBOOT}" = "1" ]; then call_xenguest_mkimage update --set-param=GUEST_AUTOBOOT=1
meta-arm-autonomy/documentation/xenguest-mkimage.md +10 -8
@@ -58,12 +58,14 @@ order. ### disk.cfg and disk-files disk.cfg contains the guest disk description (disk size and disk partitions). The file contains the following entries: -- `DISK_SIZE=X`: size of the disk to create in GB +- `DISK_SIZE=X`: size of the disk to create in MB or GB(default), + e.g. 1000M or 4[G] - `DISK_PARTX=SIZE:FS:CONTENT`: create a partition number X (1 to 4) with a - size of SIZE GB, format it with filesystem FS (can be ext2, ext3, ext4, vfat - or swap) and extract CONTENT as initial partition content - (.tar[.gz|.xz|.bz2] file or img[.gz|.bz2] file to be dumped in the partition). FS and - CONTENT can be empty. + size of SIZE MB or GB(default), e.g 1000M or 2[G]. + Format it with filesystem FS (can be ext2, ext3, ext4, vfat or swap) + and extract CONTENT as initial partition content (.tar[.gz|.xz|.bz2] file + or img[.gz|.bz2] file to be dumped in the partition). + FS and CONTENT can be empty. The disk-files contain files to be used for initializing the disk partitions content. Those should be used to create a LVM or a physical disk and initialize
@@ -105,12 +107,12 @@ For a detailed help on available operations, please use: image file. Several script can be added and the basename of FILE is used to distinguish them (calling the option twice with the same file will update the script in the image with the second one). - --disk-size=SIZE: set the guest disk size to SIZE in GB. Calling this with 0 - disable the guest disk. + --disk-size=SIZE: set the guest disk size to SIZE in MB or GB(default), + e.g 1000M or 2[G]. Calling this with 0 disable the guest disk. - --disk-add-part=NUM:SIZE:FS:CONTENT: This is adding a partition to the xenguest image disk. The partition is described with the arguments: - NUM: partition number. - - SIZE: partition size in GB. + - SIZE: partition size in MB or GB(default), e.g 1000M or 2[G]. - FS: filesystem to format the partition with. This can be ext2, ext3, ext4, vfat of swap. If empty the partition is not formated. - CONTENT: tar of img file to use to initialize the partition. The file must
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-manager +50 -6
81 lines not on this page · raw message
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-mkimage +46 -2
66 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 3/5 arm-autonomy/xenguest-mkimage: check if partition fits disk size
In reply to Kamil DziezykCheck if partition defined with '--disk-add-part=*' will fit in disk size defined with '--disk-size=*'.
Change-Id: Ide87fe541d050497b4f2e5b5b47c1bcac8f5d37a
Issue-Id: SCM-1515
--- .../xenguest/files/xenguest-mkimage | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-mkimage +41 -1
@@ -412,13 +412,53 @@ check_size() { exit 1 } +disk_config_get_size() { + disksize=$(echo -e "$( . ${IMAGE_TMPDIR}/disk.cfg && echo $DISK_SIZE)") + check_size "${disksize}" +} + +disk_config_get_parts() { + echo -e "$( . ${IMAGE_TMPDIR}/disk.cfg && \ + typeset -p | awk '$3 ~ /^DISK_PART/ { print $3 }')" +} + +disk_config_get_free_space() { + disk_usage="0" + for partinfo in $(disk_config_get_parts) + do + partsize=$(echo "${partinfo}" | cut -d '"' -f2 | sed -e "s/:.*//") + sizeMB=$(check_size "${partsize}") + [ -n "${sizeMB}" ] || exit 1 + disk_usage=$((${sizeMB::${#sizeMB}-1} + $disk_usage)) + done + + disk_size=$(disk_config_get_size) + echo -e "$((${disk_size::${#disk_size}-1} - ${disk_usage}))M" +} + disk_config_add_part() { partconf="${1}" partid=$(echo ${partconf} | sed -e "s/:.*//") partinfo=$(echo ${partconf} | sed -e "s/[^:]*://") + partsize=$(echo ${partinfo} | cut -d ":" -f1) + + # check size "ID:*SIZE*:FORMAT:CONTENT" + partsizeMB=$(check_size "${partsize}") # Make sure we don't add the same partition twice - disk_config_rm_part ${partid} + disk_config_rm_part "${partid}" + + # check available disk space + freespace=$(disk_config_get_free_space) + if ((${partsizeMB::${#partsizeMB}-1} > ${freespace::${#freespace}-1})) + then + echo -e "Not enough free disk space(${freespace}) for partition "\ + "'${partconf}'!"\ + "\tTo adjust disk size use '--disk-size' parameter"\ + "\tor shrink the partition with '--disk-add-part' parameter" + exit 1 + fi + echo "DISK_PART${partid}=\"${partinfo}\"" >> \ ${IMAGE_TMPDIR}/disk.cfg }
Signature · 1 line
2.17.1
PATCH 4/5 arm-autonomy/xenguest-manager: keep user defined partition order
In reply to Kamil DziezykIf xenguest image does not define some partitions,
e.g second partition definition is skipped but 1st and 3rd are present, xenguest-manager will create second partition(with small 2MB size), to keep user defined partition order.
Change-Id: I8ff19fd9f25eb47ac37f80bec849387f6802aba3
Issue-Id: SCM-1515
--- .../xenguest/files/xenguest-manager | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-manager +22 -2
@@ -248,12 +248,32 @@ function xenguest_disk_init() # with a : separated list defining the partition: # DISK_PART3="4:ext4:disk.tgz" means that partition 3 should be 4G formated # with ext4 and initialized with the content of disk.tgz - for part in $(seq 1 4); do - eval partdesc="\${DISK_PART${part}:-0}" + # Keep user defined partition order, + # even if previous partitions are not defined. + # Create 2MB partitions in this case + lastpart="0" + for partidx in $(seq 1 4); do + local _part="DISK_PART${partidx}" + if [ -n "${!_part:=}" ]; then + lastpart="${partidx}" + fi + done + + if [ "${lastpart}" -eq "0" ]; then + # Nothing to be added here + # No partition definition found + return + fi + + for part in $(seq 1 "${lastpart}"); do + eval partdesc="\${DISK_PART${part}:=}" size=$(echo ${partdesc} | sed -e "s/\(.*\):.*:.*/\1/") fstype=$(echo ${partdesc} | sed -e "s/.*:\(.*\):.*/\1/") content=$(echo ${partdesc} | sed -e "s/.*:.*:\(.*\)/\1/") + local _part="DISK_PART${part}" + [ -n "${!_part:=}" ] || size="2M" + size=$(check_size "${size}") if [ -n "${size}" ] && [ "${size}" != "0M" ]; then # size has appended M or G suffix, let's extract just the value
Signature · 1 line
2.17.1
PATCH 5/5 arm-autonomy/xenguest-mkimage: improve xenguest image checks
In reply to Kamil DziezykThis patch brings following improvements:
* Adding the same partition content e.g rootfs.tar.gz, for multiple partitions is now not possible.
* Guest partition can contain only supported values of:
- format types: vfat|ext2|ext3|ext4|swap|(empty)
- image types: *.img.gz|*.img.bz2|*.img
*.tar.gz|*.tar.bz2|*.tar.xz|*.tarChange-Id: I0201e7ef51830ac43fc59656fc496fcc1d13b8d4
Issue-Id: SCM-1515
--- .../xenguest/files/xenguest-mkimage | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+)
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-mkimage +65 -0
@@ -436,11 +436,70 @@ disk_config_get_free_space() { echo -e "$((${disk_size::${#disk_size}-1} - ${disk_usage}))M" } +disk_check_partition_format() { + local partformat="${1}" + # if partformat is not defined let's skip this check + [ -n "${partformat}" ] || return 0 + + case "${partformat}" in + vfat|ext2|ext3|ext4|swap) + ;; + *) + # invalid/unknown fstype + echo "Invalid file fstype ${partformat}" + exit 1 + ;; + esac +} + +disk_check_partition_content() { + local partcontent="${1}" + # if partcontent is not defined let's skip this check + [ -n "${partcontent}" ] || return 0 + + case "${partcontent}" in + *.img*) + case "${partcontent}" in + *.img.gz|*.img.bz2|*.img) + ;; + *) + # invalid/unknown compression type + echo "Invalid file format in disk ${partcontent}" + exit 1 + ;; + esac + ;; + *.tar*) + case "${partcontent}" in + *.tar.gz|*.tar.bz2|*.tar.xz|*.tar) + ;; + *) + # invalid/unknown tar type + echo "Invalid file format in disk ${partcontent}" + exit 1 + ;; + esac + ;; + *) + #invalid content type + echo "Unsupported content type ${partcontent}!" + exit 1 + ;; + esac + # do not allow to create multiple partitions the same content + if grep ":${partcontent}\"" <<< "$(disk_config_get_parts)"; then + echo "Error ${partcontent} is already inside guest image" + exit 1 + fi +} + disk_config_add_part() { partconf="${1}" partid=$(echo ${partconf} | sed -e "s/:.*//") partinfo=$(echo ${partconf} | sed -e "s/[^:]*://") partsize=$(echo ${partinfo} | cut -d ":" -f1) + partformat=$(echo ${partinfo} | cut -d ":" -f2) + partcontent=$(echo ${partinfo} | cut -d ":" -f3) # check size "ID:*SIZE*:FORMAT:CONTENT" partsizeMB=$(check_size "${partsize}")
@@ -459,6 +518,12 @@ disk_config_add_part() { exit 1 fi + # check format "ID:SIZE:*FORMAT*:CONTENT" + disk_check_partition_format "${partformat}" + + # check content "ID:SIZE:FORMAT:*CONTENT*" + disk_check_partition_content "${partcontent}" + echo "DISK_PART${partid}=\"${partinfo}\"" >> \ ${IMAGE_TMPDIR}/disk.cfg }
Signature · 1 line
2.17.1