summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudius Heine <ch@denx.de>2017-09-28 11:13:50 +0200
committerClaudius Heine <ch@denx.de>2017-09-28 11:13:50 +0200
commit3886705680f0f0e1fccaa68229597878fa2ce7a3 (patch)
treeea01032eb96b424c3e0f5187978f9a797d132919
parent5200c58a72e660b1bf1fc4b9a08fd16c47550ce4 (diff)
downloadmeta-readonly-rootfs-overlay-3886705680f0f0e1fccaa68229597878fa2ce7a3.tar.gz
Implemented 'rootoptions' and 'rootrwoptions' kernel parameters
These parameters allow to change the mount options of the read-only and read-write filesystems via the kernel commandline. Signed-off-by: Claudius Heine <ch@denx.de>
-rw-r--r--README.md14
-rw-r--r--recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh47
2 files changed, 45 insertions, 16 deletions
diff --git a/README.md b/README.md
index ec1aa07..07fb6ad 100644
--- a/README.md
+++ b/README.md
@@ -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
135specified, the current rootfs is used. 135specified, 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
138kernel, you can specify the required module name here. 138kernel, you can specify the required module name here. It will also be used in
139the mount command.
140
141`rootoptions=` specifies the mount options of the read-only file system.
142Defaults 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.
144specified, `tmpfs` is used. 148specified, `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
147kernel, you can specify the required module name here. 151kernel, you can specify the required module name here. It will also be used in
152the mount command.
153
154`rootrwoptions=` specifies the mount options of the read-write file system.
155Defaults 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
150read-write file system prior to building the overlay root files system. 158read-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"
18ROOT_RWMOUNT="/media/rfs/rw" 18ROOT_RWMOUNT="/media/rfs/rw"
19ROOT_RWRESET="no" 19ROOT_RWRESET="no"
20 20
21ROOT_ROFSTYPE=""
22ROOT_ROMOUNTOPTIONS="bind"
23ROOT_ROMOUNTOPTIONS_DEVICE="noatime,nodiratime"
24
25ROOT_RWFSTYPE=""
26ROOT_RWMOUNTOPTIONS="rw,noatime,mode=755 tmpfs"
27ROOT_RWMOUNTOPTIONS_DEVICE="rw,noatime,mode=755"
28
21early_setup() { 29early_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