forked from chesty/overlayroot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-bottom-overlay
executable file
·74 lines (60 loc) · 1.93 KB
/
init-bottom-overlay
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /scripts/functions
if grep -q -E '(^|\s)skipoverlay(\s|$)' /proc/cmdline; then
log_begin_msg "Skipping overlay, found 'skipoverlay' in cmdline"
log_end_msg
exit 0
fi
log_begin_msg "Starting overlay"
log_end_msg
# default is for the activity light to blink on sd card access
# but with tmpfs overlay there's not as much activity
echo cpu0 > /sys/class/leds/led0/trigger
mkdir -p /overlay
# if we have a filesystem label of overlaytmp
# use that as the overlay, otherwise use tmpfs.
# overlaytmp is semi permanent, it can get wiped though.
# also, overlaytmp on usb doesn't get unmounted.
# i don't have a head to watch shutdown messages
# so I don't know why. which means if you put
# overlaytmp on usb, it's probably going to get
# formated every boot, which will slow boot speed
OLDEV=`blkid -L overlaytmp`
if [ -z "${OLDEV}" ]; then
mount -t tmpfs tmpfs /overlay
else
_checkfs_once ${OLDEV} /overlay >> /log.txt 2>&1 || \
mke2fs -FL overlaytmp -t ext4 -E lazy_itable_init,lazy_journal_init ${OLDEV}
mount ${OLDEV} /overlay
fi
# if you sudo touch /overlay/reformatoverlay
# next reboot will give you a fresh /overlay
if [ -f /overlay/reformatoverlay ]; then
umount /overlay
mke2fs -FL overlaytmp -t ext4 -E lazy_itable_init,lazy_journal_init ${OLDEV}
mount ${OLDEV} /overlay
fi
mkdir -p /overlay/upper
mkdir -p /overlay/work
mkdir -p /overlay/lower
# make the readonly root available
mount -n -o move ${rootmnt} /overlay/lower
mount -t overlay overlay -olowerdir=/overlay/lower,upperdir=/overlay/upper,workdir=/overlay/work ${rootmnt}
mkdir -p ${rootmnt}/overlay
mount -n -o rbind /overlay ${rootmnt}/overlay
# fix up fstab
cp ${rootmnt}/etc/fstab ${rootmnt}/etc/fstab.orig
awk '$2 != "/" {print $0}' ${rootmnt}/etc/fstab.orig > ${rootmnt}/etc/fstab
awk '$2 == "'${rootmnt}'" { $2 = "/" ; print $0}' /etc/mtab >> ${rootmnt}/etc/fstab
exit 0