From 3886705680f0f0e1fccaa68229597878fa2ce7a3 Mon Sep 17 00:00:00 2001 From: Claudius Heine Date: Thu, 28 Sep 2017 11:13:50 +0200 Subject: 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 --- README.md | 14 +++++-- .../files/init-readonly-rootfs-overlay-boot.sh | 47 ++++++++++++++++------ 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` `root=` specifies the read-only root file system device. If this is not specified, the current rootfs is used. -`rootfstype=` if support for the-read only file system is not build into the -kernel, you can specify the required module name here. +`rootfstype=` if support for the read-only file system is not build into the +kernel, you can specify the required module name here. It will also be used in +the mount command. + +`rootoptions=` specifies the mount options of the read-only file system. +Defaults to `noatime,nodiratime`. `rootinit=` if the `init` parameter was used to specify this init script, `rootinit` can be used to overwrite the default (`/sbin/init`). @@ -144,7 +148,11 @@ kernel, you can specify the required module name here. specified, `tmpfs` is used. `rootrwfstype=` if support for the read-write file system is not build into the -kernel, you can specify the required module name here. +kernel, you can specify the required module name here. It will also be used in +the mount command. + +`rootrwoptions=` specifies the mount options of the read-write file system. +Defaults to `rw,noatime,mode=755`. `rootrwreset=` set to `yes` if you want to delete all the files in the 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" ROOT_RWMOUNT="/media/rfs/rw" ROOT_RWRESET="no" +ROOT_ROFSTYPE="" +ROOT_ROMOUNTOPTIONS="bind" +ROOT_ROMOUNTOPTIONS_DEVICE="noatime,nodiratime" + +ROOT_RWFSTYPE="" +ROOT_RWMOUNTOPTIONS="rw,noatime,mode=755 tmpfs" +ROOT_RWMOUNTOPTIONS_DEVICE="rw,noatime,mode=755" + early_setup() { mkdir -p /proc mkdir -p /sys @@ -36,17 +44,23 @@ read_args() { root=*) ROOT_RODEVICE=$optarg ;; rootfstype=*) + ROOT_ROFSTYPE="$optarg" modprobe $optarg 2> /dev/null || \ log "Could not load $optarg module";; rootinit=*) ROOT_ROINIT=$optarg ;; + rootoptions=*) + ROOT_ROMOUNTOPTIONS_DEVICE="$optarg" ;; rootrw=*) ROOT_RWDEVICE=$optarg ;; rootrwfstype=*) + ROOT_RWFSTYPE="$optarg" modprobe $optarg 2> /dev/null || \ log "Could not load $optarg module";; rootrwreset=*) ROOT_RWRESET=$optarg ;; + rootrwoptions=*) + ROOT_RWMOUNTOPTIONS_DEVICE="$optarg" ;; init=*) INIT=$optarg ;; esac @@ -75,19 +89,22 @@ mount_and_boot() { # Build mount options for read only root file system. # If no read-only device was specified via kernel command line, use # current root file system via bind mount. - ROOT_ROMOUNTOPTIONS_BIND="-o bind /" - if [ -z "${ROOT_RODEVICE}" ]; then - ROOT_ROMOUNTOPTIONS="${ROOT_ROMOUNTOPTIONS_BIND}" + ROOT_ROMOUNTPARAMS_BIND="-o ${ROOT_ROMOUNTOPTIONS} /" + if [ -n "${ROOT_RODEVICE}" ]; then + ROOT_ROMOUNTPARAMS="-o ${ROOT_ROMOUNTOPTIONS_DEVICE} $ROOT_RODEVICE" + if [ -n "${ROOT_ROFSTYPE}" ]; then + ROOT_ROMOUNTPARAMS="-t $ROOT_ROFSTYPE $ROOT_ROMOUNTPARAMS" + fi else - ROOT_ROMOUNTOPTIONS="-o noatime,nodiratime $ROOT_RODEVICE" + ROOT_ROMOUNTPARAMS="$ROOT_ROMOUNTPARAMS_BIND" fi # Mount root file system to new mount-point, if unsuccessful, try bind # mounting current root file system. - if ! $MOUNT $ROOT_ROMOUNTOPTIONS "$ROOT_ROMOUNT" 2>/dev/null && \ - [ "x$ROOT_ROMOUNTOPTIONS_BIND" == "x$ROOT_ROMOUNTOPTIONS" ] || \ + if ! $MOUNT $ROOT_ROMOUNTPARAMS "$ROOT_ROMOUNT" 2>/dev/null && \ + [ "x$ROOT_ROMOUNTPARAMS_BIND" == "x$ROOT_ROMOUNTPARAMS" ] || \ log "Could not mount $ROOT_RODEVICE, bind mounting..." && \ - ! $MOUNT $ROOT_ROMOUNTOPTIONS_BIND "$ROOT_ROMOUNT"; then + ! $MOUNT $ROOT_ROMOUNTPARAMS_BIND "$ROOT_ROMOUNT"; then fatal "Could not mount read-only rootfs" fi @@ -104,16 +121,20 @@ mount_and_boot() { fi # Build mount options for read write root file system. - # If no read-write device was specified via kernel command line, use - # tmpfs. - if [ -z "${ROOT_RWDEVICE}" ]; then - ROOT_RWMOUNTOPTIONS="-t tmpfs -o rw,noatime,mode=755 tmpfs" + # If a read-write device was specified via kernel command line, use + # it, otherwise default to tmpfs. + if [ -n "${ROOT_RWDEVICE}" ]; then + + ROOT_RWMOUNTPARAMS="-o $ROOT_RWMOUNTOPTIONS_DEVICE $ROOT_RWDEVICE" + if [ -n "${ROOT_RWFSTYPE}" ]; then + ROOT_RWMOUNTPARAMS="-t $ROOT_RWFSTYPE $ROOT_RWMOUNTPARAMS" + fi else - ROOT_RWMOUNTOPTIONS="-o rw,noatime,mode=755 $ROOT_RWDEVICE" + ROOT_RWMOUNTPARAMS="-t tmpfs -o $ROOT_RWMOUNTOPTIONS" fi # Mount read-write file system into initram root file system - if ! $MOUNT $ROOT_RWMOUNTOPTIONS $ROOT_RWMOUNT ; then + if ! $MOUNT $ROOT_RWMOUNTPARAMS $ROOT_RWMOUNT ; then fatal "Could not mount read-write rootfs" fi -- cgit v1.2.3-54-g00ecf