Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to shrink an ext4 filesystem to make room for a new partition and came across the resize2fs program. The command looks like this:

resize2fs -p /dev/mapper/ExistingExt4 $size

How should I determine $size if I want to substract exactly 15 GiB from the current ext4 filesystem? Can I use the output of df somehow?

share|improve this question

1 Answer 1

up vote 14 down vote accepted

You should not use df because it shows the size as reported by the filesystem (in this case, ext4).

Use the dumpe2fs -h /dev/mapper/ExistingExt4 command to find out the real size of the partition. The -h option makes dumpe2fs show super block info without a lot other unnecessary details. From the output, you need the block count and block size.

Block count:              19506168  
Reserved block count:     975308  
Free blocks:              13750966  
Free inodes:              4263842  
First block:              0  
Block size:               4096  

Multiplicating these values will give the partition size in bytes. The above numbers happen to be a perfect multiple of 1024:

$ python -c 'print 19506168.0 * 4096 / 1024'

Since you want to shrink the partition by 15 GiB (which is 15 MiB times 1 KiB):

$ python -c 'print 19506168.0 * 4096 / 1024  -  15 * 1024 * 1024'

As resize2fs accepts several kinds of suffixes, one of them being K for "1024 bytes", the command for shrinking the partition to 62296032 KiB becomes:

resize2fs -p /dev/mapper/ExistingExt4 62296032K

Without unit, the number will be interpreted as a multiple of the filesystem's blocksize (4096 in this case). See man resize2fs(8)

share|improve this answer
Very informative answer! –  Bram Jun 19 '12 at 15:02
man resize2fs: Optionally, the size parameter may be suffixed by one of the following the units designators: 's', 'K', 'M', or 'G', for 512 byte sectors, kilobytes, megabytes, or gigabytes, respectively. May be simpler than doing block calculations. –  lkraav Jun 7 at 9:53
Aren't you missing a k at resize2fs -p /dev/mapper/ExistingExt4 62296032 ? –  Sopalajo de Arrierez Jul 19 at 21:37
@SopalajodeArrierez You are right, a capital K was missing. Without this letter, resize2fs should complain in my case as the size is larger than the actual disk. –  Lekensteyn Jul 19 at 22:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.