File: mount-usr.sh

package info (click to toggle)
dracut 109-9
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,872 kB
  • sloc: sh: 24,527; ansic: 5,234; makefile: 346; perl: 186; python: 48; javascript: 19
file content (93 lines) | stat: -rwxr-xr-x 2,800 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh

command -v info > /dev/null || . /lib/dracut-lib.sh
command -v fsck_single > /dev/null || . /lib/fs-lib.sh

filtersubvol() {
    local _oldifs
    _oldifs="$IFS"
    local IFS=","
    # shellcheck disable=SC2086
    set -- $1
    IFS="$_oldifs"
    while [ $# -gt 0 ]; do
        case $1 in
            'subvol='*) : ;;
            *) printf '%s' "${1}," ;;
        esac
        shift
    done
}

fsck_usr() {
    local _dev="$1"
    local _fs="$2"
    local _fsopts="$3"
    local _fsckoptions

    if getargbool 0 forcefsck; then
        _fsckoptions="-f $_fsckoptions"
    fi

    fsck_single "$_dev" "$_fs" "$_fsopts" "$_fsckoptions"
}

mount_usr() {
    local _dev _mp _fs _opts _ _usr_found _ _freq _passno
    # check, if we have to mount the /usr filesystem
    while read -r _dev _mp _fs _opts _freq _passno || [ -n "$_dev" ]; do
        [ "${_dev%%#*}" != "$_dev" ] && continue
        if [ "$_mp" = "/usr" ]; then
            case "$_dev" in
                LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
                    _dev="$(label_uuid_to_dev "$_dev")"
                    ;;
                *) ;;
            esac

            if strstr "$_opts" "subvol=" \
                && [ "${root#block:}" -ef "$_dev" ] \
                && [ -n "$rflags" ]; then
                # for btrfs subvolumes we have to mount /usr with the same rflags
                rflags=$(filtersubvol "$rflags")
                rflags=${rflags%%,}
                _opts="${_opts:+${_opts},}${rflags}"
            elif getargbool 0 ro; then
                # if "ro" is specified, we want /usr to be mounted read-only
                _opts="${_opts:+${_opts},}ro"
            elif getargbool 0 rw; then
                # if "rw" is specified, we want /usr to be mounted read-write
                _opts="${_opts:+${_opts},}rw"
            fi
            echo "$_dev ${NEWROOT}${_mp} $_fs ${_opts} $_freq $_passno"
            _usr_found="1"
            break
        fi
    done < "$NEWROOT/etc/fstab" >> /etc/fstab

    if [ "$_usr_found" != "" ]; then
        # we have to mount /usr
        _fsck_ret=0
        if ! getargbool 0 rd.skipfsck; then
            if [ "0" != "${_passno:-0}" ]; then
                fsck_usr "$_dev" "$_fs" "$_opts"
                _fsck_ret=$?
                [ $_fsck_ret -ne 255 ] && echo $_fsck_ret > /run/initramfs/usr-fsck
            fi
        fi

        info "Mounting /usr with -o $_opts"
        mount "$NEWROOT/usr" 2>&1 | vinfo

        if ! ismounted "$NEWROOT/usr"; then
            warn "Mounting /usr to $NEWROOT/usr failed"
            warn "*** Dropping you to a shell; the system will continue"
            warn "*** when you leave the shell."
            emergency_shell
        fi
    fi
}

if [ -f "$NEWROOT/etc/fstab" ]; then
    mount_usr
fi