brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: resize2fs makes an ext4 filesystem use a disk you just made bigger

Disk
~/tips/tip-disk-resize2fs-grow

resize2fs /dev/sdX1

Grows an ext4 filesystem to fill its enlarged disk or partition, often while it stays mounted.

Giving a virtual machine a bigger disk is a click in the hypervisor. Inside the machine, nothing changes until the filesystem is told about the extra space.

First the partition must be bigger. If the filesystem sits on a partition, grow that one first, for example with growpart /dev/sdX 1 from cloud-utils or with parted. Then grow the filesystem:

resize2fs /dev/sdX1

Without a size, resize2fs grows the filesystem to fill the whole partition. ext4 can do this while it’s mounted, so for growing you don’t need to stop anything. An image file shows it well: a 64M filesystem in a file grown to 128M becomes 32768 blocks of 4K, the full new size.

Check afterwards with df -h.

Growing is the safe direction. Shrinking ext4 can only be done unmounted, needs an e2fsck -f first, and if you then shrink the partition by even a little too much, you cut off data. I’d only shrink with a fresh backup. And this tool is for ext2, ext3 and ext4. XFS uses xfs_growfs on the mount point and can’t shrink at all, while Btrfs uses btrfs filesystem resize max.

On LVM, lvextend -r grows the volume and runs the filesystem resize in one go.

Further reading: resize2fs(8) manual page

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (44) All topics

Link