Last active
January 6, 2025 10:32
-
-
Save vijinho/4a667dc6c43e9aa020889f5d5f8333ad to your computer and use it in GitHub Desktop.
Unmount a given ext4 filesystem and check it for bad blocks, then remount it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the user has provided a device or partition argument | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <device>" | |
exit 1 | |
fi | |
DEVICE=$1 | |
# Unmount the device to avoid any conflicts with mounted filesystems | |
umount "$DEVICE" | |
# Run fsck.ext4 with long options for better readability | |
fsck.ext4 --force \ | |
--check \ | |
--keep-going \ | |
--preen \ | |
--test \ | |
--verbose \ | |
--debug \ | |
--inode-count-fullmap \ | |
"$DEVICE" | |
# Re-mount the device after repairs are complete | |
mount "$DEVICE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment