Zerofree the image if possible
If the image has an ext filesystem and the zerofree utility is present on the build system then run zerofree. This should make images as compressable as possible which is a nice feature when building compressed qcow2 images. Change-Id: Ia6062c291f7a3f58b85a4f408ecb3d0574c65d53
This commit is contained in:
parent
6e29b45d90
commit
5184d02a7c
@ -335,7 +335,9 @@ if [ -n "$MAX_ONLINE_RESIZE" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
LOOPDEV=$(sudo losetup --show -f $TMP_IMAGE_PATH)
|
LOOPDEV=$(sudo losetup --show -f $TMP_IMAGE_PATH)
|
||||||
export EXTRA_UNMOUNT="detach_loopback $LOOPDEV"
|
# Definied here for backward compat against set -u
|
||||||
|
export EXTRA_UNMOUNT=""
|
||||||
|
export EXTRA_CLEANUP="detach_loopback $LOOPDEV"
|
||||||
export IMAGE_BLOCK_DEVICE=$LOOPDEV
|
export IMAGE_BLOCK_DEVICE=$LOOPDEV
|
||||||
eval_run_d block-device "IMAGE_BLOCK_DEVICE="
|
eval_run_d block-device "IMAGE_BLOCK_DEVICE="
|
||||||
sudo mkfs $MKFS_OPTS -t $FS_TYPE -L ${DIB_ROOT_LABEL} ${IMAGE_BLOCK_DEVICE}
|
sudo mkfs $MKFS_OPTS -t $FS_TYPE -L ${DIB_ROOT_LABEL} ${IMAGE_BLOCK_DEVICE}
|
||||||
@ -382,6 +384,13 @@ done
|
|||||||
unmount_image
|
unmount_image
|
||||||
cleanup_build_dir
|
cleanup_build_dir
|
||||||
|
|
||||||
|
# Write zeros to free blocks to aid compression of images.
|
||||||
|
if echo "$FS_TYPE" | grep -q "^ext" && which zerofree ; then
|
||||||
|
sudo zerofree $IMAGE_BLOCK_DEVICE
|
||||||
|
fi
|
||||||
|
# We are done with the loopback device make sure it is detached.
|
||||||
|
$EXTRA_CLEANUP
|
||||||
|
|
||||||
has_raw_type=
|
has_raw_type=
|
||||||
if [ "$IS_RAMDISK" == "0" ]; then
|
if [ "$IS_RAMDISK" == "0" ]; then
|
||||||
for IMAGE_TYPE in ${IMAGE_TYPES[@]} ; do
|
for IMAGE_TYPE in ${IMAGE_TYPES[@]} ; do
|
||||||
|
@ -27,6 +27,11 @@ It is recommended you check the documentation for each element you are using
|
|||||||
to determine if there are any additional dependencies. Of particular note is
|
to determine if there are any additional dependencies. Of particular note is
|
||||||
the need for the `dev-python/pyyaml` package on Gentoo hosts.
|
the need for the `dev-python/pyyaml` package on Gentoo hosts.
|
||||||
|
|
||||||
|
If the zerofree utility is present on the build system and you are building
|
||||||
|
an image with an ext filesystem zerofree will be used to zero out free
|
||||||
|
blocks in the image. This makes the resulting images much smaller if
|
||||||
|
compressed.
|
||||||
|
|
||||||
|
|
||||||
Source Installation
|
Source Installation
|
||||||
-------------------
|
-------------------
|
||||||
|
@ -24,6 +24,8 @@ function unmount_image () {
|
|||||||
# unmount from the chroot
|
# unmount from the chroot
|
||||||
# Don't use TMP_MOUNT_PATH here, it might not have been set.
|
# Don't use TMP_MOUNT_PATH here, it might not have been set.
|
||||||
unmount_dir "$TMP_BUILD_DIR/mnt"
|
unmount_dir "$TMP_BUILD_DIR/mnt"
|
||||||
|
|
||||||
|
# Left here for backward compatibility
|
||||||
if [ -n "$EXTRA_UNMOUNT" ]; then
|
if [ -n "$EXTRA_UNMOUNT" ]; then
|
||||||
$EXTRA_UNMOUNT
|
$EXTRA_UNMOUNT
|
||||||
fi
|
fi
|
||||||
@ -39,6 +41,9 @@ function cleanup () {
|
|||||||
unmount_image
|
unmount_image
|
||||||
cleanup_build_dir
|
cleanup_build_dir
|
||||||
cleanup_image_dir
|
cleanup_image_dir
|
||||||
|
if [ -n "$EXTRA_CLEANUP" ]; then
|
||||||
|
$EXTRA_CLEANUP
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensure_nbd () {
|
function ensure_nbd () {
|
||||||
|
@ -8,8 +8,10 @@ sudo apt-get install -y \
|
|||||||
debootstrap \
|
debootstrap \
|
||||||
inetutils-ping \
|
inetutils-ping \
|
||||||
kpartx \
|
kpartx \
|
||||||
|
zerofree \
|
||||||
qemu-utils || \
|
qemu-utils || \
|
||||||
sudo yum -y install \
|
sudo yum -y install \
|
||||||
debootstrap \
|
debootstrap \
|
||||||
kpartx \
|
kpartx \
|
||||||
|
zerofree \
|
||||||
qemu-img
|
qemu-img
|
||||||
|
Loading…
Reference in New Issue
Block a user