Ext4 is a widely used filesystem that supports online and offline resizing, as well as offline shrinking, to adapt to changing storage needs. However, you might encounter common errors when extending an Ext4 filesystem. This article uses the disk /dev/vdb as an example to explain how to identify and resolve these errors for a successful resize.
resize2fs: Bad magic number in super-block while trying to open /dev/vdb
Problem description
You run the following resize2fs command:
sudo resize2fs /dev/vdbThe command returns the following error:
resize2fs: Bad magic number in super-block while trying to open /dev/vdb
Couldn't find valid filesystem superblock.Cause
This error indicates the specified device, /dev/vdb, is not an Ext4 filesystem.
Solution
Verify that the device uses the Ext4 filesystem type.
lsblk --fs /dev/vdbresize2fs: Device or resource busy while trying to open /dev/vdb
Problem description
You run the resize2fs command.
sudo resize2fs /dev/vdbThe command returns the following error:
resize2fs: Device or resource busy while trying to open /dev/vdb
Couldn't find valid filesystem superblock.Cause
This error typically occurs when the filesystem is on a partition, but you run the resize2fs command on the parent disk. For example, the filesystem is on partition /dev/vdb1, but you attempt to resize the parent disk /dev/vdb.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdb 253:16 0 100G 0 disk
└─vdb1 253:17 0 50G 0 partSolution
Extend the partition.
sudo growpart /dev/vdb 1A successful command returns output similar to the following:
CHANGED: partition=1 start=2048 old: size=104855552 end=104857599 new: size=209713119 end=209715166Extend the file system.
sudo resize2fs /dev/vdb1A successful command returns output similar to the following:
resize2fs 1.46.0 (29-Jan-2020)
Filesystem at /dev/vdb1 is mounted on /mnt/test; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 13
The filesystem on /dev/vdb1 is now 26214139 (4k) blocks long.The filesystem is already 13106944 (4k) blocks long. Nothing to do!
Problem description
You run the resize2fs command.
sudo resize2fs /dev/vdb1The command returns the following error:
The filesystem is already 13106944 (4k) blocks long. Nothing to do!Cause
This error indicates the filesystem already occupies all available space on its partition. This usually occurs if you try to extend a filesystem before extending its underlying partition.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdb 253:16 0 100G 0 disk
└─vdb1 253:17 0 50G 0 partSolution
Extend the partition.
sudo growpart /dev/vdb 1A successful command returns output similar to the following:
CHANGED: partition=1 start=2048 old: size=104855552 end=104857599 new: size=209713119 end=209715166Extend the file system.
sudo resize2fs /dev/vdb1A successful command returns output similar to the following:
resize2fs 1.46.0 (29-Jan-2020)
Filesystem at /dev/vdb1 is mounted on /mnt/test; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 13
The filesystem on /dev/vdb1 is now 26214139 (4k) blocks long.resize2fs: On-line shrinking not supported
Problem description
You run the resize2fs command.
sudo resize2fs /dev/vdbThe command returns the following error:
Filesystem at /dev/vdb is mounted on /mnt/test; on-line resizing required
resize2fs: On-line shrinking not supportedCause
This error indicates that Ext4 only supports offline shrinking.
Solution
Check whether the device is mounted.
mount | grep /dev/vdbUnmount the file system.
sudo umount /mnt/testRun the
resize2fscommand again.
sudo resize2fs /dev/vdb 50GA successful command returns output similar to the following:
Resizing the filesystem on /dev/vdb to 13107200 (4k) blocks.
The filesystem on /dev/vdb is now 13107200 (4k) blocks long.resize2fs: Permission denied to resize filesystem
Problem description
You run the resize2fs command.
resize2fs /dev/vdbThe command returns the following error:
resize2fs: Permission denied to resize filesystemCause
This error indicates either you lack the required permission (CAP_SYS_RESOURCE) to resize the filesystem, or the filesystem contains errors.
Solution
Use
sudoto elevate your permissions.
sudo resize2fs /dev/vdbIf the issue persists, check the file system for errors.
dmesg | grep "EXT4-fs"If file system errors exist, unmount the file system and perform a file system check (
fsck).
sudo umount /mnt/test
sudo fsck -y /dev/vdbRun the
resize2fscommand again to perform an offline resize.
sudo resize2fs /dev/vdb