blob: ee24e82af3b69856b6d778c7bbef8e5893dbe55d [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/bin/sh
2# Copyright (C) 2011 O.S. Systems Software LTDA.
3# Licensed on MIT
4
5rootfs_enabled() {
6 return 0
7}
8
9rootfs_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 Geissler5a43b432020-06-13 10:46:56 -050016 while ! mountpoint -q $ROOTFS_DIR; do
Patrick Williamsc0f7c042017-02-23 20:41:17 -060017 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
Brad Bishop00e122a2019-10-05 11:10:57 -040030 root_partuuid=`echo $bootparam_root | cut -c10-`
31 bootparam_root="/dev/disk/by-partuuid/$root_partuuid"
32 fi
33
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"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060037 fi
38
Brad Bishopa34c0302019-09-23 22:34:48 -040039 if [ "`echo ${bootparam_root} | cut -c1-10`" = "PARTLABEL=" ]; then
40 root_partlabel=`echo $bootparam_root | cut -c11-`
41 bootparam_root="/dev/disk/by-partlabel/$root_partlabel"
42 fi
43
Brad Bishop316dfdd2018-06-25 12:45:53 -040044 if [ "`echo ${bootparam_root} | cut -c1-6`" = "LABEL=" ]; then
45 root_label=`echo $bootparam_root | cut -c7-`
46 bootparam_root="/dev/disk/by-label/$root_label"
47 fi
48
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049 if [ -e "$bootparam_root" ]; then
50 flags=""
51 if [ -n "$bootparam_ro" ] && ! echo "$bootparam_rootflags" | grep -w -q "ro"; then
52 if [ -n "$bootparam_rootflags" ]; then
53 bootparam_rootflags="$bootparam_rootflags,"
54 fi
55 bootparam_rootflags="${bootparam_rootflags}ro"
56 fi
57 if [ -n "$bootparam_rootflags" ]; then
58 flags="$flags -o$bootparam_rootflags"
59 fi
60 if [ -n "$bootparam_rootfstype" ]; then
61 flags="$flags -t$bootparam_rootfstype"
62 fi
63 mount $flags $bootparam_root $ROOTFS_DIR
Andrew Geissler5a43b432020-06-13 10:46:56 -050064 if mountpoint -q $ROOTFS_DIR; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -060065 break
66 else
67 # It is unlikely to change, but keep trying anyway.
68 # Perhaps we pick a different device next time.
69 umount $ROOTFS_DIR
70 fi
71 fi
72 fi
73 debug "Sleeping for $delay second(s) to wait root to settle..."
74 sleep $delay
75 C=$(( $C + 1 ))
76 done
77}