Skip to content

Instantly share code, notes, and snippets.

@vijinho
Last active January 6, 2025 10:35
Show Gist options
  • Save vijinho/e3918009e8bf83a9349dfe4396afb4bb to your computer and use it in GitHub Desktop.
Save vijinho/e3918009e8bf83a9349dfe4396afb4bb to your computer and use it in GitHub Desktop.
Script to unmount, defrag and remount and ext4 filesystem
#!/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