summaryrefslogtreecommitdiffstats
path: root/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh
diff options
context:
space:
mode:
authorClaudius Heine <ch@denx.de>2016-10-21 11:11:26 +0200
committerClaudius Heine <ch@denx.de>2016-10-21 11:17:17 +0200
commitb1efdfa75d9a0ca475d92e8b5ea1eba165626231 (patch)
tree0c6fbf145a5e9b9e870243c7a3a29289656c1d99 /recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh
parent1c55880c8cbba009e07645e3a7b26f2bf2a5756c (diff)
downloadmeta-readonly-rootfs-overlay-b1efdfa75d9a0ca475d92e8b5ea1eba165626231.tar.gz
added support for running this initscript directly in the image
removed udev
Diffstat (limited to 'recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh')
-rw-r--r--recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh54
1 files changed, 13 insertions, 41 deletions
diff --git a/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh b/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh
index 37a1635..4c70753 100644
--- a/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh
+++ b/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh
@@ -9,6 +9,7 @@ MOUNT="/bin/mount"
9UMOUNT="/bin/umount" 9UMOUNT="/bin/umount"
10 10
11INIT="/sbin/init" 11INIT="/sbin/init"
12ROOT_ROINIT="/sbin/init"
12 13
13ROOT_MOUNT="/mnt" 14ROOT_MOUNT="/mnt"
14ROOT_RODEVICE="" 15ROOT_RODEVICE=""
@@ -17,35 +18,12 @@ ROOT_ROMOUNT="/media/rfs/ro"
17ROOT_RWMOUNT="/media/rfs/rw" 18ROOT_RWMOUNT="/media/rfs/rw"
18ROOT_RWRESET="no" 19ROOT_RWRESET="no"
19 20
20# Copied from initramfs-framework. The core of this script probably should be
21# turned into initramfs-framework modules to reduce duplication.
22udev_daemon() {
23 OPTIONS="/sbin/udev/udevd /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd"
24
25 for o in $OPTIONS; do
26 if [ -x "$o" ]; then
27 echo $o
28 return 0
29 fi
30 done
31
32 return 1
33}
34
35_UDEV_DAEMON=`udev_daemon`
36
37early_setup() { 21early_setup() {
38 mkdir -p /proc 22 mkdir -p /proc
39 mkdir -p /sys 23 mkdir -p /sys
40 $MOUNT -t proc proc /proc 24 $MOUNT -t proc proc /proc
41 $MOUNT -t sysfs sysfs /sys 25 $MOUNT -t sysfs sysfs /sys
42 $MOUNT -t devtmpfs none /dev 26 grep -w "/dev" /proc/mounts >/dev/null || $MOUNT -t devtmpfs none /dev
43
44 mkdir -p /run
45 mkdir -p /var/run
46
47 $_UDEV_DAEMON --daemon
48 udevadm trigger --action=add
49} 27}
50 28
51read_args() { 29read_args() {
@@ -57,6 +35,8 @@ read_args() {
57 ROOT_RODEVICE=$optarg ;; 35 ROOT_RODEVICE=$optarg ;;
58 rootfstype=*) 36 rootfstype=*)
59 modprobe $optarg 2> /dev/null ;; 37 modprobe $optarg 2> /dev/null ;;
38 rootinit=*)
39 ROOT_ROINIT=$optarg ;;
60 rootrw=*) 40 rootrw=*)
61 ROOT_RWDEVICE=$optarg ;; 41 ROOT_RWDEVICE=$optarg ;;
62 rootrwfstype=*) 42 rootrwfstype=*)
@@ -108,6 +88,13 @@ mount_and_boot() {
108 fatal "Could not mount read-only rootfs" 88 fatal "Could not mount read-only rootfs"
109 fi 89 fi
110 90
91 # If future init is the same as current file, use $ROOT_ROINIT
92 # Tries to avoid loop to infinity if init is set to current file via
93 # kernel commandline
94 if cmp -s "$0" "$INIT"; then
95 INIT="$ROOT_ROINIT"
96 fi
97
111 # Build mount options for read write root filesystem. 98 # Build mount options for read write root filesystem.
112 # If no read-write device was specified via kernel commandline, use tmpfs. 99 # If no read-write device was specified via kernel commandline, use tmpfs.
113 if [ -z "${ROOT_RWDEVICE}" ]; then 100 if [ -z "${ROOT_RWDEVICE}" ]; then
@@ -128,9 +115,9 @@ mount_and_boot() {
128 115
129 # Determine which unification filesystem to use 116 # Determine which unification filesystem to use
130 union_fs_type="" 117 union_fs_type=""
131 if grep -w "overlay" /proc/filesystems; then 118 if grep -w "overlay" /proc/filesystems >/dev/null; then
132 union_fs_type="overlay" 119 union_fs_type="overlay"
133 elif grep -w "aufs" /proc/filesystems; then 120 elif grep -w "aufs" /proc/filesystems >/dev/null; then
134 union_fs_type="aufs" 121 union_fs_type="aufs"
135 else 122 else
136 union_fs_type="" 123 union_fs_type=""
@@ -155,21 +142,6 @@ mount_and_boot() {
155 $MOUNT -n --move $ROOT_ROMOUNT ${ROOT_MOUNT}/$ROOT_ROMOUNT 142 $MOUNT -n --move $ROOT_ROMOUNT ${ROOT_MOUNT}/$ROOT_ROMOUNT
156 $MOUNT -n --move $ROOT_RWMOUNT ${ROOT_MOUNT}/$ROOT_RWMOUNT 143 $MOUNT -n --move $ROOT_RWMOUNT ${ROOT_MOUNT}/$ROOT_RWMOUNT
157 144
158 # Watches the udev event queue, and exits if all current events are handled
159 udevadm settle --timeout=3
160 # Kills the current udev running processes, which survived after
161 # device node creation events were handled, to avoid unexpected behavior
162 killall -9 "${_UDEV_DAEMON##*/}" 2>/dev/null
163
164 # Remove /run /var/run that are created in early_setup
165 rm -rf /run /var/run
166
167 # Move the mount points of some filesystems over to
168 # the corresponding directories under the real root filesystem.
169 for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do
170 mkdir -p ${ROOT_MOUNT}/media/${dir##*/}
171 $MOUNT -n --move $dir ${ROOT_MOUNT}/media/${dir##*/}
172 done
173 $MOUNT -n --move /proc ${ROOT_MOUNT}/proc 145 $MOUNT -n --move /proc ${ROOT_MOUNT}/proc
174 $MOUNT -n --move /sys ${ROOT_MOUNT}/sys 146 $MOUNT -n --move /sys ${ROOT_MOUNT}/sys
175 $MOUNT -n --move /dev ${ROOT_MOUNT}/dev 147 $MOUNT -n --move /dev ${ROOT_MOUNT}/dev