diff options
author | Anton Gerasimov <anton@advancedtelematic.com> | 2016-09-01 16:11:52 +0200 |
---|---|---|
committer | Anton Gerasimov <anton@advancedtelematic.com> | 2016-09-01 16:11:52 +0200 |
commit | d9c84bb2ea534dd2a49e2290f5eab21d7b3cfd55 (patch) | |
tree | f01b8d1be16569993ed825b669cda70f347bb48b /meta-sota | |
parent | df72ee883ec73cab47cfaa23e0f2feff9f1d2862 (diff) |
Adds image type for OSTree deployment sysroot
Bug-AGL: SPEC-246
Change-Id: I1390d1aae652f84b61a3b9ca33ae886c138edc50
Signed-off-by: Anton Gerasimov <anton@advancedtelematic.com>
Diffstat (limited to 'meta-sota')
-rw-r--r-- | meta-sota/classes/image_types_ostree.bbclass | 87 |
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}" + +} + |