diff --git a/diskimage_builder/lib/disk-image-create b/diskimage_builder/lib/disk-image-create index c90dcedb..cfd7cf40 100644 --- a/diskimage_builder/lib/disk-image-create +++ b/diskimage_builder/lib/disk-image-create @@ -62,6 +62,7 @@ function show_options () { echo " --logfile -- save run output to given logfile (implies DIB_QUIET=1)" echo " --checksum -- generate MD5 and SHA256 checksum files for the created image" echo " --image-size size -- image size in GB for the created image" + echo " --image-extra-size size -- extra image size in GB for the created image" echo " --image-cache directory -- location for cached images(default ~/.cache/image-create)" echo " --max-online-resize size -- max number of filesystem blocks to support when resizing." echo " Useful if you want a really large root partition when the image is deployed." @@ -148,6 +149,7 @@ while true ; do -p) IFS="," read -a _INSTALL_PACKAGES <<< "$2"; export INSTALL_PACKAGES=( ${INSTALL_PACKAGES[@]} ${_INSTALL_PACKAGES[@]} ) ; shift 2 ;; --checksum) shift; export DIB_CHECKSUM=1;; --image-size) export DIB_IMAGE_SIZE=$2; shift 2;; + --image-extra-size) export DIB_IMAGE_EXTRA_SIZE=$2; shift 2;; --image-cache) export DIB_IMAGE_CACHE=$2; shift 2;; --max-online-resize) export MAX_ONLINE_RESIZE=$2; shift 2;; --mkfs-journal-size) export DIB_JOURNAL_SIZE=$2; shift 2;; @@ -378,8 +380,15 @@ else echo "Calculating image size (this may take a minute)..." sudo du -a -c -x ${TMP_BUILD_DIR}/built > ${du_output} # the last line is the total size from "-c". - # scale this by 0.6 to create a slightly bigger image - du_size=$(tail -n1 ${du_output} | cut -f1 | awk '{print int($1 / 0.6)}') + if [ -n "$DIB_IMAGE_EXTRA_SIZE" ]; then + # add DIB_IMAGE_EXTRA_SIZE to create a bigger image as requested + du_extra_size=$(echo "$DIB_IMAGE_EXTRA_SIZE" | awk '{printf("%d\n",$1 * 1024 *1024)}') + du_size_tmp=$(tail -n1 ${du_output} | cut -f1) + du_size=$(echo "$du_size_tmp $du_extra_size" | awk '{print int($1 + $2)}') + else + # scale this by 0.6 to create a slightly bigger image + du_size=$(tail -n1 ${du_output} | cut -f1 | awk '{print int($1 / 0.6)}') + fi $xtrace fi diff --git a/doc/source/user_guide/building_an_image.rst b/doc/source/user_guide/building_an_image.rst index 299cd953..b724e1b2 100644 --- a/doc/source/user_guide/building_an_image.rst +++ b/doc/source/user_guide/building_an_image.rst @@ -617,7 +617,7 @@ more complicated block-device layouts with multiple partitions, you may need to take into account the special behaviour described below. The ``local_loop`` module will take it's default size from the -following argument. +following arguments: ``--image-size`` The size of loopback device which the image will be generated in, @@ -625,6 +625,11 @@ following argument. from the on-disk size of the image and then scaled up by a fixed 60% factor. Can also set ``DIB_IMAGE_SIZE``. +``--image-extra-size`` + Extra space to add when automatically calculating image size, in + gigabytes. This overrides the default 60% scale up as described + above for ``--image-size``. Can also set ``DIB_IMAGE_EXTRA_SIZE``. + The special node named ``mkfs_root`` is affected by the following; this reflects that the standard layout has only a single root partition so the options are, in effect, global for the default diff --git a/releasenotes/notes/image-size-padding-24f88d1c4a215221.yaml b/releasenotes/notes/image-size-padding-24f88d1c4a215221.yaml new file mode 100644 index 00000000..e5e284f1 --- /dev/null +++ b/releasenotes/notes/image-size-padding-24f88d1c4a215221.yaml @@ -0,0 +1,4 @@ +--- +features: + - The ``--image-extra-size`` option is provided to override the default + 60% padding growth of the image size with a fixed gigabyte value.