Skip to content

Instantly share code, notes, and snippets.

@vijinho
Last active January 6, 2025 10:32
Show Gist options
  • Save vijinho/4a667dc6c43e9aa020889f5d5f8333ad to your computer and use it in GitHub Desktop.
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
#!/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