how to calculate correct values for resize2fs

Bodo Thiesen bothie at
Sat Jun 27 10:46:47 UTC 2009

Hello Jelle

1. Please don't CC to poster if you answer, we are all on this list and
   get the messages anyways.

2. And please don't full-quote if not *really* necessary.

3. From your other mail:
   > The problem is I have to automate this process
   That's an important information you forgot to mention in the initial
   post ;)

* Jelle de Jong <jelledejong at> hat geschrieben:

> $ fdisk -l /dev/sda
> Disk /dev/sda: 4034 MB, 4034838528 bytes

> bc <<< "4034-16"
> resize2fs /dev/sda1 4018M
> # result: partition is only 983973 (4K) blocks
> # requested: 1028608 blocks
> # will not fit exiting

4034838528 is 3847 MB and not 4034 like fdisk told you. Obviously fdisk is 
using that bogus SI-numbering.

4018*1024^2 is 1028608 clusters and the underlaying block device of the 
file system only supports 983973 clusters (which it already provides).

So: Take the bytes value, devide it by 1024^2 to gain the real number of
MBs and subtract 18 (not 16) MB in the first call to resize2fs like this:

resize2fs -p /dev/sda1 $(echo "
		export LANG=C
		fdisk -l /dev/sda | grep sda: | awk '{ print $5 }'
" | bc)

Then shrink the partition by 16 MB then resize2fs /dev/sda1 without
argument again to fill up the unused space again.

Remember my advice from the previous mail I'v written as well.

Regards, Bodo

More information about the Ext3-users mailing list