Ext4 is a file system that is widely used. You can extend Ext4 file systems online and extend or shrink Ext4 file systems offline based on your storage requirements. However, you may encounter errors when you extend Ext4 file systems. This topic describes how to identify and handle the errors to ensure that the Ext4 file systems can be extended. In the examples, the /dev/vdb disk is used.
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 following error messages appear:
resize2fs: Bad magic number in super-block while trying to open /dev/vdb
Couldn't find valid filesystem superblock.Cause
The device that you want to extend, such as /dev/vdb, is not formatted to Ext4.
Solution
Check the file systems on the device. Make sure that the file systems on the device are Ext4 file systems.
lsblk --fs /dev/vdbresize2fs: Device or resource busy while trying to open /dev/vdb
Problem description
You run the following resize2fs command:
sudo resize2fs /dev/vdbThe following error messages appear:
resize2fs: Device or resource busy while trying to open /dev/vdb
Couldn't find valid filesystem superblock.Cause
In most cases, the preceding issue occurs because the file system that you want to extend resides on a partition. For example, when you run the resize2fs command with the disk name /dev/vdb as an argument but the file system actually resides at /dev/vdb1 partition, the preceding error messages appear.
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 1The following command output indicates that the partition is extended:
CHANGED: partition=1 start=2048 old: size=104855552 end=104857599 new: size=209713119 end=209715166Extend the file system.
sudo resize2fs /dev/vdb1The following command output indicates that the file system is extended:
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 following resize2fs command:
sudo resize2fs /dev/vdb1The following error message appears:
The filesystem is already 13106944 (4k) blocks long. Nothing to do!Cause
In most cases, the preceding issue occurs because the file system that you want to extend resides on a partition. For example, when you run the resize2fs command with the partition name /dev/vdb1 as an argument, the preceding error message appears.
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 1The following command output indicates that the partition is extended:
CHANGED: partition=1 start=2048 old: size=104855552 end=104857599 new: size=209713119 end=209715166Extend the file system.
sudo resize2fs /dev/vdb1The following command output indicates that the file system is extended:
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 following resize2fs command:
sudo resize2fs /dev/vdbThe following error messages appear:
Filesystem at /dev/vdb is mounted on /mnt/test; on-line resizing required
resize2fs: On-line shrinking not supportedCause
Ext4 file systems can be shrunk offline but cannot be shrunk online.
Solution
Check whether the device is mounted.
mount | grep /dev/vdbUnmount the file system.
sudo umount /mnt/testRun the
resize2fscommand to extend the file system.
sudo resize2fs /dev/vdb 50GThe following command output indicates that the file system is shrunk:
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 following resize2fs command:
resize2fs /dev/vdbThe following error message appears:
resize2fs: Permission denied to resize filesystemCause
The CAP_SYS_RESOURCE privilege is required to perform resize2fs operations, or the file system contains errors.
Solution
Run the resize2fs command with
sudoprivileges.
sudo resize2fs /dev/vdbIf the issue persists, check the file system for errors.
dmesg | grep "EXT4-fs"If the file system contains errors, unmount the file system and perform a file system check (
fsck).
sudo umount /mnt/test
sudo fsck -y /dev/vdbRun the
resize2fscommand to extend the file system offline.
sudo resize2fs /dev/vdb