Last active
January 6, 2025 10:35
-
-
Save vijinho/e3918009e8bf83a9349dfe4396afb4bb to your computer and use it in GitHub Desktop.
Script to unmount, defrag and remount and ext4 filesystem
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 argument | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <device>" | |
exit 1 | |
fi | |
DEVICE=$1 | |
# Unmount the specified device | |
umount $DEVICE | |
# Perform fsck on the device with long arguments and enable verbose output, force check, repair mode, directory optimization, and inode count full map | |
fsck.ext4 \ | |
--verbose \ | |
--force \ | |
--repair \ | |
--directory-optimize \ | |
--inode-count-fullmap \ | |
-p $DEVICE | |
# Mount the device back after fsck | |
mount $DEVICE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment