Add squashfs output image format

The squashfs format brings a couple of advantages over the other
formats. Image is often an order of magnitude smaller and it can
be used natively, either as an initrd, either with loop mount.

Change-Id: If72940b0c4dafb2504c52dd0429a8eb3f8305751
This commit is contained in:
Tristan Cacqueray 2016-12-18 01:59:07 +00:00
parent da41ee6012
commit 9d13084c41
5 changed files with 19 additions and 4 deletions

View File

@ -102,7 +102,7 @@ function show_options () {
echo "Options:" echo "Options:"
echo " -a i386|amd64|armhf -- set the architecture of the image(default amd64)" echo " -a i386|amd64|armhf -- set the architecture of the image(default amd64)"
echo " -o imagename -- set the imagename of the output image file(default image)" echo " -o imagename -- set the imagename of the output image file(default image)"
echo " -t qcow2,tar,tgz,vhd,docker,aci,raw -- set the image types of the output image files (default qcow2)" echo " -t qcow2,tar,tgz,squashfs,vhd,docker,aci,raw -- set the image types of the output image files (default qcow2)"
echo " File types should be comma separated. VHD outputting requires the vhd-util" echo " File types should be comma separated. VHD outputting requires the vhd-util"
echo " executable be in your PATH. ACI outputting requires the ACI_MANIFEST " echo " executable be in your PATH. ACI outputting requires the ACI_MANIFEST "
echo " environment variable be a path to a manifest file." echo " environment variable be a path to a manifest file."
@ -268,6 +268,12 @@ for X in ${!IMAGE_TYPES[@]}; do
exit 1 exit 1
fi fi
;; ;;
squashfs)
if [ -z "$(which mksquashfs)" ]; then
echo "squashfs output format specified but no mksquashfs executable found."
exit 1
fi
;;
docker) docker)
if [ -z "$(which docker)" ]; then if [ -z "$(which docker)" ]; then
echo "docker output format specified but no docker executable found." echo "docker output format specified but no docker executable found."
@ -452,6 +458,10 @@ for X in ${!IMAGE_TYPES[@]} ; do
fi fi
sudo chown $USER: $IMAGE_NAME.${IMAGE_TYPES[$X]} sudo chown $USER: $IMAGE_NAME.${IMAGE_TYPES[$X]}
unset IMAGE_TYPES[$X] unset IMAGE_TYPES[$X]
elif [ "${IMAGE_TYPES[$x]}" == "squashfs" ]; then
sudo mksquashfs ${TMP_BUILD_DIR}/mnt $IMAGE_NAME.squash -comp xz \
-noappend -root-becomes ${TMP_BUILD_DIR}/mnt \
-wildcards -e "proc/*" -e "sys/*" -no-recovery
elif [ "${IMAGE_TYPES[$X]}" == "docker" ]; then elif [ "${IMAGE_TYPES[$X]}" == "docker" ]; then
sudo tar -C ${TMP_BUILD_DIR}/mnt -cf - --exclude ./sys \ sudo tar -C ${TMP_BUILD_DIR}/mnt -cf - --exclude ./sys \
--exclude ./proc --xattrs --xattrs-include=\* . \ --exclude ./proc --xattrs --xattrs-include=\* . \
@ -476,7 +486,7 @@ if [[ (! $IMAGE_ELEMENT =~ no-final-image) && "$IS_RAMDISK" == "0" ]]; then
# We have to do raw last because it is destructive # We have to do raw last because it is destructive
if [ "$IMAGE_TYPE" = "raw" ]; then if [ "$IMAGE_TYPE" = "raw" ]; then
has_raw_type=1 has_raw_type=1
else elif [ "$IMAGE_TYPE" != "squashfs" ]; then
compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE
fi fi
done done

View File

@ -1,2 +1,3 @@
# This is a cross-platform list tracking distribution packages needed by tests; # This is a cross-platform list tracking distribution packages needed by tests;
# see http://docs.openstack.org/infra/bindep/ for additional information. # see http://docs.openstack.org/infra/bindep/ for additional information.
squashfs-tools

View File

@ -52,6 +52,7 @@ formats are:
* qcow2 * qcow2
* tar * tar
* tgz * tgz
* squashfs
* vhd * vhd
* docker * docker
* raw * raw

View File

@ -0,0 +1,3 @@
---
features:
- New squashfs image output format.

View File

@ -59,8 +59,8 @@ function build_test_image() {
fi fi
} }
test_formats="tar tgz raw qcow2 docker aci" test_formats="tar tgz squashfs raw qcow2 docker aci"
for binary in qemu-img docker ; do for binary in qemu-img docker mksquashfs; do
if [ -z "$(which $binary)" ]; then if [ -z "$(which $binary)" ]; then
echo "Warning: No $binary binary found, cowardly refusing to run tests." echo "Warning: No $binary binary found, cowardly refusing to run tests."
exit 1 exit 1