]>
Commit | Line | Data |
---|---|---|
76c88488 | 1 | #!/bin/sh |
cc02093d HH |
2 | # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- |
3 | # ex: ts=8 sw=4 sts=4 et filetype=sh | |
e8cf498d | 4 | |
c9f1e3d1 | 5 | type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
fefab84f | 6 | type det_fs >/dev/null 2>&1 || . /lib/fs-lib.sh |
57c6b805 | 7 | |
fefab84f MS |
8 | mount_root() { |
9 | local _ret | |
6a5170a1 | 10 | local _rflags_ro |
0216d1cd | 11 | # sanity - determine/fix fstype |
fefab84f | 12 | rootfs=$(det_fs "${root#block:}" "$fstype") |
6a5170a1 | 13 | |
47b8f66c HH |
14 | journaldev=$(getarg "root.journaldev=") |
15 | if [ -n "$journaldev" ]; then | |
6a5170a1 FC |
16 | case "$rootfs" in |
17 | xfs) | |
18 | rflags="${rflags:+${rflags},}logdev=$journaldev" | |
19 | ;; | |
20 | reiserfs) | |
21 | fsckoptions="-j $journaldev $fsckoptions" | |
22 | rflags="${rflags:+${rflags},}jdev=$journaldev" | |
23 | ;; | |
24 | *);; | |
25 | esac | |
26 | fi | |
27 | ||
28 | _rflags_ro="$rflags,ro" | |
ae4758ce | 29 | _rflags_ro="${_rflags_ro##,}" |
6a5170a1 | 30 | |
79148c29 | 31 | while ! mount -t ${rootfs} -o "$_rflags_ro" "${root#block:}" "$NEWROOT"; do |
ae4758ce | 32 | warn "Failed to mount -t ${rootfs} -o $_rflags_ro ${root#block:} $NEWROOT" |
5113a3ef HH |
33 | fsck_ask_err |
34 | done | |
57c6b805 | 35 | |
3871942d | 36 | READONLY= |
13af399f | 37 | fsckoptions= |
3871942d HH |
38 | if [ -f "$NEWROOT"/etc/sysconfig/readonly-root ]; then |
39 | . "$NEWROOT"/etc/sysconfig/readonly-root | |
40 | fi | |
41 | ||
42 | if getargbool 0 "readonlyroot=" -y readonlyroot; then | |
43 | READONLY=yes | |
44 | fi | |
45 | ||
46 | if getarg noreadonlyroot ; then | |
47 | READONLY=no | |
48 | fi | |
49 | ||
50 | if [ -f "$NEWROOT"/fastboot ] || getargbool 0 fastboot ; then | |
51 | fastboot=yes | |
52 | fi | |
53 | ||
965c2d87 | 54 | if ! getargbool 0 rd.skipfsck; then |
af3b67b2 AŻ |
55 | if [ -f "$NEWROOT"/fsckoptions ]; then |
56 | fsckoptions=$(cat "$NEWROOT"/fsckoptions) | |
57 | fi | |
58 | ||
965c2d87 AŻ |
59 | if [ -f "$NEWROOT"/forcefsck ] || getargbool 0 forcefsck ; then |
60 | fsckoptions="-f $fsckoptions" | |
61 | elif [ -f "$NEWROOT"/.autofsck ]; then | |
62 | [ -f "$NEWROOT"/etc/sysconfig/autofsck ] && \ | |
63 | . "$NEWROOT"/etc/sysconfig/autofsck | |
64 | if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then | |
65 | AUTOFSCK_OPT="$AUTOFSCK_OPT -f" | |
66 | fi | |
67 | if [ -n "$AUTOFSCK_SINGLEUSER" ]; then | |
68 | warn "*** Warning -- the system did not shut down cleanly. " | |
69 | warn "*** Dropping you to a shell; the system will continue" | |
70 | warn "*** when you leave the shell." | |
9d787df1 | 71 | action_on_fail |
965c2d87 AŻ |
72 | fi |
73 | fsckoptions="$AUTOFSCK_OPT $fsckoptions" | |
3871942d | 74 | fi |
3871942d HH |
75 | fi |
76 | ||
3871942d | 77 | rootopts= |
68e7661c | 78 | if getargbool 1 rd.fstab -d -n rd_NO_FSTAB \ |
cc02093d HH |
79 | && ! getarg rootflags \ |
80 | && [ -f "$NEWROOT/etc/fstab" ] \ | |
81 | && ! [ -L "$NEWROOT/etc/fstab" ]; then | |
3b403b32 | 82 | # if $NEWROOT/etc/fstab contains special mount options for |
57c6b805 HH |
83 | # the root filesystem, |
84 | # remount it with the proper options | |
cc02093d | 85 | rootopts="defaults" |
7209df9e | 86 | while read dev mp fs opts dump fsck; do |
d793fc2e HH |
87 | # skip comments |
88 | [ "${dev%%#*}" != "$dev" ] && continue | |
3b403b32 | 89 | |
57c6b805 | 90 | if [ "$mp" = "/" ]; then |
0216d1cd | 91 | # sanity - determine/fix fstype |
fefab84f | 92 | rootfs=$(det_fs "${root#block:}" "$fs") |
cc02093d | 93 | rootopts=$opts |
7209df9e | 94 | rootfsck=$fsck |
cc02093d | 95 | break |
57c6b805 | 96 | fi |
cc02093d | 97 | done < "$NEWROOT/etc/fstab" |
3871942d HH |
98 | fi |
99 | ||
21b69115 | 100 | # we want rootflags (rflags) to take precedence so prepend rootopts to |
79148c29 AŻ |
101 | # them |
102 | rflags="${rootopts},${rflags}" | |
103 | rflags="${rflags#,}" | |
104 | rflags="${rflags%,}" | |
21b69115 | 105 | |
7ed1de2f | 106 | # backslashes are treated as escape character in fstab |
c60dbcc0 MS |
107 | # esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g') |
108 | # printf '%s %s %s %s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" >/etc/fstab | |
7ed1de2f | 109 | |
6625b74e | 110 | ran_fsck=0 |
5113a3ef HH |
111 | if fsck_able "$rootfs" && \ |
112 | [ "$rootfsck" != "0" -a -z "$fastboot" -a "$READONLY" != "yes" ] && \ | |
7209df9e | 113 | ! strstr "${rflags}" _netdev && \ |
9fb01d49 | 114 | ! getargbool 0 rd.skipfsck; then |
5113a3ef | 115 | umount "$NEWROOT" |
840d8e47 | 116 | fsck_single "${root#block:}" "$rootfs" "$rflags" "$fsckoptions" |
fefab84f MS |
117 | _ret=$? |
118 | [ $_ret -ne 255 ] && echo $_ret >/run/initramfs/root-fsck | |
6625b74e | 119 | ran_fsck=1 |
57c6b805 | 120 | fi |
3871942d | 121 | |
7209df9e HH |
122 | echo "${root#block:} $NEWROOT $rootfs ${rflags:-defaults} 0 $rootfsck" >> /etc/fstab |
123 | ||
5113a3ef HH |
124 | if ! ismounted "$NEWROOT"; then |
125 | info "Mounting ${root#block:} with -o ${rflags}" | |
126 | mount "$NEWROOT" 2>&1 | vinfo | |
79148c29 | 127 | elif ! are_lists_eq , "$rflags" "$_rflags_ro" defaults; then |
5113a3ef HH |
128 | info "Remounting ${root#block:} with -o ${rflags}" |
129 | mount -o remount "$NEWROOT" 2>&1 | vinfo | |
130 | fi | |
d884af80 | 131 | |
af3b67b2 | 132 | if ! getargbool 0 rd.skipfsck; then |
32bd2fbb HH |
133 | [ -f "$NEWROOT"/forcefsck ] && rm -f -- "$NEWROOT"/forcefsck 2>/dev/null |
134 | [ -f "$NEWROOT"/.autofsck ] && rm -f -- "$NEWROOT"/.autofsck 2>/dev/null | |
af3b67b2 | 135 | fi |
fefab84f MS |
136 | } |
137 | ||
138 | if [ -n "$root" -a -z "${root%%block:*}" ]; then | |
139 | mount_root | |
f81a894e | 140 | fi |