From 88bbedb26e24ec313d7809592e91f351b0f346d5 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sun, 26 Apr 2020 13:42:54 +0000 Subject: image_types_ota: export OSTREE_BOOT_PARTITION when needed The environment variable OSTREE_BOOT_PARTITION is only used when using GRUB. Move the export into the if statement. Also add a comment why manually adding /boot/loader{.0} directory is necessary. Signed-off-by: Stefan Agner --- classes/image_types_ota.bbclass | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 2cc8913..e9f9467 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass @@ -45,14 +45,17 @@ do_image_ota[cleandirs] = "${OTA_SYSROOT}" do_image_ota[depends] = "${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER') == 'grub' else ''} \ ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER') == 'u-boot' else ''}" IMAGE_CMD_ota () { - export OSTREE_BOOT_PARTITION=${OSTREE_BOOT_PARTITION} - ostree admin --sysroot=${OTA_SYSROOT} init-fs ${OTA_SYSROOT} ostree admin --sysroot=${OTA_SYSROOT} os-init ${OSTREE_OSNAME} + + # Preparation required to steer ostree bootloader detection mkdir -p ${OTA_SYSROOT}/boot/loader.0 ln -s loader.0 ${OTA_SYSROOT}/boot/loader if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then + # Used by ostree-grub-generator called by the ostree binary + export OSTREE_BOOT_PARTITION=${OSTREE_BOOT_PARTITION} + mkdir -p ${OTA_SYSROOT}/boot/grub2 ln -s ../loader/grub.cfg ${OTA_SYSROOT}/boot/grub2/grub.cfg elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then -- cgit v1.2.3-54-g00ecf From 34b1e543c91cfb89c29687c799ac941085d83307 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sun, 26 Apr 2020 14:55:29 +0000 Subject: image_types_ostree: drop unnecessary tmp handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current code clears tmp and then creates a symlink inside it to /sysroot/tmp: tmp └── tmp -> sysroot/tmp This is likely a mistake and the root tmp should have pointed to sysroot/tmp. However, since /tmp is mounted as a tmpfs anyways, we can get rid of all this logic. Signed-off-by: Stefan Agner --- classes/image_types_ostree.bbclass | 3 --- 1 file changed, 3 deletions(-) diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index ce9f984..d29d4c4 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -38,9 +38,6 @@ IMAGE_CMD_ostree () { mkdir sysroot ln -sf sysroot/ostree ostree - rm -rf tmp/* - ln -sf sysroot/tmp tmp - mkdir -p usr/rootdirs mv etc usr/ -- cgit v1.2.3-54-g00ecf From c60b6bb82e7121635ce3f7119927e8704fe03f0f Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sat, 25 Apr 2020 22:15:39 +0000 Subject: image_types_ostree: use hardlink tree Instead of copying the files to be commited to the ostree just use a hardlink tree. This improves performance and wasts less diskspace. When using this method the root directory has already the correct permission bits set. Also get rid of the unnecessary sync. This halfs the execution time of the do_image_ostree tasks in my measurments. Signed-off-by: Stefan Agner --- classes/image_types_ostree.bbclass | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index d29d4c4..758ce00 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -20,14 +20,24 @@ CONVERSION_CMD_tar = "touch ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${ CONVERSIONTYPES_append = " tar" TAR_IMAGE_ROOTFS_task-image-ostree = "${OSTREE_ROOTFS}" + +python prepare_ostree_rootfs() { + import oe.path + import shutil + + ostree_rootfs = d.getVar("OSTREE_ROOTFS") + if os.path.lexists(ostree_rootfs): + bb.utils.remove(ostree_rootfs, True) + + # Copy required as we change permissions on some files. + image_rootfs = d.getVar("IMAGE_ROOTFS") + oe.path.copyhardlinktree(image_rootfs, ostree_rootfs) +} + do_image_ostree[dirs] = "${OSTREE_ROOTFS}" -do_image_ostree[cleandirs] = "${OSTREE_ROOTFS}" +do_image_ostree[prefuncs] += "prepare_ostree_rootfs" do_image_ostree[depends] = "coreutils-native:do_populate_sysroot virtual/kernel:do_deploy ${INITRAMFS_IMAGE}:do_image_complete" IMAGE_CMD_ostree () { - cp -a ${IMAGE_ROOTFS}/* ${OSTREE_ROOTFS} - chmod a+rx ${OSTREE_ROOTFS} - sync - for d in var/*; do if [ "${d}" != "var/local" ]; then rm -rf ${d} -- cgit v1.2.3-54-g00ecf From cd153180c359fefb95d57968b8a4fa0471b588c0 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sat, 25 Apr 2020 22:22:37 +0000 Subject: image_types_ostree/ota: do not commit homes to the OSTree The home directory currently are commited to the OSTree, presumably to then use it for the deployment. However, we do have access to the original rootfs in the OSTree deployment tasks (do_image_ota) hence transferring the files "via OSTree" is not necessary. We do already carry over some files from the original OE rootfs to /var/sota. Follow this approach for /var/local and /home as well. The home will still be stored in the sysroot as documented in https://ostree.readthedocs.io/en/latest/manual/adapting-existing/. Signed-off-by: Stefan Agner --- classes/image_types_ostree.bbclass | 12 +++++------- classes/image_types_ota.bbclass | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index 758ce00..28d9802 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -71,13 +71,11 @@ IMAGE_CMD_ostree () { mkdir -p usr/share/sota/ echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname - # Preserve data in /home to be later copied to /sysroot/home by sysroot - # generating procedure - mkdir -p usr/homedirs - if [ -d "home" ] && [ ! -L "home" ]; then - mv home usr/homedirs/home - ln -sf var/rootdirs/home home - fi + # home directories get copied from the OE root later to the final sysroot + # Create a symlink to var/rootdirs/home to make sure the OSTree deployment + # redirects /home to /var/rootdirs/home. + rm -rf home/ + ln -sf var/rootdirs/home home # Move persistent directories to /var dirs="opt mnt media srv" diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index e9f9467..8f5a01a 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass @@ -80,8 +80,8 @@ IMAGE_CMD_ota () { # Ensure the permissions are correctly set chmod 700 ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota - cp -a ${OSTREE_ROOTFS}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true - cp -a ${OSTREE_ROOTFS}/usr/homedirs/home ${OTA_SYSROOT}/ || true + cp -a ${IMAGE_ROOTFS}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true + cp -a ${IMAGE_ROOTFS}/home ${OTA_SYSROOT}/ || true # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) install -d ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local # Set package version for the first deployment -- cgit v1.2.3-54-g00ecf From fb058bb8eedd9a3a168fa87534f55d1ea610a90a Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sat, 25 Apr 2020 23:36:46 +0000 Subject: image_types_ostree/ota: move home physically to /var/rootdirs/home Instead of using the double indirection mode /home -> /var/rootdirs/home -> /sysroot/home move the home directory physically into /var/rootdirs. This allows to use the --modern flag when initializing the file system. The "old" style is still supported, and does make sense in case the home directories need to be shared between multiple deployments. Since multiple deployments is not a use case in meta-updater use the /var approach. See also: https://github.com/ostreedev/ostree/issues/2085. The modern flag also gets rid of dev, proc, root, run, sys and tmp. All of them have been empty and unused. Note: This change cannot be pushed through updates as this is an initial deployment setting. Only devices provisioned with images built with this change applied will use the new layout. Updates will continue to work on both systems as the symlink from the deployment stays the same (first indirection is still /home -> /var/rootdirs/home). Signed-off-by: Stefan Agner --- classes/image_types_ostree.bbclass | 2 -- classes/image_types_ota.bbclass | 7 +++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index 28d9802..a8a6c39 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -56,13 +56,11 @@ IMAGE_CMD_ostree () { mkdir -p usr/etc/tmpfiles.d tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} - echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf} else mkdir -p usr/etc/init.d tmpfiles_conf=usr/etc/init.d/tmpfiles.sh echo '#!/bin/sh' > ${tmpfiles_conf} echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} - echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf} ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh fi diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 8f5a01a..374ddc2 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass @@ -45,7 +45,7 @@ do_image_ota[cleandirs] = "${OTA_SYSROOT}" do_image_ota[depends] = "${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER') == 'grub' else ''} \ ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER') == 'u-boot' else ''}" IMAGE_CMD_ota () { - ostree admin --sysroot=${OTA_SYSROOT} init-fs ${OTA_SYSROOT} + ostree admin --sysroot=${OTA_SYSROOT} init-fs --modern ${OTA_SYSROOT} ostree admin --sysroot=${OTA_SYSROOT} os-init ${OSTREE_OSNAME} # Preparation required to steer ostree bootloader detection @@ -81,7 +81,10 @@ IMAGE_CMD_ota () { chmod 700 ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota cp -a ${IMAGE_ROOTFS}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true - cp -a ${IMAGE_ROOTFS}/home ${OTA_SYSROOT}/ || true + + mkdir -p ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/rootdirs + cp -a ${IMAGE_ROOTFS}/home ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/rootdirs/home || true + # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) install -d ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local # Set package version for the first deployment -- cgit v1.2.3-54-g00ecf