resize2fs

ext2/ext3/ext4 file system resizer

resize2fs [ -fFpPMbs ] [ -d debug-flags ] [ -S RAID-stride ] [ -z undo_file ] device [ newSize ]

Resizes ext2, ext3, or ext4 unmounted file system. (Run from /etc/init.d to resize root fs)
Can expand the size even if the filesystem is mounted,

newSize can be suffixed by s, K, M, or G, for 512 byte sectors, kilobytes, …, can not be larger than the size of the partition.
Default: blocksize of the filesystem.
Defaults to the size of the partition.

Does not change the size of the partition. To enlarge a filesystem, first use parted -m /dev/mmcblk0 unit sector resizepart …

If using the logical volume manager lvm use lvextend.

To shrink an ext2 partition, first use resize2fs to shrink the size of filesystem.
Then use parted or fdisk to shrink the size of the partition. Do not make it smaller than the new size of the ext2 filesystem!

Enlarge example:

 /bin/df -m
    Filesystem     1M-blocks  Used Available Use% Mounted on
    /dev/root           4960  4548       142  97% / 

 sudo fdisk /dev/mmcblk0
    Device         Boot    Start      End  Sectors  Size Id Type
    /dev/mmcblk0p2         98304 12551295 12452992    6G 83 Linux     5.93GB


 sudo resize2fs -d16 -p /dev/mmcblk0p2 
    resize2fs 1.43.4 (31-Jan-2017)
    Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 1
    The filesystem on /dev/mmcblk0p2 is now 1556624 (4k) blocks long.

 /bin/df -m
    Filesystem     1M-blocks  Used Available Use% Mounted on
    /dev/root           5921  4548      1064  82% /
-P Print the number of file system blocks in the file system if it is shrunk and exit.
sudo resize2fs -P /dev/mmcblk0p2 
 resize2fs 1.43.4 (31-Jan-2017)
 Estimated minimum size of the filesystem: 1306624
-M Minimize the file system size
-p Prints out a percentage completion bars for each operation during an offline resize,
-d flagsdebug flags. Computed by adding the numbers of the flags (all 2+4+8+16+32= 3E = 62
  •  2 - block relocations
  •  4 - inode relocations
  •  8 - moving the inode table
  • 16 - Print timing information
  • 32 - minimum filesystem size calculation
  • -f Forces overriding some safety checks
    -F Flush the filesystem device's buffer caches before beginning. Useful for doing time trials.
    -b Turns on  the 64bit feature, resizes the group descriptors , and moves other metadata
    -s Turns off the 64bit feature and frees blocks that are no longer in use.
    -S RAID-stride heuristically determines the RAID stride specified when the filesystem was created. Allows explicitl specifying a RAID stride setting to be used by resize2fs instead.
    -z undo_file Before overwriting a file system block, save the old contents .
    Used with e2undo(8) to restore the old contents of the file system.
    Default resize2fs-device.e2undo in the directory specified via $E2FSPROGS_UNDO_DIR .

    Cannot be used to recover from a power fail. reset or system crash.

    SEE ALSO fdisk(8), e2fsck(8), mke2fs(8), lvm(8), lvextend(8)