diff options
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh | 47 |
2 files changed, 45 insertions, 16 deletions
@@ -134,8 +134,12 @@ The same as before but it now starts `/bin/sh` instead of `/sbin/init` | |||
134 | `root=` specifies the read-only root file system device. If this is not | 134 | `root=` specifies the read-only root file system device. If this is not |
135 | specified, the current rootfs is used. | 135 | specified, the current rootfs is used. |
136 | 136 | ||
137 | `rootfstype=` if support for the-read only file system is not build into the | 137 | `rootfstype=` if support for the read-only file system is not build into the |
138 | kernel, you can specify the required module name here. | 138 | kernel, you can specify the required module name here. It will also be used in |
139 | the mount command. | ||
140 | |||
141 | `rootoptions=` specifies the mount options of the read-only file system. | ||
142 | Defaults to `noatime,nodiratime`. | ||
139 | 143 | ||
140 | `rootinit=` if the `init` parameter was used to specify this init script, | 144 | `rootinit=` if the `init` parameter was used to specify this init script, |
141 | `rootinit` can be used to overwrite the default (`/sbin/init`). | 145 | `rootinit` can be used to overwrite the default (`/sbin/init`). |
@@ -144,7 +148,11 @@ kernel, you can specify the required module name here. | |||
144 | specified, `tmpfs` is used. | 148 | specified, `tmpfs` is used. |
145 | 149 | ||
146 | `rootrwfstype=` if support for the read-write file system is not build into the | 150 | `rootrwfstype=` if support for the read-write file system is not build into the |
147 | kernel, you can specify the required module name here. | 151 | kernel, you can specify the required module name here. It will also be used in |
152 | the mount command. | ||
153 | |||
154 | `rootrwoptions=` specifies the mount options of the read-write file system. | ||
155 | Defaults to `rw,noatime,mode=755`. | ||
148 | 156 | ||
149 | `rootrwreset=` set to `yes` if you want to delete all the files in the | 157 | `rootrwreset=` set to `yes` if you want to delete all the files in the |
150 | read-write file system prior to building the overlay root files system. | 158 | read-write file system prior to building the overlay root files system. |
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 ff6a774..be62db0 100644 --- a/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh +++ b/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh | |||
@@ -18,6 +18,14 @@ ROOT_ROMOUNT="/media/rfs/ro" | |||
18 | ROOT_RWMOUNT="/media/rfs/rw" | 18 | ROOT_RWMOUNT="/media/rfs/rw" |
19 | ROOT_RWRESET="no" | 19 | ROOT_RWRESET="no" |
20 | 20 | ||
21 | ROOT_ROFSTYPE="" | ||
22 | ROOT_ROMOUNTOPTIONS="bind" | ||
23 | ROOT_ROMOUNTOPTIONS_DEVICE="noatime,nodiratime" | ||
24 | |||
25 | ROOT_RWFSTYPE="" | ||
26 | ROOT_RWMOUNTOPTIONS="rw,noatime,mode=755 tmpfs" | ||
27 | ROOT_RWMOUNTOPTIONS_DEVICE="rw,noatime,mode=755" | ||
28 | |||
21 | early_setup() { | 29 | early_setup() { |
22 | mkdir -p /proc | 30 | mkdir -p /proc |
23 | mkdir -p /sys | 31 | mkdir -p /sys |
@@ -36,17 +44,23 @@ read_args() { | |||
36 | root=*) | 44 | root=*) |
37 | ROOT_RODEVICE=$optarg ;; | 45 | ROOT_RODEVICE=$optarg ;; |
38 | rootfstype=*) | 46 | rootfstype=*) |
47 | ROOT_ROFSTYPE="$optarg" | ||
39 | modprobe $optarg 2> /dev/null || \ | 48 | modprobe $optarg 2> /dev/null || \ |
40 | log "Could not load $optarg module";; | 49 | log "Could not load $optarg module";; |
41 | rootinit=*) | 50 | rootinit=*) |
42 | ROOT_ROINIT=$optarg ;; | 51 | ROOT_ROINIT=$optarg ;; |
52 | rootoptions=*) | ||
53 | ROOT_ROMOUNTOPTIONS_DEVICE="$optarg" ;; | ||
43 | rootrw=*) | 54 | rootrw=*) |
44 | ROOT_RWDEVICE=$optarg ;; | 55 | ROOT_RWDEVICE=$optarg ;; |
45 | rootrwfstype=*) | 56 | rootrwfstype=*) |
57 | ROOT_RWFSTYPE="$optarg" | ||
46 | modprobe $optarg 2> /dev/null || \ | 58 | modprobe $optarg 2> /dev/null || \ |
47 | log "Could not load $optarg module";; | 59 | log "Could not load $optarg module";; |
48 | rootrwreset=*) | 60 | rootrwreset=*) |
49 | ROOT_RWRESET=$optarg ;; | 61 | ROOT_RWRESET=$optarg ;; |
62 | rootrwoptions=*) | ||
63 | ROOT_RWMOUNTOPTIONS_DEVICE="$optarg" ;; | ||
50 | init=*) | 64 | init=*) |
51 | INIT=$optarg ;; | 65 | INIT=$optarg ;; |
52 | esac | 66 | esac |
@@ -75,19 +89,22 @@ mount_and_boot() { | |||
75 | # Build mount options for read only root file system. | 89 | # Build mount options for read only root file system. |
76 | # If no read-only device was specified via kernel command line, use | 90 | # If no read-only device was specified via kernel command line, use |
77 | # current root file system via bind mount. | 91 | # current root file system via bind mount. |
78 | ROOT_ROMOUNTOPTIONS_BIND="-o bind /" | 92 | ROOT_ROMOUNTPARAMS_BIND="-o ${ROOT_ROMOUNTOPTIONS} /" |
79 | if [ -z "${ROOT_RODEVICE}" ]; then | 93 | if [ -n "${ROOT_RODEVICE}" ]; then |
80 | ROOT_ROMOUNTOPTIONS="${ROOT_ROMOUNTOPTIONS_BIND}" | 94 | ROOT_ROMOUNTPARAMS="-o ${ROOT_ROMOUNTOPTIONS_DEVICE} $ROOT_RODEVICE" |
95 | if [ -n "${ROOT_ROFSTYPE}" ]; then | ||
96 | ROOT_ROMOUNTPARAMS="-t $ROOT_ROFSTYPE $ROOT_ROMOUNTPARAMS" | ||
97 | fi | ||
81 | else | 98 | else |
82 | ROOT_ROMOUNTOPTIONS="-o noatime,nodiratime $ROOT_RODEVICE" | 99 | ROOT_ROMOUNTPARAMS="$ROOT_ROMOUNTPARAMS_BIND" |
83 | fi | 100 | fi |
84 | 101 | ||
85 | # Mount root file system to new mount-point, if unsuccessful, try bind | 102 | # Mount root file system to new mount-point, if unsuccessful, try bind |
86 | # mounting current root file system. | 103 | # mounting current root file system. |
87 | if ! $MOUNT $ROOT_ROMOUNTOPTIONS "$ROOT_ROMOUNT" 2>/dev/null && \ | 104 | if ! $MOUNT $ROOT_ROMOUNTPARAMS "$ROOT_ROMOUNT" 2>/dev/null && \ |
88 | [ "x$ROOT_ROMOUNTOPTIONS_BIND" == "x$ROOT_ROMOUNTOPTIONS" ] || \ | 105 | [ "x$ROOT_ROMOUNTPARAMS_BIND" == "x$ROOT_ROMOUNTPARAMS" ] || \ |
89 | log "Could not mount $ROOT_RODEVICE, bind mounting..." && \ | 106 | log "Could not mount $ROOT_RODEVICE, bind mounting..." && \ |
90 | ! $MOUNT $ROOT_ROMOUNTOPTIONS_BIND "$ROOT_ROMOUNT"; then | 107 | ! $MOUNT $ROOT_ROMOUNTPARAMS_BIND "$ROOT_ROMOUNT"; then |
91 | fatal "Could not mount read-only rootfs" | 108 | fatal "Could not mount read-only rootfs" |
92 | fi | 109 | fi |
93 | 110 | ||
@@ -104,16 +121,20 @@ mount_and_boot() { | |||
104 | fi | 121 | fi |
105 | 122 | ||
106 | # Build mount options for read write root file system. | 123 | # Build mount options for read write root file system. |
107 | # If no read-write device was specified via kernel command line, use | 124 | # If a read-write device was specified via kernel command line, use |
108 | # tmpfs. | 125 | # it, otherwise default to tmpfs. |
109 | if [ -z "${ROOT_RWDEVICE}" ]; then | 126 | if [ -n "${ROOT_RWDEVICE}" ]; then |
110 | ROOT_RWMOUNTOPTIONS="-t tmpfs -o rw,noatime,mode=755 tmpfs" | 127 | |
128 | ROOT_RWMOUNTPARAMS="-o $ROOT_RWMOUNTOPTIONS_DEVICE $ROOT_RWDEVICE" | ||
129 | if [ -n "${ROOT_RWFSTYPE}" ]; then | ||
130 | ROOT_RWMOUNTPARAMS="-t $ROOT_RWFSTYPE $ROOT_RWMOUNTPARAMS" | ||
131 | fi | ||
111 | else | 132 | else |
112 | ROOT_RWMOUNTOPTIONS="-o rw,noatime,mode=755 $ROOT_RWDEVICE" | 133 | ROOT_RWMOUNTPARAMS="-t tmpfs -o $ROOT_RWMOUNTOPTIONS" |
113 | fi | 134 | fi |
114 | 135 | ||
115 | # Mount read-write file system into initram root file system | 136 | # Mount read-write file system into initram root file system |
116 | if ! $MOUNT $ROOT_RWMOUNTOPTIONS $ROOT_RWMOUNT ; then | 137 | if ! $MOUNT $ROOT_RWMOUNTPARAMS $ROOT_RWMOUNT ; then |
117 | fatal "Could not mount read-write rootfs" | 138 | fatal "Could not mount read-write rootfs" |
118 | fi | 139 | fi |
119 | 140 | ||