#!/bin/sh

type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh

for root in $(getargs rootfallback=); do
    root=$(label_uuid_to_dev "$root")

    if ! [ -b "$root" ]; then
        warn "Could not find rootfallback $root"
        continue
    fi

    ext2=$( blkid "$root" | sed -e 's/.*TYPE="*//' -e 's/[" ].*//' )
    #?         _fstype="$(find_mp_fstype /)"
    [ -z "$ext2" ] && ext2=ext2
    [ "$ext2" = ext2 ] && modprobe ext4 && lsmod | grep -q ext4 && ext2=ext4

    if mount -t $ext2 "$root" /sysroot; then
        info "Mounted rootfallback -t $ext2 $root"
        exit 0
    fi

    warn "Failed to mount rootfallback -t $ext2 $root"
    exit 1
done

[ -e "$job" ] && rm -f "$job"
