Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright (C) 2011 O.S. Systems Software LTDA. |
| 3 | # Licensed on MIT |
| 4 | |
| 5 | rootfs_enabled() { |
| 6 | return 0 |
| 7 | } |
| 8 | |
| 9 | rootfs_run() { |
| 10 | if [ -z "$ROOTFS_DIR" ]; then |
| 11 | return |
| 12 | fi |
| 13 | C=0 |
| 14 | delay=${bootparam_rootdelay:-1} |
| 15 | timeout=${bootparam_roottimeout:-5} |
| 16 | while [ ! -d $ROOTFS_DIR/dev ]; do |
| 17 | if [ $(( $C * $delay )) -gt $timeout ]; then |
| 18 | fatal "root '$bootparam_root' doesn't exist or does not contain a /dev." |
| 19 | fi |
| 20 | |
| 21 | if [ -n "$bootparam_root" ]; then |
| 22 | debug "No e2fs compatible filesystem has been mounted, mounting $bootparam_root..." |
| 23 | |
| 24 | if [ "`echo ${bootparam_root} | cut -c1-5`" = "UUID=" ]; then |
| 25 | root_uuid=`echo $bootparam_root | cut -c6-` |
| 26 | bootparam_root="/dev/disk/by-uuid/$root_uuid" |
| 27 | fi |
| 28 | |
| 29 | if [ "`echo ${bootparam_root} | cut -c1-9`" = "PARTUUID=" ]; then |
| 30 | root_uuid=`echo $bootparam_root | cut -c10-` |
| 31 | bootparam_root="/dev/disk/by-partuuid/$root_uuid" |
| 32 | fi |
| 33 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame^] | 34 | if [ "`echo ${bootparam_root} | cut -c1-10`" = "PARTLABEL=" ]; then |
| 35 | root_partlabel=`echo $bootparam_root | cut -c11-` |
| 36 | bootparam_root="/dev/disk/by-partlabel/$root_partlabel" |
| 37 | fi |
| 38 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 39 | if [ "`echo ${bootparam_root} | cut -c1-6`" = "LABEL=" ]; then |
| 40 | root_label=`echo $bootparam_root | cut -c7-` |
| 41 | bootparam_root="/dev/disk/by-label/$root_label" |
| 42 | fi |
| 43 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 44 | if [ -e "$bootparam_root" ]; then |
| 45 | flags="" |
| 46 | if [ -n "$bootparam_ro" ] && ! echo "$bootparam_rootflags" | grep -w -q "ro"; then |
| 47 | if [ -n "$bootparam_rootflags" ]; then |
| 48 | bootparam_rootflags="$bootparam_rootflags," |
| 49 | fi |
| 50 | bootparam_rootflags="${bootparam_rootflags}ro" |
| 51 | fi |
| 52 | if [ -n "$bootparam_rootflags" ]; then |
| 53 | flags="$flags -o$bootparam_rootflags" |
| 54 | fi |
| 55 | if [ -n "$bootparam_rootfstype" ]; then |
| 56 | flags="$flags -t$bootparam_rootfstype" |
| 57 | fi |
| 58 | mount $flags $bootparam_root $ROOTFS_DIR |
| 59 | if [ -d $ROOTFS_DIR/dev ]; then |
| 60 | break |
| 61 | else |
| 62 | # It is unlikely to change, but keep trying anyway. |
| 63 | # Perhaps we pick a different device next time. |
| 64 | umount $ROOTFS_DIR |
| 65 | fi |
| 66 | fi |
| 67 | fi |
| 68 | debug "Sleeping for $delay second(s) to wait root to settle..." |
| 69 | sleep $delay |
| 70 | C=$(( $C + 1 )) |
| 71 | done |
| 72 | } |