summaryrefslogtreecommitdiffstats
path: root/meta-sota/classes
diff options
context:
space:
mode:
authorJan-Simon Moeller <jsmoeller@linuxfoundation.org>2016-09-12 14:29:53 +0000
committerGerrit Code Review <gerrit@172.30.200.200>2016-09-12 14:29:53 +0000
commit0d6d370cdebd3c27eace1f9c7104b01e8ee8402e (patch)
treeaa2b08cccd48c574b277e6b0a17b7e23337a9fd4 /meta-sota/classes
parent53ae34d7652bed4ad2162d1e03cfcb78d2724066 (diff)
parentd9c84bb2ea534dd2a49e2290f5eab21d7b3cfd55 (diff)
Merge "Adds image type for OSTree deployment sysroot"
Diffstat (limited to 'meta-sota/classes')
-rw-r--r--meta-sota/classes/image_types_ostree.bbclass87
1 files changed, 87 insertions, 0 deletions
diff --git a/meta-sota/classes/image_types_ostree.bbclass b/meta-sota/classes/image_types_ostree.bbclass
new file mode 100644
index 0000000..b82bfb7
--- /dev/null
+++ b/meta-sota/classes/image_types_ostree.bbclass
@@ -0,0 +1,87 @@
+# OSTree deployment
+
+inherit image_types
+
+IMAGE_DEPENDS_ostree = "ostree-native:do_populate_sysroot \
+ virtual/kernel:do_deploy \
+ ${INITRAMFS_IMAGE}:do_rootfs"
+
+# Please redefine OSTREE_REPO in your local.conf in order to have a persistent
+# OSTree repo
+OSTREE_REPO ?= "${DEPLOY_DIR_IMAGE}/ostree_repo"
+export OSTREE_REPO
+
+# OSTREE_BRANCHNAME can also be redefined
+OSTREE_BRANCHNAME ?= "${IMAGE_BASENAME}"
+export OSTREE_BRANCHNAME
+
+IMAGE_CMD_ostree () {
+ OSTREE_ROOTFS=`mktemp -d ${WORKDIR}/ostree-root-XXXXX`
+ cp -rp ${IMAGE_ROOTFS}/* ${OSTREE_ROOTFS}
+ cd ${OSTREE_ROOTFS}
+
+ # Create sysroot directory to which physical sysroot will be mounted
+ mkdir sysroot
+ ln -sf /sysroot/ostree ostree
+ ln -sf /sysroot/tmp tmp
+
+ mkdir -p usr/rootdirs
+ mkdir -p var/rootdirs
+
+ # Implement UsrMove
+ dirs="bin sbin lib"
+
+ for dir in ${dirs} ; do
+ if [ -d ${dir} ] && [ ! -L ${dir} ] ; then
+ mv ${dir} usr/rootdirs/
+ rm -rf ${dir}
+ ln -sf /usr/rootdirs/${dir} ${dir}
+ fi
+ done
+
+ # Move persistent directories to /var
+ dirs="home opt mnt media srv"
+
+ for dir in ${dirs}; do
+ if [ -d ${dir} ] && [ ! -L ${dir} ]; then
+ mv ${dir} var/rootdirs/
+ ln -sf /var/rootdirs/${dir} ${dir}
+ fi
+ done
+
+ if [ -d root ] && [ ! -L root ]; then
+ mv root var/roothome
+ ln -sf /var/roothome root
+ fi
+
+ # Creating boot directories is required for "ostree admin deploy"
+
+ mkdir -p boot/loader.0
+ mkdir -p boot/loader.1
+ ln -sf boot/loader.0 boot/loader
+
+ checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} | cut -f 1 -d " "`
+
+ cp ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} boot/vmlinuz-${checksum}
+ cp ${DEPLOY_DIR_IMAGE}/${INITRD_IMAGE}-${MACHINE}.cpio.gz boot/initramfs-${checksum}
+
+ cd ${WORKDIR}
+
+ # Create a tarball that can be then commited to OSTree repo
+ OSTREE_TAR=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ostree.tar.bz2
+ tar -C ${OSTREE_ROOTFS} -cjf ${OSTREE_TAR} .
+ rm -rf ${OSTREE_ROOTFS}
+
+ if [ ! -d ${OSTREE_REPO} ]; then
+ ostree --repo=${OSTREE_REPO} init --mode=archive-z2
+ fi
+
+ # Commit the result
+ ostree --repo=${OSTREE_REPO} commit \
+ --tree=tar=${OSTREE_TAR} \
+ --skip-if-unchanged \
+ --branch=${OSTREE_BRANCHNAME} \
+ --subject="Commit-id: ${IMAGE_NAME}"
+
+}
+