tune2fs Command
Adjust tunable filesystem parameters on ext2, ext3, and ext4 filesystems
Syntax:
tune2fs [OPTIONS] device
Warning: The tune2fs command modifies filesystem parameters and should be used with caution. Always backup important data before making changes. Some operations require the filesystem to be unmounted.
Description
The tune2fs command allows system administrators to adjust various tunable filesystem parameters on Linux ext2, ext3, and ext4 filesystems. It can modify parameters such as the maximum mount count, check interval, reserved block count, filesystem label, and many other options that affect filesystem behavior and performance.
Note: Most tune2fs operations can be performed on mounted filesystems, but some changes may require unmounting the filesystem first. Always check the documentation for specific options.
Common Options
| Option | Description |
|---|---|
-l |
List the contents of the filesystem superblock |
-L volume-label |
Set the volume label of the filesystem |
-c max-mount-counts |
Set maximum number of mounts between filesystem checks |
-C mount-count |
Set the number of times the filesystem has been mounted |
-i interval |
Set the maximal time between filesystem checks |
-j |
Add an ext3 journal to the filesystem |
-J journal-options |
Override default journal parameters |
-m reserved-blocks-percentage |
Set percentage of blocks reserved for super-user |
-r reserved-blocks-count |
Set number of reserved blocks |
-u user |
Set the user who can use reserved blocks |
-g group |
Set the group which can use reserved blocks |
-e errors-behavior |
Set behavior when errors are detected |
-f |
Force the operation to complete |
-o [^]mount-options |
Set or clear default mount options |
-U UUID |
Set the universally unique identifier (UUID) |
Examples
Display filesystem information:
tune2fs -l /dev/sda1 # Shows detailed filesystem information tune2fs -l /dev/sda1 | grep -i label # Show only the filesystem label
Set filesystem label:
tune2fs -L "MyData" /dev/sda1 # Sets the filesystem label to "MyData" tune2fs -L "" /dev/sda1 # Removes the filesystem label
Adjust reserved blocks:
tune2fs -m 1 /dev/sda1 # Set reserved blocks to 1% (default is 5%) tune2fs -r 0 /dev/sda1 # Set reserved blocks count to 0 tune2fs -m 0 /dev/sda1 # Disable reserved blocks entirely
Set filesystem check intervals:
tune2fs -c 30 /dev/sda1 # Force fsck after 30 mounts tune2fs -c 0 /dev/sda1 # Disable mount-count-based checking tune2fs -i 0 /dev/sda1 # Disable time-based checking tune2fs -i 1m /dev/sda1 # Set check interval to 1 month
Configure error behavior:
tune2fs -e continue /dev/sda1 # Continue on errors tune2fs -e remount-ro /dev/sda1 # Remount read-only on errors tune2fs -e panic /dev/sda1 # Panic on errors
Add journal to ext2 filesystem:
# Convert ext2 to ext3 tune2fs -j /dev/sda1 # Add journal with specific size tune2fs -J size=32 /dev/sda1 # Add external journal tune2fs -J device=/dev/sdb1 /dev/sda1
Set UUID:
tune2fs -U random /dev/sda1 # Generate and set a random UUID tune2fs -U clear /dev/sda1 # Clear the UUID tune2fs -U 12345678-1234-1234-1234-123456789012 /dev/sda1 # Set specific UUID
Configure default mount options:
tune2fs -o acl,user_xattr /dev/sda1 # Enable ACL and extended attributes tune2fs -o ^acl /dev/sda1 # Disable ACL support tune2fs -o journal_data /dev/sda1 # Enable data journaling
Set reserved block ownership:
tune2fs -u root /dev/sda1 # Set root as user for reserved blocks tune2fs -g wheel /dev/sda1 # Set wheel group for reserved blocks tune2fs -u 1000 -g 1000 /dev/sda1 # Set specific UID/GID for reserved blocks
Error Behavior Options
| Option | Description |
|---|---|
continue |
Continue normal execution when errors are encountered |
remount-ro |
Remount the filesystem read-only when errors are encountered |
panic |
Cause a kernel panic when errors are encountered |
Time Interval Formats
| Format | Description | Example |
|---|---|---|
d |
Days | 30d (30 days) |
w |
Weeks | 4w (4 weeks) |
m |
Months | 6m (6 months) |
y |
Years | 1y (1 year) |
0 |
Disable | 0 (disabled) |
Advanced Usage
Comprehensive filesystem optimization:
# Optimize for performance tune2fs -m 1 -c 0 -i 0 /dev/sda1 # Set label and UUID tune2fs -L "DataDrive" -U random /dev/sda1 # Configure for server use tune2fs -m 1 -e remount-ro -o acl,user_xattr /dev/sda1
Backup and restore filesystem parameters:
# Backup current settings tune2fs -l /dev/sda1 > filesystem_backup.txt # View specific parameters tune2fs -l /dev/sda1 | grep -E "(Reserved|Mount count|Check interval)"
Batch operations on multiple filesystems:
# Set same label pattern for multiple drives
for dev in /dev/sd{b,c,d}1; do
tune2fs -L "Data$(basename $dev)" "$dev"
done
# Disable checking on all data drives
for dev in /dev/sd{b,c,d}1; do
tune2fs -c 0 -i 0 "$dev"
done
Journal configuration:
# Create external journal mke2fs -O journal_dev /dev/sdb1 tune2fs -J device=/dev/sdb1 /dev/sda1 # Set journal size for large filesystem tune2fs -J size=128 /dev/sda1
Monitoring and Verification
Check filesystem status:
# View mount count and maximum tune2fs -l /dev/sda1 | grep -i "mount count" # Check reserved blocks tune2fs -l /dev/sda1 | grep -i "reserved" # View filesystem features tune2fs -l /dev/sda1 | grep -i "filesystem features"
Verify changes:
# Before making changes tune2fs -l /dev/sda1 | grep "Filesystem label" # Make change tune2fs -L "NewLabel" /dev/sda1 # Verify change tune2fs -l /dev/sda1 | grep "Filesystem label"
Common Use Cases
- Performance optimization: Reducing reserved blocks on data partitions
- Maintenance scheduling: Adjusting filesystem check intervals
- System identification: Setting meaningful filesystem labels
- Error handling: Configuring appropriate error behavior
- Storage management: Converting between ext2/ext3/ext4
- Security configuration: Setting reserved block ownership
- Backup preparation: Setting UUIDs for consistent mounting
- Server optimization: Disabling unnecessary checks on stable systems
Best Practices
- Always backup important data before making filesystem changes
- Test changes on non-critical systems first
- Document filesystem parameters before and after changes
- Use meaningful labels for easy identification
- Consider disabling time-based checks on stable servers
- Set reserved blocks to 1% or less on large data partitions
- Use appropriate error behavior for different filesystem types
- Monitor filesystem health after making changes
- Keep UUIDs unique across systems
- Use external journals for high-performance requirements
Safety Considerations
- Some operations may require unmounting the filesystem
- Changing journal parameters can affect data integrity
- Modifying error behavior affects system stability
- Always verify changes with
tune2fs -l - Keep backups of critical filesystem parameters
- Test changes in non-production environments first