File: overlay-diskfile

package info (click to toggle)
overlay-boot 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 184 kB
  • sloc: sh: 253; makefile: 59; ansic: 26
file content (45 lines) | stat: -rwxr-xr-x 1,286 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
#
# Helper script for using a diskfile for the LOWER or UPPER+WORK
# filesystems.
#
# Example use a whole diskfile filesystem as LOWER:
# LOWER=!overlay-diskfile mnt/ disk.img
#
# Example use a diskfile partition 2 as LOWER:
# LOWER=!overlay-diskfile mnt/ disk.img 2
#
# Example use a subtree of a diskfile partition 2 as LOWER:
# LOWER=!overlay-diskfile mnt/some/path disk.img 2
#
# Example use a while diskfile as UPPER and WORK.
# The diskfile is mounted on "mnt".
# UPPER=!overlay-diskfile mnt/some/upper/path disk.img 2
# WORK= mnt/some/work/path

# Helper function to determine the mount offset for the partition, if any
partoffset() {
    local X
    if [ -z "$2" ] ; then
	echo 0
    else
	fdisk -lo Start "$1" | grep -A$2 '^ Start' | \
	    sed '${s|^|512*|;b};d' | bc -l
    fi
}

# Only do something when invoked by overlay-boot
if [ "$ACTION" = "overlay-boot" ] ; then
    DISKFILE="$2"
    # .. and a diskfile is given
    if [ -n "$DISKFILE" ] ; then
	MOUNTPOINT="$(realpath "${1%/*}")"
	PARTITIONINDEX="$3"
	# .. and it's not mounted yet (for this subhost)
	if ! grep -qE "^[^ ]* $MOUNTPOINT" /proc/mounts ; then
	    OFFSET=$(partoffset "$DISKFILE" "$PARTITIONINDEX")
	    mount -ooffset=$OFFSET "$DISKFILE" "$MOUNTPOINT" || exit 1
	fi
    fi
fi
echo "${1#/}"