diff options
-rw-r--r-- | COPYING.MIT | 17 | ||||
-rw-r--r-- | README.md | 71 | ||||
-rw-r--r-- | conf/layer.conf | 10 | ||||
-rw-r--r-- | recipes-core/images/core-image-rorootfs-overlay-initramfs.bb | 22 | ||||
-rw-r--r-- | recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh | 160 | ||||
-rw-r--r-- | recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb | 19 | ||||
-rw-r--r-- | recipes-kernel/linux/linux-yocto_%.bbappend | 1 |
7 files changed, 300 insertions, 0 deletions
diff --git a/COPYING.MIT b/COPYING.MIT new file mode 100644 index 0000000..89de354 --- /dev/null +++ b/COPYING.MIT | |||
@@ -0,0 +1,17 @@ | |||
1 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
2 | of this software and associated documentation files (the "Software"), to deal | ||
3 | in the Software without restriction, including without limitation the rights | ||
4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
5 | copies of the Software, and to permit persons to whom the Software is | ||
6 | furnished to do so, subject to the following conditions: | ||
7 | |||
8 | The above copyright notice and this permission notice shall be included in | ||
9 | all copies or substantial portions of the Software. | ||
10 | |||
11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
17 | THE SOFTWARE. | ||
diff --git a/README.md b/README.md new file mode 100644 index 0000000..1e44be2 --- /dev/null +++ b/README.md | |||
@@ -0,0 +1,71 @@ | |||
1 | This README file contains information on the contents of the | ||
2 | readonly-rootfs-overlay layer. | ||
3 | |||
4 | Please see the corresponding sections below for details. | ||
5 | |||
6 | # Dependencies | ||
7 | |||
8 | This layer depends on: | ||
9 | |||
10 | URI: git://git.openembedded.org/bitbake | ||
11 | branch: master | ||
12 | |||
13 | URI: git://git.openembedded.org/openembedded-core | ||
14 | layers: meta | ||
15 | branch: master | ||
16 | |||
17 | |||
18 | # Patches | ||
19 | |||
20 | Please submit any patches against the readonly-rootfs-overlay layer via pull | ||
21 | request. | ||
22 | |||
23 | |||
24 | # Table of Contents | ||
25 | |||
26 | I. Adding the readonly-rootfs-overlay layer to your build | ||
27 | II. Read-only root filesystem | ||
28 | III. Kernel command line parameters | ||
29 | |||
30 | |||
31 | ## I. Adding the readonly-rootfs-overlay layer to your build | ||
32 | |||
33 | In order to use this layer, you need to make the build system aware of | ||
34 | it. | ||
35 | |||
36 | Assuming the readonly-rootfs-overlay layer exists at the top-level of your | ||
37 | yocto build tree, you can add it to the build system by adding the | ||
38 | location of the readonly-rootfs-overlay layer to bblayers.conf, along with any | ||
39 | other layers needed. e.g.: | ||
40 | |||
41 | BBLAYERS ?= " \ | ||
42 | /path/to/yocto/meta \ | ||
43 | /path/to/yocto/meta-poky \ | ||
44 | /path/to/yocto/meta-yocto-bsp \ | ||
45 | /path/to/yocto/meta-readonly-rootfs-overlay \ | ||
46 | " | ||
47 | |||
48 | |||
49 | ## II. Read-only root filesystem | ||
50 | |||
51 | If you use this layer you do *not* need to set `read-only-rootfs` in the | ||
52 | `IMAGE_FEATURES` or `EXTRA_IMAGE_FEATURES` variable. | ||
53 | |||
54 | ## III. Kernel command line parameters | ||
55 | |||
56 | Example: | ||
57 | |||
58 | ``` | ||
59 | root=/dev/vda rootfstype=ext4 rootrw=/dev/vdb rootrwfstype=btrfs | ||
60 | ``` | ||
61 | |||
62 | `root=` specifies the read-only root filesystem device. (required) | ||
63 | |||
64 | `rootfstype=` if support for the-read only filesystem is not build into the | ||
65 | kernel, you can specifiy the required module name here. | ||
66 | |||
67 | `rootrw=` specifies the read-write root filesystem device. If this is not | ||
68 | specified, `tmpfs` is used. | ||
69 | |||
70 | `rootrwfstype=` if support for the read-write filesystem is not build into the | ||
71 | kernel, you can specifiy the required module name here. | ||
diff --git a/conf/layer.conf b/conf/layer.conf new file mode 100644 index 0000000..72f9c36 --- /dev/null +++ b/conf/layer.conf | |||
@@ -0,0 +1,10 @@ | |||
1 | # We have a conf and classes directory, add to BBPATH | ||
2 | BBPATH .= ":${LAYERDIR}" | ||
3 | |||
4 | # We have recipes-* directories, add to BBFILES | ||
5 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ | ||
6 | ${LAYERDIR}/recipes-*/*/*.bbappend" | ||
7 | |||
8 | BBFILE_COLLECTIONS += "readonly-rootfs-overlay" | ||
9 | BBFILE_PATTERN_readonly-rootfs-overlay = "^${LAYERDIR}/" | ||
10 | BBFILE_PRIORITY_readonly-rootfs-overlay = "6" | ||
diff --git a/recipes-core/images/core-image-rorootfs-overlay-initramfs.bb b/recipes-core/images/core-image-rorootfs-overlay-initramfs.bb new file mode 100644 index 0000000..4c21555 --- /dev/null +++ b/recipes-core/images/core-image-rorootfs-overlay-initramfs.bb | |||
@@ -0,0 +1,22 @@ | |||
1 | # Simple initramfs image. Mostly used for live images. | ||
2 | DESCRIPTION = "Small image capable of booting a device. The kernel includes \ | ||
3 | the Minimal RAM-based Initial Root Filesystem (initramfs), mounts the root fs \ | ||
4 | read only and uses a file system overlay for written data." | ||
5 | |||
6 | PACKAGE_INSTALL = "initramfs-readonly-rootfs-overlay ${VIRTUAL-RUNTIME_base-utils} udev base-passwd ${ROOTFS_BOOTSTRAP_INSTALL}" | ||
7 | |||
8 | # Do not pollute the initrd image with rootfs features | ||
9 | IMAGE_FEATURES = "" | ||
10 | |||
11 | export IMAGE_BASENAME = "core-image-readonly-rootfs-overlay-initramfs" | ||
12 | IMAGE_LINGUAS = "" | ||
13 | |||
14 | LICENSE = "MIT" | ||
15 | |||
16 | IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}" | ||
17 | inherit core-image | ||
18 | |||
19 | IMAGE_ROOTFS_SIZE = "8192" | ||
20 | IMAGE_ROOTFS_EXTRA_SPACE = "0" | ||
21 | |||
22 | BAD_RECOMMENDATIONS += "busybox-syslog" | ||
diff --git a/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh b/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh new file mode 100644 index 0000000..315da9b --- /dev/null +++ b/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh | |||
@@ -0,0 +1,160 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
4 | |||
5 | ROOT_MOUNT="/rootfs" | ||
6 | MOUNT="/bin/mount" | ||
7 | UMOUNT="/bin/umount" | ||
8 | ROOT_RWDEVICE="tmpfs" | ||
9 | ROOT_ROMOUNT="/rfs/ro" | ||
10 | ROOT_RWMOUNT="/rfs/rw" | ||
11 | |||
12 | # Copied from initramfs-framework. The core of this script probably should be | ||
13 | # turned into initramfs-framework modules to reduce duplication. | ||
14 | udev_daemon() { | ||
15 | OPTIONS="/sbin/udev/udevd /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd" | ||
16 | |||
17 | for o in $OPTIONS; do | ||
18 | if [ -x "$o" ]; then | ||
19 | echo $o | ||
20 | return 0 | ||
21 | fi | ||
22 | done | ||
23 | |||
24 | return 1 | ||
25 | } | ||
26 | |||
27 | _UDEV_DAEMON=`udev_daemon` | ||
28 | |||
29 | early_setup() { | ||
30 | mkdir -p /proc | ||
31 | mkdir -p /sys | ||
32 | $MOUNT -t proc proc /proc | ||
33 | $MOUNT -t sysfs sysfs /sys | ||
34 | $MOUNT -t devtmpfs none /dev | ||
35 | |||
36 | # support modular kernel | ||
37 | modprobe isofs 2> /dev/null | ||
38 | |||
39 | mkdir -p /run | ||
40 | mkdir -p /var/run | ||
41 | |||
42 | $_UDEV_DAEMON --daemon | ||
43 | udevadm trigger --action=add | ||
44 | } | ||
45 | |||
46 | read_args() { | ||
47 | [ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline` | ||
48 | for arg in $CMDLINE; do | ||
49 | optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` | ||
50 | case $arg in | ||
51 | root=*) | ||
52 | ROOT_DEVICE=$optarg ;; | ||
53 | rootfstype=*) | ||
54 | modprobe $optarg 2> /dev/null ;; | ||
55 | rootrw=*) | ||
56 | ROOT_RWDEVICE=$optarg ;; | ||
57 | rootrwfstype=*) | ||
58 | modprobe $optarg 2> /dev/null ;; | ||
59 | video=*) | ||
60 | video_mode=$arg ;; | ||
61 | vga=*) | ||
62 | vga_mode=$arg ;; | ||
63 | console=*) | ||
64 | if [ -z "${console_params}" ]; then | ||
65 | console_params=$arg | ||
66 | else | ||
67 | console_params="$console_params $arg" | ||
68 | fi ;; | ||
69 | esac | ||
70 | done | ||
71 | } | ||
72 | |||
73 | fatal() { | ||
74 | echo $1 >$CONSOLE | ||
75 | echo >$CONSOLE | ||
76 | exec sh | ||
77 | } | ||
78 | |||
79 | early_setup | ||
80 | |||
81 | [ -z "$CONSOLE" ] && CONSOLE="/dev/console" | ||
82 | |||
83 | read_args | ||
84 | |||
85 | mount_and_boot() { | ||
86 | mkdir -p $ROOT_MOUNT $ROOT_ROMOUNT $ROOT_RWMOUNT | ||
87 | mknod /dev/loop0 b 7 0 2>/dev/null | ||
88 | |||
89 | # Mount read-only root filesystem into initramfs rootfs | ||
90 | if ! $MOUNT -o ro,noatime,nodiratime $ROOT_DEVICE $ROOT_ROMOUNT ; then | ||
91 | fatal "Could not mount read-only rootfs" | ||
92 | fi | ||
93 | |||
94 | # determine which unification filesystem to use | ||
95 | union_fs_type="" | ||
96 | if grep -w "overlay" /proc/filesystems; then | ||
97 | union_fs_type="overlay" | ||
98 | elif grep -w "aufs" /proc/filesystems; then | ||
99 | union_fs_type="aufs" | ||
100 | else | ||
101 | union_fs_type="" | ||
102 | fi | ||
103 | |||
104 | # Build mount options for read write root filesystem. | ||
105 | # If no read-write device was specified via kernel commandline, use tmpfs. | ||
106 | if [ "tmpfs" == $ROOT_RWDEVICE ]; then | ||
107 | ROOT_RWMOUNTOPTIONS="-t tmpfs -o rw,noatime,mode=755" | ||
108 | else | ||
109 | ROOT_RWMOUNTOPTIONS="-o rw,noatime,mode=755" | ||
110 | fi | ||
111 | |||
112 | # Mount read-write filesystem into initram rootfs | ||
113 | if ! $MOUNT $ROOT_RWMOUNTOPTIONS $ROOT_RWDEVICE $ROOT_RWMOUNT ; then | ||
114 | fatal "Could not mount read-write rootfs" | ||
115 | fi | ||
116 | |||
117 | # Create/Mount overlay root filesystem | ||
118 | case $union_fs_type in | ||
119 | "overlay") | ||
120 | mkdir -p $ROOT_RWMOUNT/upperdir $ROOT_RWMOUNT/work | ||
121 | $MOUNT -t overlay overlay -o "lowerdir=$ROOT_ROMOUNT,upperdir=$ROOT_RWMOUNT/upperdir,workdir=$ROOT_RWMOUNT/work" $ROOT_MOUNT | ||
122 | ;; | ||
123 | "aufs") | ||
124 | $MOUNT -t aufs -o "dirs=$ROOT_RWMOUNT=rw:$ROOT_ROMOUNT=ro" aufs $ROOT_MOUNT | ||
125 | ;; | ||
126 | "") | ||
127 | fatal "No overlay filesystem type available" | ||
128 | ;; | ||
129 | esac | ||
130 | |||
131 | # Move read-only and read-write root filesystem into the overlay filesystem | ||
132 | mkdir -p $ROOT_MOUNT/$ROOT_ROMOUNT $ROOT_MOUNT/$ROOT_RWMOUNT | ||
133 | $MOUNT --move $ROOT_ROMOUNT $ROOT_MOUNT/$ROOT_ROMOUNT | ||
134 | $MOUNT --move $ROOT_RWMOUNT $ROOT_MOUNT/$ROOT_RWMOUNT | ||
135 | |||
136 | # Watches the udev event queue, and exits if all current events are handled | ||
137 | udevadm settle --timeout=3 --quiet | ||
138 | # Kills the current udev running processes, which survived after | ||
139 | # device node creation events were handled, to avoid unexpected behavior | ||
140 | killall -9 "${_UDEV_DAEMON##*/}" 2>/dev/null | ||
141 | |||
142 | # Move the mount points of some filesystems over to | ||
143 | # the corresponding directories under the real root filesystem. | ||
144 | for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do | ||
145 | mkdir -p ${ROOT_MOUNT}/media/${dir##*/} | ||
146 | $MOUNT -n --move $dir ${ROOT_MOUNT}/media/${dir##*/} | ||
147 | done | ||
148 | $MOUNT -n --move /proc ${ROOT_MOUNT}/proc | ||
149 | $MOUNT -n --move /sys ${ROOT_MOUNT}/sys | ||
150 | $MOUNT -n --move /dev ${ROOT_MOUNT}/dev | ||
151 | |||
152 | cd $ROOT_MOUNT | ||
153 | |||
154 | # busybox switch_root supports -c option | ||
155 | exec switch_root -c /dev/console $ROOT_MOUNT /sbin/init $CMDLINE || | ||
156 | fatal "Couldn't switch_root, dropping to shell" | ||
157 | } | ||
158 | |||
159 | mount_and_boot | ||
160 | |||
diff --git a/recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb b/recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb new file mode 100644 index 0000000..7c2bdf6 --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-readonly-rootfs-overlay_1.0.bb | |||
@@ -0,0 +1,19 @@ | |||
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 | RDEPENDS_${PN} = "udev" | ||
6 | SRC_URI = "file://init-readonly-rootfs-overlay-boot.sh" | ||
7 | |||
8 | S = "${WORKDIR}" | ||
9 | |||
10 | do_install() { | ||
11 | install -m 0755 ${WORKDIR}/init-readonly-rootfs-overlay-boot.sh ${D}/init | ||
12 | install -d ${D}/dev | ||
13 | mknod -m 622 ${D}/dev/console c 5 1 | ||
14 | } | ||
15 | |||
16 | FILES_${PN} += " /init /dev " | ||
17 | |||
18 | # Due to kernel dependency | ||
19 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||
diff --git a/recipes-kernel/linux/linux-yocto_%.bbappend b/recipes-kernel/linux/linux-yocto_%.bbappend new file mode 100644 index 0000000..cc2bfe6 --- /dev/null +++ b/recipes-kernel/linux/linux-yocto_%.bbappend | |||
@@ -0,0 +1 @@ | |||
KERNEL_FEATURES_append = " features/overlayfs/overlayfs.scc" | |||