From 4017e4178bc38bf855ca023490d12f6e89063956 Mon Sep 17 00:00:00 2001 From: jumperfly Date: Wed, 16 Nov 2016 19:54:24 +0000 Subject: [PATCH] If the newimg partition is not found just log a message and carry on. --- README.md | 6 +++++- src/init | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a8410f5..de02acf 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,15 @@ This is used as the writeable area of the overlay and consists of three director * /persistent: Used as an additional 'lowerdir' of the overlayfs. As the 'upperdir' is cleared, this read-only lower dir allows customisations to be made compared to the read-only OS image. eg. SSH keys. ### The image partition -This must contain a single file, root-squashfs.img which contains the full operating system. +This must contain a single file, root-squashfs.img which contains the full operating system. This is mounted read-only. + +If the overlayfs module is found within the image under /lib/modules/ it is loaded, otherwise it is assumed overlayfs support is build into the kernel. ### The new image partition. If the partition is detected and contains an image file with the same name as the one that will be mounted from the image partition it will be moved into the image partition. The previous image will be renamed -old.img +If this partition is used, then the 'image' partition should be at least double the size in order to hold old and new images. + ## Project structure The build.sh script will generate two initramfs files per architecture into a 'target' directory. * init--.gz - The 'standard' initramfs. This should be used in most cases. diff --git a/src/init b/src/init index fb2c7b5..549d6db 100755 --- a/src/init +++ b/src/init @@ -35,16 +35,22 @@ if [[ $ATTEMPTS -eq $MAX_WAIT ]]; then fi # Mount device containing updated image (if any) -mount -t ext4 $NEWIMG_DEVICE /mnt/newimg -if [[ -e /mnt/newimg/$OS_IMAGE ]]; then - # Mount device containing current image RW and replace with updated image - mount -t ext4 $IMG_DEVICE /mnt/img - mv -f /mnt/newimg/$OS_IMAGE /mnt/img/$OS_IMAGE-new - mv -f /mnt/img/$OS_IMAGE /mnt/img/$OS_IMAGE-old - mv /mnt/img/$OS_IMAGE-new /mnt/img/$OS_IMAGE - umount /mnt/img +if findfs $NEWIMG_DEVICE &> /dev/null; then + mount -t ext4 $NEWIMG_DEVICE /mnt/newimg + if [[ -e /mnt/newimg/$OS_IMAGE ]]; then + # Mount device containing current image RW and replace with updated image + echo "Detected a new OS image, copying to image partition..." + mount -t ext4 $IMG_DEVICE /mnt/img + mv -f /mnt/newimg/$OS_IMAGE /mnt/img/$OS_IMAGE-new + mv -f /mnt/img/$OS_IMAGE /mnt/img/$OS_IMAGE-old + mv /mnt/img/$OS_IMAGE-new /mnt/img/$OS_IMAGE + umount /mnt/img + echo "New image copied." + fi + umount /mnt/newimg +else + echo "The 'newimg' partition was not detected, not checking for updated images." fi -umount /mnt/newimg # Mount device containing current image RO mount -t ext4 -o ro $IMG_DEVICE /mnt/img