summaryrefslogtreecommitdiffstats
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
parent1c55880c8cbba009e07645e3a7b26f2bf2a5756c (diff)
downloadmeta-readonly-rootfs-overlay-b1efdfa75d9a0ca475d92e8b5ea1eba165626231.tar.gz
added support for running this initscript directly in the image
removed udev
-rw-r--r--README.md34
-rw-r--r--recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh54
-rw-r--r--recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb17
-rw-r--r--recipes-core/initrdscripts/initscripts-readonly-rootfs-overlay_1.0.bb1
-rw-r--r--recipes-core/initrdscripts/readonly-rootfs-overlay-init-script.inc18
5 files changed, 67 insertions, 57 deletions
diff --git a/README.md b/README.md
index 8f037b3..00ed942 100644
--- a/README.md
+++ b/README.md
@@ -57,18 +57,48 @@ If you use this layer you do *not* need to set `read-only-rootfs` in the
57 57
58## Kernel command line parameters 58## Kernel command line parameters
59 59
60Example: 60### Example using initrd:
61 61
62``` 62```
63root=/dev/sda1 rootfstype=ext4 rootrw=/dev/sda2 rootrwfstype=btrfs 63root=/dev/sda1 rootrw=/dev/sda2
64``` 64```
65 65
66This cmd line start `/sbin/init` with the `/dev/sda1` partition as the read-only
67rootfs and the `/dev/sda2` partition as the read-write persistend state.
68
69```
70root=/dev/sda1 rootrw=/dev/sda2 init=/bin/sh
71```
72
73The same as before but it now starts `/bin/sh` instead of `/sbin/init`.
74
75### Example without initrd:
76
77```
78root=/dev/sda1 rootrw=/dev/sda2 init=/init
79```
80
81This cmd line starts `/sbin/init` with `/dev/sda1` partition as the read-only
82rootfs and the `/dev/sda2` partition as the read-write persistend state. When
83using this init script without an initrd, `init=/init` has to be set.
84
85```
86root=/dev/sda1 rootrw=/dev/sda2 init=/init rootinit=/bin/sh
87```
88
89The same as before but it now starts `/bin/sh` instead of `/sbin/init`
90
91### Details
92
66`root=` specifies the read-only root filesystem device. If this is not 93`root=` specifies the read-only root filesystem device. If this is not
67specified, the current rootfs is used. 94specified, the current rootfs is used.
68 95
69`rootfstype=` if support for the-read only filesystem is not build into the 96`rootfstype=` if support for the-read only filesystem is not build into the
70kernel, you can specifiy the required module name here. 97kernel, you can specifiy the required module name here.
71 98
99`rootinit=` if the `init` parameter was used to specify this init script,
100`rootinit` can be used to overwrite the default (`/sbin/init`).
101
72`rootrw=` specifies the read-write filesystem device. If this is not 102`rootrw=` specifies the read-write filesystem device. If this is not
73specified, `tmpfs` is used. 103specified, `tmpfs` is used.
74 104
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
diff --git a/recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb b/recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb
index 7c2bdf6..164d394 100644
--- a/recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb
+++ b/recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb
@@ -1,19 +1,8 @@
1SUMMARY = "Read only rootfs with overlay init script" 1require readonly-rootfs-overlay-init-script.inc
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
4DEPENDS = "virtual/kernel"
5RDEPENDS_${PN} = "udev"
6SRC_URI = "file://init-readonly-rootfs-overlay-boot.sh"
7 2
8S = "${WORKDIR}" 3do_install_append() {
9
10do_install() {
11 install -m 0755 ${WORKDIR}/init-readonly-rootfs-overlay-boot.sh ${D}/init
12 install -d ${D}/dev 4 install -d ${D}/dev
13 mknod -m 622 ${D}/dev/console c 5 1 5 mknod -m 622 ${D}/dev/console c 5 1
14} 6}
15 7
16FILES_${PN} += " /init /dev " 8FILES_${PN} += "/dev"
17
18# Due to kernel dependency
19PACKAGE_ARCH = "${MACHINE_ARCH}"
diff --git a/recipes-core/initrdscripts/initscripts-readonly-rootfs-overlay_1.0.bb b/recipes-core/initrdscripts/initscripts-readonly-rootfs-overlay_1.0.bb
new file mode 100644
index 0000000..9428356
--- /dev/null
+++ b/recipes-core/initrdscripts/initscripts-readonly-rootfs-overlay_1.0.bb
@@ -0,0 +1 @@
require readonly-rootfs-overlay-init-script.inc
diff --git a/recipes-core/initrdscripts/readonly-rootfs-overlay-init-script.inc b/recipes-core/initrdscripts/readonly-rootfs-overlay-init-script.inc
new file mode 100644
index 0000000..947246b
--- /dev/null
+++ b/recipes-core/initrdscripts/readonly-rootfs-overlay-init-script.inc
@@ -0,0 +1,18 @@
1SUMMARY = "Read only rootfs with overlay init script"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
4DEPENDS = "virtual/kernel"
5SRC_URI = "file://init-readonly-rootfs-overlay-boot.sh"
6
7S = "${WORKDIR}"
8
9do_install() {
10 install -m 0755 ${WORKDIR}/init-readonly-rootfs-overlay-boot.sh ${D}/init
11 install -d "${D}/media/rfs/ro"
12 install -d "${D}/media/rfs/rw"
13}
14
15FILES_${PN} += " /init /media/rfs"
16
17# Due to kernel dependency
18PACKAGE_ARCH = "${MACHINE_ARCH}"