diff options
| -rw-r--r-- | recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh | 40 |
1 files changed, 29 insertions, 11 deletions
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 c777eec..ff6a774 100644 --- a/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh +++ b/recipes-core/initrdscripts/files/init-readonly-rootfs-overlay-boot.sh | |||
| @@ -37,14 +37,14 @@ read_args() { | |||
| 37 | ROOT_RODEVICE=$optarg ;; | 37 | ROOT_RODEVICE=$optarg ;; |
| 38 | rootfstype=*) | 38 | rootfstype=*) |
| 39 | modprobe $optarg 2> /dev/null || \ | 39 | modprobe $optarg 2> /dev/null || \ |
| 40 | echo "Could not load $optarg module";; | 40 | log "Could not load $optarg module";; |
| 41 | rootinit=*) | 41 | rootinit=*) |
| 42 | ROOT_ROINIT=$optarg ;; | 42 | ROOT_ROINIT=$optarg ;; |
| 43 | rootrw=*) | 43 | rootrw=*) |
| 44 | ROOT_RWDEVICE=$optarg ;; | 44 | ROOT_RWDEVICE=$optarg ;; |
| 45 | rootrwfstype=*) | 45 | rootrwfstype=*) |
| 46 | modprobe $optarg 2> /dev/null || \ | 46 | modprobe $optarg 2> /dev/null || \ |
| 47 | echo "Could not load $optarg module";; | 47 | log "Could not load $optarg module";; |
| 48 | rootrwreset=*) | 48 | rootrwreset=*) |
| 49 | ROOT_RWRESET=$optarg ;; | 49 | ROOT_RWRESET=$optarg ;; |
| 50 | init=*) | 50 | init=*) |
| @@ -54,11 +54,15 @@ read_args() { | |||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | fatal() { | 56 | fatal() { |
| 57 | echo $1 >$CONSOLE | 57 | echo "rorootfs-overlay: $1" >$CONSOLE |
| 58 | echo >$CONSOLE | 58 | echo >$CONSOLE |
| 59 | exec sh | 59 | exec sh |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | log() { | ||
| 63 | echo "rorootfs-overlay: $1" >$CONSOLE | ||
| 64 | } | ||
| 65 | |||
| 62 | early_setup | 66 | early_setup |
| 63 | 67 | ||
| 64 | [ -z "${CONSOLE+x}" ] && CONSOLE="/dev/console" | 68 | [ -z "${CONSOLE+x}" ] && CONSOLE="/dev/console" |
| @@ -71,20 +75,27 @@ mount_and_boot() { | |||
| 71 | # Build mount options for read only root file system. | 75 | # Build mount options for read only root file system. |
| 72 | # If no read-only device was specified via kernel command line, use | 76 | # If no read-only device was specified via kernel command line, use |
| 73 | # current root file system via bind mount. | 77 | # current root file system via bind mount. |
| 74 | ROOT_ROMOUNTOPTIONS_BIND="-o bind,ro /" | 78 | ROOT_ROMOUNTOPTIONS_BIND="-o bind /" |
| 75 | if [ -z "${ROOT_RODEVICE}" ]; then | 79 | if [ -z "${ROOT_RODEVICE}" ]; then |
| 76 | ROOT_ROMOUNTOPTIONS="${ROOT_ROMOUNTOPTIONS_BIND}" | 80 | ROOT_ROMOUNTOPTIONS="${ROOT_ROMOUNTOPTIONS_BIND}" |
| 77 | else | 81 | else |
| 78 | ROOT_ROMOUNTOPTIONS="-o ro,noatime,nodiratime $ROOT_RODEVICE" | 82 | ROOT_ROMOUNTOPTIONS="-o noatime,nodiratime $ROOT_RODEVICE" |
| 79 | fi | 83 | fi |
| 80 | 84 | ||
| 81 | # Mount root file system as read-only to mount-point, if unsuccessful, | 85 | # Mount root file system to new mount-point, if unsuccessful, try bind |
| 82 | # try bind mount current rootfs | 86 | # mounting current root file system. |
| 83 | if ! $MOUNT $ROOT_ROMOUNTOPTIONS $ROOT_ROMOUNT && \ | 87 | if ! $MOUNT $ROOT_ROMOUNTOPTIONS "$ROOT_ROMOUNT" 2>/dev/null && \ |
| 84 | ! $MOUNT $ROOT_ROMOUNTOPTIONS_BIND $ROOT_ROMOUNT; then | 88 | [ "x$ROOT_ROMOUNTOPTIONS_BIND" == "x$ROOT_ROMOUNTOPTIONS" ] || \ |
| 89 | log "Could not mount $ROOT_RODEVICE, bind mounting..." && \ | ||
| 90 | ! $MOUNT $ROOT_ROMOUNTOPTIONS_BIND "$ROOT_ROMOUNT"; then | ||
| 85 | fatal "Could not mount read-only rootfs" | 91 | fatal "Could not mount read-only rootfs" |
| 86 | fi | 92 | fi |
| 87 | 93 | ||
| 94 | # Remounting root file system as read only. | ||
| 95 | if ! $MOUNT -o remount,ro "$ROOT_ROMOUNT"; then | ||
| 96 | fatal "Could not remount read-only rootfs as read only" | ||
| 97 | fi | ||
| 98 | |||
| 88 | # If future init is the same as current file, use $ROOT_ROINIT | 99 | # If future init is the same as current file, use $ROOT_ROINIT |
| 89 | # Tries to avoid loop to infinity if init is set to current file via | 100 | # Tries to avoid loop to infinity if init is set to current file via |
| 90 | # kernel command line | 101 | # kernel command line |
| @@ -125,10 +136,17 @@ mount_and_boot() { | |||
| 125 | case $union_fs_type in | 136 | case $union_fs_type in |
| 126 | "overlay") | 137 | "overlay") |
| 127 | mkdir -p $ROOT_RWMOUNT/upperdir $ROOT_RWMOUNT/work | 138 | mkdir -p $ROOT_RWMOUNT/upperdir $ROOT_RWMOUNT/work |
| 128 | $MOUNT -t overlay overlay -o "lowerdir=$ROOT_ROMOUNT,upperdir=$ROOT_RWMOUNT/upperdir,workdir=$ROOT_RWMOUNT/work" $ROOT_MOUNT | 139 | $MOUNT -t overlay overlay \ |
| 140 | -o "$(printf "%s%s%s" \ | ||
| 141 | "lowerdir=$ROOT_ROMOUNT," \ | ||
| 142 | "upperdir=$ROOT_RWMOUNT/upperdir," \ | ||
| 143 | "workdir=$ROOT_RWMOUNT/work")" \ | ||
| 144 | $ROOT_MOUNT | ||
| 129 | ;; | 145 | ;; |
| 130 | "aufs") | 146 | "aufs") |
| 131 | $MOUNT -t aufs -o "dirs=$ROOT_RWMOUNT=rw:$ROOT_ROMOUNT=ro" aufs $ROOT_MOUNT | 147 | $MOUNT -t aufs i\ |
| 148 | -o "dirs=$ROOT_RWMOUNT=rw:$ROOT_ROMOUNT=ro" \ | ||
| 149 | aufs $ROOT_MOUNT | ||
| 132 | ;; | 150 | ;; |
| 133 | "") | 151 | "") |
| 134 | fatal "No overlay filesystem type available" | 152 | fatal "No overlay filesystem type available" |
