-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinitscript
More file actions
89 lines (72 loc) · 1.75 KB
/
initscript
File metadata and controls
89 lines (72 loc) · 1.75 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
# layerpie: overlayfs for rpi
# initramfs script prologue
PREREQ=""
prereqs()
{
echo "${PREREQ}"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. /scripts/functions
# constants
BASEDIR=/mnt/lpie
TMPFS=$BASEDIR/rw
UPPER=$TMPFS/upper
WORK=$TMPFS/work
LOWER=$BASEDIR/ro
# utility functions
chk_fail()
{
if [ $1 -ne 0 ] ; then
panic "lpie: $2"
exit 0
fi
}
# check kernel cmdline if lpie is enabled
ENABLED=0
for CMD_PARAM in $(cat /proc/cmdline); do
case ${CMD_PARAM} in
lpie)
ENABLED=1
;;
esac
done
if [ $ENABLED -eq 0 ]; then
exit 0
fi
# load driver
modprobe overlay
chk_fail $? "failed to load overlay driver"
# mount ramdisk and create directories
mkdir -p $TMPFS
mount -t tmpfs tmpfs $TMPFS
chk_fail $? "failed to mount tmpfs at $TMPFS"
mkdir -p $UPPER
mkdir -p $WORK
# mount rootfs
mkdir -p $LOWER
mount -o move $rootmnt $LOWER
chk_fail $? "failed to move rootfs from $rootmnt to $LOWER"
# initiate overlay mount
mount -t overlay -o lowerdir=$LOWER,upperdir=$UPPER,workdir=$WORK overlay $rootmnt
chk_fail $? "failed to mount overlayfs at $rootmnt"
# relocate mountpoints to rootmnt
mkdir -p ${rootmnt}${LOWER}
mount -o move $LOWER ${rootmnt}${LOWER}
chk_fail $? "failed to relocate $LOWER ro $rootmnt"
mkdir -p ${rootmnt}${TMPFS}
mount -o move $TMPFS ${rootmnt}${TMPFS}
chk_fail $? "failed to relocate $TMPFS to $rootmnt"
# adjust fstab
echo "# lpie fstab" > $rootmnt/etc/fstab
echo "/dev/mmcblk0p1 /boot vfat ro 0 2" >> $rootmnt/etc/fstab
echo "# raspian fstab (without / and /boot)" >> $rootmnt/etc/fstab
GREP=$rootmnt/bin/grep
cat ${rootmnt}${LOWER}/etc/fstab | $GREP -v " / " | $GREP -v " /boot " >> $rootmnt/etc/fstab
log_success_msg "lpie: file systems ready"
exit 0