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} |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 16 | while ! mountpoint -q $ROOTFS_DIR; do |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 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" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame^] | 27 | elif [ "`echo ${bootparam_root} | cut -c1-9`" = "PARTUUID=" ]; then |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 28 | root_partuuid=`echo $bootparam_root | cut -c10-` |
| 29 | bootparam_root="/dev/disk/by-partuuid/$root_partuuid" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame^] | 30 | elif [ "`echo ${bootparam_root} | cut -c1-10`" = "PARTLABEL=" ]; then |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 31 | root_partlabel=`echo $bootparam_root | cut -c11-` |
| 32 | bootparam_root="/dev/disk/by-partlabel/$root_partlabel" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame^] | 33 | elif [ "`echo ${bootparam_root} | cut -c1-6`" = "LABEL=" ]; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 34 | root_label=`echo $bootparam_root | cut -c7-` |
| 35 | bootparam_root="/dev/disk/by-label/$root_label" |
| 36 | fi |
| 37 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 38 | if [ -e "$bootparam_root" ]; then |
| 39 | flags="" |
| 40 | if [ -n "$bootparam_ro" ] && ! echo "$bootparam_rootflags" | grep -w -q "ro"; then |
| 41 | if [ -n "$bootparam_rootflags" ]; then |
| 42 | bootparam_rootflags="$bootparam_rootflags," |
| 43 | fi |
| 44 | bootparam_rootflags="${bootparam_rootflags}ro" |
| 45 | fi |
| 46 | if [ -n "$bootparam_rootflags" ]; then |
| 47 | flags="$flags -o$bootparam_rootflags" |
| 48 | fi |
| 49 | if [ -n "$bootparam_rootfstype" ]; then |
| 50 | flags="$flags -t$bootparam_rootfstype" |
| 51 | fi |
| 52 | mount $flags $bootparam_root $ROOTFS_DIR |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 53 | if mountpoint -q $ROOTFS_DIR; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 54 | break |
| 55 | else |
| 56 | # It is unlikely to change, but keep trying anyway. |
| 57 | # Perhaps we pick a different device next time. |
| 58 | umount $ROOTFS_DIR |
| 59 | fi |
| 60 | fi |
| 61 | fi |
| 62 | debug "Sleeping for $delay second(s) to wait root to settle..." |
| 63 | sleep $delay |
| 64 | C=$(( $C + 1 )) |
| 65 | done |
| 66 | } |