how to calculate correct values for resize2fs

Bodo Thiesen bothie at
Sat Jun 27 18:54:27 UTC 2009

* Jelle de Jong <jelledejong at> hat geschrieben:

> Ok I seems to have missed a part and that is that after the resizing of
> the file system I have to resize the partition to make the free space.
> Then I have to make the file system fit the partition again, and after
> that I can make a new partition in the free space.

It's not 100%ly needed to do it this way, but doing it by exactly
calculating the needed size is just error prone, so this is the way, *I*
would do it (because it doesn't do any harm this way but helps preventing

> Disk /dev/loop0: 104 MB, 104857600 bytes
> 4 heads, 32 sectors/track, 1600 cylinders, total 204800 sectors
> Units = sectors of 1 * 512 = 512 bytes
> Disk identifier: 0x0000cef3
>       Device Boot      Start         End      Blocks   Id  System
> /dev/loop0p1   *          32      102399       51184   83  Linux
> /dev/loop0p2          102400      204799       51200   83  Linux
> echo "32*512" | bc
> 16384
> losetup -o 16384 /dev/loop1 /dev/loop0
> echo "32*102400" | bc
> 3276800

104857600/512=204800, so the disk image is 204800 blocks. The start 
values are in blocks. So, 32*512 is ok, but the other value has to be
102400*512 then ...

> losetup -o 3276800 /dev/loop2 /dev/loop0

... which leads to

losetup -o 52428800 /dev/loop2 /dev/loop0

> sudo losetup -a
> fdisk -l /dev/loop0
> mkfs.ext2 /dev/loop1
> mkfs.ext4 /dev/loop2

Because of the wrong second losetup, the latter mkfs damages the first
file system obviously (which doesn't neccessarily cause troubles like in
this test case - but it might have).

> /sbin/parted --script /dev/loop0 \
> resize 1 0 88080384B \
> print
> Error: File system has an incompatible feature enabled.  Compatible
> features are has_journal, dir_index, filetype, sparse_super and
> large_file.  Use tune2fs or debugfs to remove features.

You should be able to 'rm' the partition and then 'mkpart' it with the new
size. (I don't know parted, maybe you will have to use fdisk for that, if
parted doesn't want you to create a partition without destroying the data
in it, just test it.)

Regards, Bodo

More information about the Ext3-users mailing list