62

How do I determine the block size of an ext3 partition on Linux?

8 Answers 8

75
# tune2fs -l /dev/sda1 | grep -i 'block size'
Block size:               1024

Replace /dev/sda1 with the partition you want to check.

50

Without root, without writing, and for any filesystem type, you can do:

stat -fc %s .

This will give block size of the filesystem mounted in current directory (or any other directory specified instead of the dot).

4
  • 3
    Don't forget the dot at the end of that command as stat -f is expecting is expecting a folder to give you stats about. Jan 9, 2017 at 0:11
  • And to further narrow it down to what the OP asked for: stat --printf='%s' -f . May 19, 2017 at 15:01
  • 1
    with newlinestat --printf='%s\n' -f .
    – c4f4t0r
    Mar 28, 2018 at 9:48
  • 1
    @JaniUusitalo, @c4f4t0r: thanks for the hint, corrected the answer using -c which is simpler than --printf='...\n'
    – mik
    Mar 28, 2018 at 14:14
13
dumpe2fs -h /dev/md2

will output something with:

Block size:               4096
Fragment size:            4096
10

In the case where you don't have the right to run tune2fs on a device (e.g. in a corporate environment) you can try writing a single byte to a file on the partition in question and check the disk usage:

echo 1 > test
du -h test
7

On x86, a filesystem block is just about always 4KiB - the default size - and never larger than the size of a memory page (which is 4KiB).

4
  • 1
    This is the same on every platform, the largest block size is supported by ext2/3 is 4096 bytes. Jun 23, 2009 at 10:06
  • Thanks Dave! I learned something today ;-) I originally thought the ext3 blocksize could be 8k on platforms that supported 8k memory pages.
    – wzzrd
    Jun 23, 2009 at 12:44
  • Wikipedia says it can be 8k: en.wikipedia.org/wiki/Ext3#Size_limits
    – dfrankow
    Apr 25, 2012 at 22:41
  • 1
    @dfrankow: if you have 8k memory pages, such as on Alpha hardware, yes. But you do not have those on x86 hardware and that is what I was talking about.
    – wzzrd
    Apr 26, 2012 at 8:03
5

To detect block size of required partition:

  1. Detect partition name:

    $ df -h
    

    for example we have /dev/sda1

  2. Detect block size for this partition:

    $ sudo blockdev --getbsz /dev/sda1
    
0
stat <<Filename>>

will also give file size in blocks

1
  • This is not what the OP asked
    – Pablo A
    Jul 3, 2019 at 7:55
0

Use

sudo dumpe2fs /dev/sda1 | grep "Block size"

where /dev/sda1 is the device partition. You can get it from lsblk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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