Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

resize2fs

Grow or shrink an ext2/ext3/ext4 file system.

Level
RHCSA exam
Group
Disks and file systems
Needs root
Yes
Package
e2fsprogs

What it does

resize2fs DEVICE grows the file system to fill the device (also when mounted). With a size it can also shrink — only unmounted and after e2fsck -f. When you shrink, shrink the file system before the LV; when you grow, grow the LV first.

lvextend -r and lvreduce -r call it for you.

How to write it

resize2fs [OPTION]... DEVICE [SIZE]

Options 10

Most used

SIZE
New size with unit (K, M, G, T, s = 512-byte sectors); without: fill the device.
-f
Force (skip safety checks).
-F
Flush the device buffers first.
-M
Shrink to the minimum size.
-P
Print the minimum size (estimate).
-p
Show progress.
-d FLAGS
Debug flags.
-S STRIDE
RAID stride.
-b, -s
Turn the 64bit feature on / off.
-z FILE
Save an undo file.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Grow after lvextend

    lvextend -L +2G /dev/vgdata/lvweb
    resize2fs /dev/vgdata/lvweb

    Online grow of a mounted ext4.

  2. 2Shrink to 3 GiB

    umount /docs
    e2fsck -f /dev/vgfiles/lvdocs
    resize2fs /dev/vgfiles/lvdocs 3G
    lvreduce -L 3G /dev/vgfiles/lvdocs
    mount /docs

    The order matters: file system first.

  3. 3How small can it get?

    resize2fs -P /dev/vgfiles/lvdocs
    Estimated minimum size of the filesystem: 140326

    In blocks (usually 4 KiB).

  4. 4Shrink to the minimum

    resize2fs -M /dev/vgfiles/lvdocs

    Before copying to a smaller disk.

  5. 5Show progress

    resize2fs -p /dev/vgdata/lvweb

    For big file systems.

  6. 6Grow a partition-based ext4

    growpart /dev/vdb 1; resize2fs /dev/vdb1

    After the disk was made bigger.

  7. 7Easier: let LVM do it

    lvextend -r -L +1G /dev/vgdata/lvweb

    Calls resize2fs.

  8. 8Undo file for safety

    resize2fs -z /root/resize.undo /dev/vgfiles/lvdocs 3G

    Restore with e2undo if something goes wrong.

  9. 9Check after resize

    df -h /docs

    The new size.

  10. 10Mounted shrink fails

    resize2fs /dev/vgfiles/lvdocs 3G
    resize2fs: On-line shrinking not supported

    Unmount first.

Exit codes

0Done.
1Error.