YouTip LogoYouTip

Linux Comm Resize2Fs

[![Image 1: Linux Command Encyclopaedia](#) Linux Command Encyclopaedia](#)\n\n* * *\n\n`resize2fs` is a utility in Linux systems for adjusting the size of ext2/ext3/ext4 file systems. It can enlarge or shrink the file system without losing data, and is usually used together with `LVM` (Logical Volume Management) or disk partitioning tools.\n\n* * *\n\n## Command Syntax\n\nresize2fs device \n### Parameter Description\n\n| Parameter | Description |\n| --- | --- |\n| Device | Specifies the device where the file system to be adjusted is located (e.g., `/dev/sda1`) |\n| New size | Optional parameter, specifies the new size of the file system (units can be K/M/G) |\n\n* * *\n\n## Common Options\n\n| Option | Description |\n| --- | --- |\n| `-d` | Display debug information |\n| `-f` | Force the operation to execute |\n| `-p` | Display progress bar |\n| `-M` | Shrink the file system to the minimum possible size |\n| `-P` | Print the minimum possible size of the file system without performing the resize |\n\n* * *\n\n## Usage Scenarios\n\n### Scenario 1: Enlarging the File System\n\nWhen the underlying storage device (partition/LVM) has been enlarged, you need to adjust the file system to use the new space:\n\n## Example\n\n# 1. First enlarge the underlying device (partition or LVM)\n\n# 2. Then adjust the file system\n\n resize2fs /dev/vg01/lv01\n\n### Scenario 2: Shrinking the File System\n\n## Example\n\n# 1. First shrink the file system (note: need to unmount the file system first)\n\numount /mnt/data\n\n e2fsck -f /dev/vg01/lv01\n\n resize2fs /dev/vg01/lv01 10G\n\n# 2. Then shrink the underlying device\n\n* * *\n\n## Detailed Examples\n\n### Example 1: Enlarging an ext4 File System\n\n## Example\n\n# Check current file system size\n\ndf -h /mnt/data\n\n# Enlarge the LVM logical volume (assuming space has been prepared)\n\n lvextend -L +5G /dev/vg01/lv01\n\n# Adjust the file system size\n\n resize2fs /dev/vg01/lv01\n\n# Verify the new size\n\ndf -h /mnt/data\n\n### Example 2: Shrinking an ext4 File System\n\n## Example\n\n# Unmount the file system\n\numount /mnt/data\n\n# Force file system check\n\n e2fsck -f /dev/vg01/lv01\n\n# Shrink the file system to 15GB\n\n resize2fs /dev/vg01/lv01 15G\n\n# Shrink the LVM logical volume (note: should be slightly larger than the file system)\n\n lvreduce -L 15.5G /dev/vg01/lv01\n\n# Remount\n\nmount /dev/vg01/lv01 /mnt/data\n\n* * *\n\n## Notes\n\n1. **Data Backup**: Be sure to back up important data before resizing the file system\n2. **File System Check**: Must run `e2fsck -f` before shrinking operations\n3. **Order Issues**:\n - When enlarging: First enlarge the device, then enlarge the file system\n - When shrinking: First shrink the file system, then shrink the device\n\n4. **Online Resize**: In some cases, you can resize without unmounting the file system, but unmounting is safer\n5. **Minimum Size**: Use the `-P` option to see the minimum size the file system can be shrunk to\n\n* * *\n\n## FAQ\n\n### Q1: Why can't resize2fs adjust non-ext file systems?\n\nA: `resize2fs` is a tool specifically designed for ext2/ext3/ext4 file systems. Other file systems like XFS, Btrfs, etc. have their own resize tools.\n\n### Q2: Will resizing operations lose data?\n\nA: Correct operations usually won't lose data, but any disk operation has risks, so backing up is strongly recommended.\n\n### Q3: How to know the minimum size a file system can be shrunk to?\n\nA: Use the command: `resize2fs -P /dev/your_device`\n\n* * *\n\n## Flowchart: resize2fs Workflow\n\n## Example\n\ngraph TD\n\n A --> B{Operation Type}\n\n B -->|Enlarge| C\n\n C --> D\n\n B -->|Shrink| E\n\n E --> F\n\n F --> G\n\n G --> H\n\n D & H --> I\n\n I --> J\n\n* * *\n\n## Summary\n\n`resize2fs` is a powerful tool for managing ext file system sizes. When used properly, it can flexibly adjust storage space. Remember the operation sequence and precautions, and you can safely and efficiently complete file system resizing tasks.\n\n* * Linux Command Encyclopaedia](#)
← Linux Comm GdbLinux Comm Zypper β†’