83 lines
2.6 KiB
Bash
83 lines
2.6 KiB
Bash
#!/bin/sh
|
|
# Copyright (C) 2011 O.S. Systems Software LTDA.
|
|
# Licensed on MIT
|
|
|
|
rootfs_enabled() {
|
|
return 0
|
|
}
|
|
|
|
e2fsck_check() {
|
|
if [ -n "`which e2fsck`" ]; then
|
|
fsckout=`e2fsck -p -v ${1}`
|
|
fsckret=$?
|
|
# Avoid empty newline after summary
|
|
echo "e2fsck: ${fsckout}" >/dev/kmsg
|
|
# Return code >= 4 means uncorrected / operational error
|
|
## TODO: force boot into a recovery mode or similar, as there is really not
|
|
## much we can do in case the fs is corrupted in a bad way
|
|
if [ "${fsckret}" -ge "4" ]; then
|
|
echo "e2fsck: WARNING: file system errors left uncorrected: ret ${fsckret}" >/dev/kmsg
|
|
fi
|
|
fi
|
|
}
|
|
|
|
rootfs_run() {
|
|
if [ -z "$ROOTFS_DIR" ]; then
|
|
return
|
|
fi
|
|
C=0
|
|
delay=${bootparam_rootdelay:-1}
|
|
timeout=${bootparam_roottimeout:-5}
|
|
while ! mountpoint -q $ROOTFS_DIR; do
|
|
if [ $(( $C * $delay )) -gt $timeout ]; then
|
|
fatal "root '$bootparam_root' doesn't exist or does not contain a /dev."
|
|
fi
|
|
|
|
if [ -n "$bootparam_root" ]; then
|
|
debug "No e2fs compatible filesystem has been mounted, mounting $bootparam_root..."
|
|
|
|
if [ "`echo ${bootparam_root} | cut -c1-5`" = "UUID=" ]; then
|
|
root_uuid=`echo $bootparam_root | cut -c6-`
|
|
bootparam_root="/dev/disk/by-uuid/$root_uuid"
|
|
elif [ "`echo ${bootparam_root} | cut -c1-9`" = "PARTUUID=" ]; then
|
|
root_partuuid=`echo $bootparam_root | cut -c10-`
|
|
bootparam_root="/dev/disk/by-partuuid/$root_partuuid"
|
|
elif [ "`echo ${bootparam_root} | cut -c1-10`" = "PARTLABEL=" ]; then
|
|
root_partlabel=`echo $bootparam_root | cut -c11-`
|
|
bootparam_root="/dev/disk/by-partlabel/$root_partlabel"
|
|
elif [ "`echo ${bootparam_root} | cut -c1-6`" = "LABEL=" ]; then
|
|
root_label=`echo $bootparam_root | cut -c7-`
|
|
bootparam_root="/dev/disk/by-label/$root_label"
|
|
fi
|
|
|
|
if [ -e "$bootparam_root" ]; then
|
|
e2fsck_check ${bootparam_root}
|
|
flags=""
|
|
if [ -n "$bootparam_ro" ] && ! echo "$bootparam_rootflags" | grep -w -q "ro"; then
|
|
if [ -n "$bootparam_rootflags" ]; then
|
|
bootparam_rootflags="$bootparam_rootflags,"
|
|
fi
|
|
bootparam_rootflags="${bootparam_rootflags}ro"
|
|
fi
|
|
if [ -n "$bootparam_rootflags" ]; then
|
|
flags="$flags -o$bootparam_rootflags"
|
|
fi
|
|
if [ -n "$bootparam_rootfstype" ]; then
|
|
flags="$flags -t$bootparam_rootfstype"
|
|
fi
|
|
mount $flags $bootparam_root $ROOTFS_DIR
|
|
if mountpoint -q $ROOTFS_DIR; then
|
|
break
|
|
else
|
|
# It is unlikely to change, but keep trying anyway.
|
|
# Perhaps we pick a different device next time.
|
|
umount $ROOTFS_DIR
|
|
fi
|
|
fi
|
|
fi
|
|
debug "Sleeping for $delay second(s) to wait root to settle..."
|
|
sleep $delay
|
|
C=$(( $C + 1 ))
|
|
done
|
|
}
|