diff options
5 files changed, 67 insertions, 57 deletions
@@ -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 | ||
60 | Example: | 60 | ### Example using initrd: |
61 | 61 | ||
62 | ``` | 62 | ``` |
63 | root=/dev/sda1 rootfstype=ext4 rootrw=/dev/sda2 rootrwfstype=btrfs | 63 | root=/dev/sda1 rootrw=/dev/sda2 |
64 | ``` | 64 | ``` |
65 | 65 | ||
66 | This cmd line start `/sbin/init` with the `/dev/sda1` partition as the read-only | ||
67 | rootfs and the `/dev/sda2` partition as the read-write persistend state. | ||
68 | |||
69 | ``` | ||
70 | root=/dev/sda1 rootrw=/dev/sda2 init=/bin/sh | ||
71 | ``` | ||
72 | |||
73 | The same as before but it now starts `/bin/sh` instead of `/sbin/init`. | ||
74 | |||
75 | ### Example without initrd: | ||
76 | |||
77 | ``` | ||
78 | root=/dev/sda1 rootrw=/dev/sda2 init=/init | ||
79 | ``` | ||
80 | |||
81 | This cmd line starts `/sbin/init` with `/dev/sda1` partition as the read-only | ||
82 | rootfs and the `/dev/sda2` partition as the read-write persistend state. When | ||
83 | using this init script without an initrd, `init=/init` has to be set. | ||
84 | |||
85 | ``` | ||
86 | root=/dev/sda1 rootrw=/dev/sda2 init=/init rootinit=/bin/sh | ||
87 | ``` | ||
88 | |||
89 | The 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 |
67 | specified, the current rootfs is used. | 94 | specified, 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 |
70 | kernel, you can specifiy the required module name here. | 97 | kernel, 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 |
73 | specified, `tmpfs` is used. | 103 | specified, `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" | |||
9 | UMOUNT="/bin/umount" | 9 | UMOUNT="/bin/umount" |
10 | 10 | ||
11 | INIT="/sbin/init" | 11 | INIT="/sbin/init" |
12 | ROOT_ROINIT="/sbin/init" | ||
12 | 13 | ||
13 | ROOT_MOUNT="/mnt" | 14 | ROOT_MOUNT="/mnt" |
14 | ROOT_RODEVICE="" | 15 | ROOT_RODEVICE="" |
@@ -17,35 +18,12 @@ ROOT_ROMOUNT="/media/rfs/ro" | |||
17 | ROOT_RWMOUNT="/media/rfs/rw" | 18 | ROOT_RWMOUNT="/media/rfs/rw" |
18 | ROOT_RWRESET="no" | 19 | ROOT_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. | ||
22 | udev_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 | |||
37 | early_setup() { | 21 | early_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 | ||
51 | read_args() { | 29 | read_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 @@ | |||
1 | SUMMARY = "Read only rootfs with overlay init script" | 1 | require readonly-rootfs-overlay-init-script.inc |
2 | LICENSE = "MIT" | ||
3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
4 | DEPENDS = "virtual/kernel" | ||
5 | RDEPENDS_${PN} = "udev" | ||
6 | SRC_URI = "file://init-readonly-rootfs-overlay-boot.sh" | ||
7 | 2 | ||
8 | S = "${WORKDIR}" | 3 | do_install_append() { |
9 | |||
10 | do_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 | ||
16 | FILES_${PN} += " /init /dev " | 8 | FILES_${PN} += "/dev" |
17 | |||
18 | # Due to kernel dependency | ||
19 | PACKAGE_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 @@ | |||
1 | SUMMARY = "Read only rootfs with overlay init script" | ||
2 | LICENSE = "MIT" | ||
3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
4 | DEPENDS = "virtual/kernel" | ||
5 | SRC_URI = "file://init-readonly-rootfs-overlay-boot.sh" | ||
6 | |||
7 | S = "${WORKDIR}" | ||
8 | |||
9 | do_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 | |||
15 | FILES_${PN} += " /init /media/rfs" | ||
16 | |||
17 | # Due to kernel dependency | ||
18 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||