aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/catalyst-spec.5.txt7
-rwxr-xr-xtargets/support/filesystem-functions.sh57
-rwxr-xr-xtargets/support/target_image_setup.sh4
3 files changed, 65 insertions, 3 deletions
diff --git a/doc/catalyst-spec.5.txt b/doc/catalyst-spec.5.txt
index a1559faf..5624e8b6 100644
--- a/doc/catalyst-spec.5.txt
+++ b/doc/catalyst-spec.5.txt
@@ -177,7 +177,7 @@ an embedded or hardened system.
Filesystem
~~~~~~~~~~
-*livecd/fstype*::
+*livecd/fstype*, *<target>/fstype*::
The fstype is used to determine what sort of CD we should build. This
is used to set the type of loopback filesystem that we will use on our
CD. Possible values are as follows:
@@ -186,12 +186,13 @@ CD. Possible values are as follows:
`normal`;; This creates a loop without compression.
`noloop`;; This copies the files to the CD directly, without using a
loopback.
+ `cloud`;; This creates a partitioned QCOW2 image for cloud images.
-*livecd/fsops*::
+*livecd/fsops*, *<target>/fsops*::
The fsops are a list of optional parameters that can be passed to the
tool which will create the filesystem specified in *livecd/fstype*
(example: `-root-owned`). It is valid for the following fstypes:
-`squashfs`, `jffs`, `jffs2`, and `cramfs`.
+`squashfs`, `jffs`, `jffs2`, `cramfs`, `cloud`.
*livecd/iso*::
This is the full path and filename to the ISO image that the
diff --git a/targets/support/filesystem-functions.sh b/targets/support/filesystem-functions.sh
index 98fd5fe3..5d41e3f2 100755
--- a/targets/support/filesystem-functions.sh
+++ b/targets/support/filesystem-functions.sh
@@ -80,3 +80,60 @@ create_cramfs(){
mkcramfs ${clst_fsops} ${clst_destpath} $1/${loopname} \
|| die "Could not create a cramfs filesystem"
}
+
+create_cloud_qcow2() {
+ export source_path="${clst_destpath}"
+ export destination_path="$1"
+ export loopname="image.loop"
+ export qcow2name="image.loop"
+
+ echo "Preparing disk..."
+ # TODO: auto-shrink
+ fallocate -l 5G ${destination_path}/${loopname} \
+ || die "${loopname} creation failure"
+ ( set -e
+ parted -s "${destination_path}/${loopname}" mklabel gpt
+ parted -s --align=none "${destination_path}/${loopname}" mkpart bios_boot 0 2M
+ parted -s --align=none "${destination_path}/${loopname}" mkpart primary 2M 100%
+ parted -s "${destination_path}/${loopname}" set 1 boot on
+ parted -s "${destination_path}/${loopname}" set 1 bios_grub on
+ ) || die "Failed to partition new loopback volume"
+
+ BLOCK_DEV=$(losetup -f --show "${TEMP_DIR}/${TEMP_IMAGE}")
+ mkfs.ext4 -m 0 -F ${clst_fsops} "${BLOCK_DEV}p2" \
+ || die "Couldn't create ext4 filesystem"
+
+ install -d ${destination_path}/loopmount
+ sync; sync; sleep 3 # Try to work around 2.6.0+ loopback bug
+ mount -t ext4 -o acl,user_xattr,delalloc "${BLOCK_DEV}p2" \
+ ${destination_path}/loopmount \
+ || die "Couldn't mount loopback ext4 filesystem"
+ sync; sync; sleep 3 # Try to work around 2.6.0+ loopback bug
+
+ echo "Copying content..."
+ cp -pPR ${source_path}/* ${destination_path}/loopmount
+ [ $? -ne 0 ] && { umount ${destination_path}/${loopname}; \
+ die "Couldn't copy files to loopback ext4 filesystem"; }
+
+ echo 'Installing grub...'
+ grub2-install "${BLOCK_DEV}" --boot-directory "${destination_path}/loopmount/boot"
+
+ umount ${destination_path}/loopmount \
+ || die "Couldn't unmount loopback ext4 filesystem"
+ rmdir -f ${destination_path}/loopmount \
+ || die "Couldn't remove loopmount point"
+
+ # TODO: apply zerofree to the volume
+ # TODO: force an fsck on the volumne
+
+ losetup -d "${BLOCK_DEV}" \
+ || die "Failed to delete block device"
+
+ qemu-img convert -c -f raw -O qcow2 \
+ ${destination_path}/${loopname} \
+ ${destination_path}/${qcow2name} \
+ || die "Failed to convert loop to qcow2"
+ rm -f ${destination_path}/${loopname}
+
+ # Now, $clst_target_path should contain a usable qcow2 image
+}
diff --git a/targets/support/target_image_setup.sh b/targets/support/target_image_setup.sh
index b428d4ed..e1b4ac87 100755
--- a/targets/support/target_image_setup.sh
+++ b/targets/support/target_image_setup.sh
@@ -35,6 +35,10 @@ case ${clst_fstype} in
create_cramfs $1
loopret=$?
;;
+ cloud)
+ create_cloud_qcow2 $1
+ loopret=$?
+ ;;
esac
if [ ${loopret} = "1" ]