3 type getarg
> /dev
/null
2>&1 || .
/lib
/dracut-lib.sh
6 info
"note - fsck suggests reboot, if you"
7 info
"leave shell, booting will continue normally"
8 emergency_shell
-n "(reboot ?)"
12 warn
"*** An error occurred during the file system check."
13 warn
"*** Dropping you to a shell; the system will try"
14 warn
"*** to mount the filesystem(s), when you leave the shell."
15 emergency_shell
-n "(Repair filesystem)"
18 # inherits: _ret _drv _out
20 [ "$_ret" -gt 0 ] && warn
"$_drv returned with $_ret"
21 if [ "$_ret" -ge 4 ]; then
22 [ -n "$_out" ] && echo "$_out" | vwarn
25 [ -n "$_out" ] && echo "$_out" | vinfo
26 [ "$_ret" -ge 2 ] && fsck_ask_reboot
30 # note: this function sets _drv of the caller
40 # } >/dev/null 2>&1 &&
41 # _drv="_drv=none fsck_drv_xfs" &&
46 type e2fsck
> /dev
/null
2>&1 \
47 && _drv
="fsck_drv_com e2fsck" \
51 type fsck.f2fs
> /dev
/null
2>&1 \
52 && _drv
="fsck_drv_com fsck.f2fs" \
56 type jfs_fsck
> /dev
/null
2>&1 \
57 && _drv
="fsck_drv_com jfs_fsck" \
61 type reiserfsck
> /dev
/null
2>&1 \
62 && _drv
="fsck_drv_com reiserfsck" \
66 # type btrfsck >/dev/null 2>&1 &&
67 # _drv="_drv=none fsck_drv_btrfs" &&
72 # nfs can be a nop, returning success
77 type fsck
> /dev
/null
2>&1 \
78 && _drv
="fsck_drv_std fsck" \
86 # note: all drivers inherit: _drv _fop _dev
89 # xfs fsck is not necessary... Either it mounts or not
94 # btrfs fsck is not necessary... Either it mounts or not
98 # common code for checkers that follow usual subset of options and return codes
104 if ! strglobin
"$_fop" "-[ynap]"; then
105 _fop
="-a${_fop:+ "$_fop"}"
108 info
"issuing $_drv $_fop $_dev"
109 # we enforce non-interactive run, so $() is fine
110 _out
=$
($_drv "$_fop" "$_dev")
117 # code for generic fsck, if the filesystem checked is "unknown" to us
123 info
"issuing fsck $_fop $_dev"
124 # note, we don't enforce -a here, thus fsck is being run (in theory)
125 # interactively; otherwise some tool might complain about lack of terminal
126 # (and using -a might not be safe)
127 # shellcheck disable=SC2086
128 fsck
$_fop "$_dev" > /dev
/console
2>&1
135 # checks single filesystem, relying on specific "driver"; we don't rely on
136 # automatic checking based on fstab, so empty one is passed;
137 # takes 4 arguments - device, filesystem, filesystem options, additional fsck options;
138 # first 2 arguments are mandatory (fs may be auto or "")
139 # returns 255 if filesystem wasn't checked at all (e.g. due to lack of
140 # necessary tools or insufficient options)
142 local FSTAB_FILE
=/etc
/fstab.empty
144 local _fs
="${2:-auto}"
148 [ $# -lt 2 ] && return 255
149 # if UUID= marks more than one device, take only the first one
150 [ -e "$_dev" ] || _dev
=$
(devnames
"$_dev" |
while read -r line ||
[ -n "$line" ]; do if [ -n "$line" ]; then
154 [ -e "$_dev" ] ||
return 255
155 _fs
=$
(det_fs
"$_dev" "$_fs")
156 fsck_able
"$_fs" ||
return 255
158 info
"Checking $_fs: $_dev"
164 # takes list of filesystems to check in parallel; we don't rely on automatic
165 # checking based on fstab, so empty one is passed
167 local FSTAB_FILE
=/etc
/fstab.empty
173 [ $# -eq 0 ] ||
! type fsck
> /dev
/null
2>&1 && return 255
175 info
"Checking filesystems (fsck -M -T -a):"
181 _out
="$(fsck -M -T "$@
" -- -a)"
189 # verify supplied filesystem type:
190 # if user provided the fs and we couldn't find it, assume user is right
191 # if we found the fs, assume we're right
194 local _orig
="${2:-auto}"
197 _fs
=$
(udevadm info
--query=env
--name="$_dev" \
198 |
while read -r line ||
[ -n "$line" ]; do
199 if str_starts
"$line" "ID_FS_TYPE="; then
200 echo "${line#ID_FS_TYPE=}"
206 if [ "$_fs" = "auto" ]; then
224 [ -z "$_rootfstype" ] && _rootfstype
=$
(getarg rootfstype
=)
225 [ -z "$_rootflags" ] && _rootflags
=$
(getarg rootflags
=)
227 [ -z "$_rootfstype" ] && _rootfstype
="auto"
229 if [ -z "$_rootflags" ]; then
230 _rootflags
="ro,x-initrd.mount"
232 _rootflags
="ro,$_rootflags,x-initrd.mount"
237 CMDLINE
=$
(getcmdline
)
238 for _o
in $CMDLINE; do
248 if [ "$_rw" = "1" ]; then
249 _rootflags
="$_rootflags,rw"
250 if ! getargbool
0 rd.skipfsck
; then
255 if grep -q "$_root /sysroot" /etc
/fstab
; then
256 echo "$_root /sysroot $_rootfstype $_rootflags $_fspassno 0" >> /etc
/fstab
261 if type systemctl
> /dev
/null
2> /dev
/null
; then
262 systemctl daemon-reload
263 systemctl
--no-block start initrd-root-fs.target