3 # Helper script for using a diskfile for the LOWER or UPPER+WORK
6 # Example use a whole diskfile filesystem as LOWER:
7 # LOWER=!overlay-diskfile mnt/ disk.img
9 # Example use a diskfile partition 2 as LOWER:
10 # LOWER=!overlay-diskfile mnt/ disk.img 2
12 # Example use a subtree of a diskfile partition 2 as LOWER:
13 # LOWER=!overlay-diskfile mnt/some/path disk.img 2
15 # Example use a while diskfile as UPPER and WORK.
16 # The diskfile is mounted on "mnt".
17 # UPPER=!overlay-diskfile mnt/some/upper/path disk.img 2
18 # WORK= mnt/some/work/path
20 # Helper function to determine the mount offset for the partition, if any
26 fdisk -lo Start "$1" | grep -A$2 '^ Start' | \
27 sed '${s|^|512*|;b};d' | bc -l
31 # Only do something when invoked by overlay-boot
32 if [ "$ACTION" = "overlay-boot" ] ; then
34 # .. and a diskfile is given
35 if [ -n "$DISKFILE" ] ; then
36 MOUNTPOINT="$(realpath "${1%/*}")"
38 # .. and it's not mounted yet (for this subhost)
39 if ! grep -qE "^[^ ]* $MOUNTPOINT" /proc/mounts ; then
40 OFFSET=$(partoffset "$DISKFILE" "$PARTITIONINDEX")
41 mount -ooffset=$OFFSET "$DISKFILE" "$MOUNTPOINT" || exit 1