[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#797361: [PATCH initramfs-tools 2/3] Only run fsck if enabled in /etc/fstab (pass=0)



hooks/functions: Don't install fsck for a mountpoint with pass=0, and do
nothing if all mountpoints have pass=0

scripts/functions: Change _checkfs_once to fail quietly if fsck is missing

scripts/local: Only call _checkfs_once if pass!=0

Closes: #797361
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 hooks/fsck        | 20 +++++++++++++-------
 scripts/functions |  4 ++++
 scripts/local     |  4 +++-
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/hooks/fsck b/hooks/fsck
index 1e2b645..f80f037 100755
--- a/hooks/fsck
+++ b/hooks/fsck
@@ -39,6 +39,7 @@ _read_fstab_entry () {
 					echo "MNT_FSNAME=$MNT_FSNAME"
 					echo "MNT_DIR=$MNT_DIR"
 					echo "MNT_TYPE=$MNT_TYPE"
+					echo "MNT_PASS=$MNT_PASS"
 					break 2
 				fi
 				MNT_DIR=""
@@ -47,13 +48,13 @@ _read_fstab_entry () {
 	done
 }
 
-# Find a specific fstab entry and print its type (if found)
+# Find a specific fstab entry and print its type (if found, and pass != 0)
 # $1=mountpoint
-get_fstype_fstab () {
+get_fsck_type_fstab () {
 	eval "$(_read_fstab_entry "$1")"
 
 	# Not found by default.
-	if [ "$1" = "$MNT_DIR" ]; then
+	if [ "$1" = "$MNT_DIR" ] && [ "$MNT_PASS" != 0 ]; then
 		case "$MNT_TYPE" in
 			auto)
 				if command -v blkid >/dev/null 2>&1 ; then
@@ -73,9 +74,9 @@ get_fstype_fstab () {
 	fi
 }
 
-get_fstypes() {
-	get_fstype_fstab /
-	get_fstype_fstab /usr
+get_fsck_types() {
+	get_fsck_type_fstab /
+	get_fsck_type_fstab /usr
 }
 
 case $1 in
@@ -92,6 +93,11 @@ fi
 . /usr/share/initramfs-tools/scripts/functions
 . /usr/share/initramfs-tools/hook-functions
 
+fsck_types="$(get_fsck_types | sort | uniq)"
+
+if [ -z "$fsck_types" ]; then
+	exit 0
+fi
 
 copy_exec /sbin/fsck
 copy_exec /sbin/logsave
@@ -105,7 +111,7 @@ cat >"${DESTDIR}/etc/e2fsck.conf" <<EOF
 broken_system_clock=1
 EOF
 
-for type in $(get_fstypes | sort | uniq); do
+for type in $fsck_types; do
 	if [ "$type" = 'auto' ] ; then
 		echo "Warning: couldn't identify filesystem type for fsck hook, ignoring."
 		continue
diff --git a/scripts/functions b/scripts/functions
index 33fddcf..319cd10 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -349,6 +349,10 @@ _checkfs_once()
 	TYPE=$(get_fstype "$1")
 
 	FSCKCODE=0
+	if ! command -v fsck >/dev/null 2>&1; then
+		log_warning_msg "fsck not present, so skipping $NAME file system"
+		return
+	fi
 	if [ "$fastboot" = "y" ] ; then
 		log_warning_msg "Fast boot enabled, so skipping $NAME file system check."
 		return
diff --git a/scripts/local b/scripts/local
index f6424f0..25584fc 100644
--- a/scripts/local
+++ b/scripts/local
@@ -175,7 +175,9 @@ local_mount_fs()
 	# FIXME This has no error checking
 	modprobe "${MNT_TYPE}"
 
-	checkfs "$MNT_FSNAME" "$MNT_DIR"
+	if [ "$MNT_PASS" != 0 ]; then
+		checkfs "$MNT_FSNAME" "$MNT_DIR"
+	fi
 
 	# FIXME This has no error checking
 	# Mount filesystem

-- 
Ben Hutchings
Theory and practice are closer in theory than in practice.
                                - John Levine, moderator of comp.compilers

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: