Discussion:
[ubuntu-us-mi] resizing mounted filesystem
Robert Citek
2010-10-06 00:20:57 UTC
Permalink
I'm running into some kind of limit for expanding a mounted file
system. Does anyone know of a workaround that allows me to expand yet
keep the filesystem mounted?

In brief, I have a mounted filesystem that I want to make larger, e.g.
from 5MB to 10GB. However, resize2fs gets about half-way before
stopping with an error. Nothing on the filesystem seems to be broken,
I just can't make it any larger. If I unmount, fsck, resize, and
mount again, that works just fine. But I'd rather not unmount. Or if
I do need to unmount, only unmount to change some setting on the
filesystem and not do a full fsck. (still googling to figure out what
that setting might be.)

Here's a simple script to replicate the issue I'm having. It needs to
be run as root. So, if you are not comfortable with that, please do
not run it.

# code to demonstrate issue
dd if=/dev/zero of=ext4.img bs=1M count=10000
mkfs.ext4 -F ext4.img 5M
mkdir -p ext4.loop
mount -o loop ext4.img ext4.loop
df -PhT ext4.loop
resize2fs $(mount | grep ext4.loop | cut -d" " -f1)
df -PhT ext4.loop

# workaround to demonstrate filesystem can be resized, just not when mounted
umount ext4.loop/
e2fsck -fy ext4.img
resize2fs ext4.img
mount -o loop ext4.img ext4.loop
df -PhT ext4.loop

BTW, this was tested on Ubuntu Lucid 10.04.

Regards,
- Robert
Robert Citek
2010-10-06 00:25:02 UTC
Permalink
Forgot to post the error message at the resize step:

# resize2fs $(mount | grep ext4.loop | cut -d" " -f1)
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/loop0 is mounted on /tmp/ext4/ext4.loop; on-line
resizing required
old desc_blocks = 1, new_desc_blocks = 40
Performing an on-line resize of /dev/loop0 to 10240000 (1k) blocks.
resize2fs: Operation not permitted While trying to add group #640

Regards,
- Robert
Post by Robert Citek
I'm running into some kind of limit for expanding a mounted file
system. ?Does anyone know of a workaround that allows me to expand yet
keep the filesystem mounted?
In brief, I have a mounted filesystem that I want to make larger, e.g.
from 5MB to 10GB. ?However, resize2fs gets about half-way before
stopping with an error. ?Nothing on the filesystem seems to be broken,
I just can't make it any larger. ?If I unmount, fsck, resize, and
mount again, that works just fine. ?But I'd rather not unmount. ?Or if
I do need to unmount, only unmount to change some setting on the
filesystem and not do a full fsck. (still googling to figure out what
that setting might be.)
Here's a simple script to replicate the issue I'm having. ?It needs to
be run as root. ?So, if you are not comfortable with that, please do
not run it.
# code to demonstrate issue
dd if=/dev/zero of=ext4.img bs=1M count=10000
mkfs.ext4 -F ext4.img 5M
mkdir -p ext4.loop
mount -o loop ext4.img ext4.loop
df -PhT ext4.loop
resize2fs $(mount | grep ext4.loop | cut -d" " -f1)
df -PhT ext4.loop
# workaround to demonstrate filesystem can be resized, just not when mounted
umount ext4.loop/
e2fsck -fy ext4.img
resize2fs ext4.img
mount -o loop ext4.img ext4.loop
df -PhT ext4.loop
BTW, this was tested on Ubuntu Lucid 10.04.
Regards,
- Robert
Robert Citek
2010-10-07 03:35:26 UTC
Permalink
Post by Robert Citek
# workaround to demonstrate filesystem can be resized, just not when mounted
umount ext4.loop/
e2fsck -fy ext4.img
resize2fs ext4.img
mount -o loop ext4.img ext4.loop
df -PhT ext4.loop
I should have resized the filesystem on the loopback device, e.g.
/dev/loop0. When that happens you cannot resize an ext4 filesystem,
even when unmounted. Here's some code to demonstrate, again run as
root:

dd if=/dev/zero of=ext4.img bs=1M count=10000
dev=$(losetup -vf ext4.img| cut -d" " -f4)
mkfs.ext4 ${dev} 5M
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 3G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 2G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 3G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 5G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 3G

At this point resize2fs returns an error:

resize2fs: /dev/loop0: The combination of flex_bg and
!resize_inode features is not supported by resize2fs.

This means the filesystems is 5GB forever. It cannot be resized,
expanded or shrunk.

In contrast, ext3 does not have this issue.

mkfs.ext3 ${dev} 5M
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 3G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 2G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 3G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 5G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 3G


Workaround: when creating an ext4 filesystem, use the extended option
resize=. For example:

mkfs.ext4 -E resize=100000000000 ${dev} 5M
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 5G
tune2fs -l ${dev} | grep -i gdt
resize2fs ${dev} 3G

This option can be added to /etc/mke2fs.conf. Technically, using
resize= is not really a workaround. It merely postpones the problem
to a bigger sized file system.

Regards,
- Robert

Loading...