This adds support for fsck'ing root at bootstrap if the fsck binary and necessary helpers are included. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- init | 15 +++++++++++++++ init_functions | 22 ++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/init b/init index 975368b..30677de 100644 --- a/init +++ b/init @@ -78,6 +78,21 @@ if [ "${break}" = "y" ] || [ "${break}" = "premount" ]; then launch_interactive_shell fi +rootdev=$(resolve_device "$root") && root=$rootdev +unset rootdev + +if [ -z "$skipfsck" ]; then + fsck_device "$root" + fsckret=$? + if [ "$fsckret" -ne 255 ]; then + if [ $(( $fsckret & 2 )) -eq 2 ]; then + msg "***** reboot required *****" + launch_interactive_shell --exec + fi + echo "$fsckret" > /run/initramfs/root-fsck + fi +fi + # Mount root at /new_root ${mount_handler:-default_mount_handler} /new_root diff --git a/init_functions b/init_functions index 85c1344..62c6af7 100644 --- a/init_functions +++ b/init_functions @@ -58,6 +58,9 @@ parse_cmdline() { fi [ "$lhs" = "${lhs//[^0-9a-zA-Z]}" ] && [ "$lhs" = "${lhs#[0-9]}" ] && eval ${lhs}=\${rhs} ;; + forcefsck) + FORCEFSCK="-f" + ;; *) lhs=${w//[-.]/_} [ "$lhs" = "${lhs//[^0-9a-zA-Z]}" ] && [ "$lhs" = "${lhs#[0-9]}" ] && eval ${lhs}=y ;; @@ -74,6 +77,19 @@ parse_cmdline() { done } +fsck_device() { + [ -x /sbin/fsck ] || return 255 + + if [ ! -b "$1" ]; then + err "device '$1' not found. Skipping fsck." + return 255 + fi + + msg ":: performing fsck on '$1'" + FSTAB_FILE=/dev/null fsck -Ta -C"$FSCK_FD" "$1" -- $FORCEFSCK +} + + resolve_device() { local major minor dev device=$1 @@ -120,9 +136,7 @@ resolve_device() { } default_mount_handler() { - local rootdev - - if ! rootdev=$(resolve_device "$root"); then + if [ ! -b "$root" ]; then err "Unable to determine major/minor number of root device '$root'." echo "You are being dropped to a recovery shell" echo " Type 'exit' to try and continue booting" @@ -130,7 +144,7 @@ default_mount_handler() { msg "Trying to continue (this will most likely fail) ..." fi - if ! mount ${fstype:+-t $fstype} -o ${rwopt:-ro}${rootflags:+,$rootflags} "$rootdev" "$1"; then + if ! mount ${fstype:+-t $fstype} -o ${rwopt:-ro}${rootflags:+,$rootflags} "$root" "$1"; then echo "You are now being dropped into an emergency shell." launch_interactive_shell msg "Trying to continue (this will most likely fail) ..." -- 1.7.7.3