Find the answer to your Linux question:
Results 1 to 8 of 8
Any guru here know about Linux disk block size setting? i assume it should be 512bytes, but no command that I know can list that value out. also puzzled by ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    14

    Linux disk block size...help please


    Any guru here know about Linux disk block size setting? i assume it should be 512bytes, but no command that I know can list that value out. also puzzled by the block size of fdisk partition (fdisk -l), is that that block size is the actual block size? as for fdisk, block size= unit size / 1024, unit size=512 * sector * sector per track, sometimes this size can be some weird number such as 504 bytes.

    thanks for help and input in any form.

    the output from linux raid is also in blocks, is this block same as the block in fdisk output? (cat /proc/mdstat)

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Any time Linux refers to block size, it is almost always 1024 bytes - Linux uses 1024-byte blocks as its primitive units for the buffer cache and everything The only times it isn't is in filesystem-specific drivers, since some filesystems use other granularities (for example, on a normal-sized ext3 filesystem, the filesystem block size is usually 4096 bytes). However, you almost never get to see the filesystem block size; almost the only way to actually see it is to be a kernel hacker or run programs like dumpe2fs.

    What you are referring to with fdisk isn't actually a "block" size, but a cylinder size. A "cylinder" is the primitive unit of the standard PC partition table, and you will never ever have to worry about it except when you are using fdisk (it comes from the old bad days, before IDE hard drives, when the BIOS had to work with disk cylinders).

  3. #3
    Just Joined!
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    14
    thanks pal, so the output of "block" for fdisk would have nothing to do with block size in general term? just wonder if there is any command to list out device block size (for device with no file system sitting on top of it, i.e, dumpe2fs can not be used to product output).

    i am working on a project to compute the acutal disk usage, but just can not find a firm definition on this....like to learn more from you. thanks...


    sample output from RAID device of my server (size in blocks, and seems the block size here have some relationship with the block number listed by fdisk)
    ----------------------------------------------------------------------
    Personalities : [linear] [raid0] [raid1] [raid5]
    read_ahead 1024 sectors
    Event: 5
    md4 : active raid5 hdb16[2] hdb15[1] hdb1[0]
    1606272 blocks level 5, 4k chunk, algorithm 0 [3/3] [UUU]

    md3 : active raid5 hdb14[3] lvmb[2] hdb2[1] lvma[0]
    1240896 blocks level 4, 4k chunk, algorithm 0 [4/4] [UUUU]

    md2 : active raid1 hdb4[1] hdb5[0]
    803136 blocks [2/2] [UU]

    md1 : active raid0 hdb6[1] hdb7[0]
    1606272 blocks 4k chunks

    md0 : active linear hdb8[1] hdb9[0]
    1606272 blocks 32k rounding



    sample output from fdisk -l of my server
    ----------------------------------------
    fdisk -l

    fdisk -l

    Disk /dev/hda: 6448 MB, 6448619520 bytes
    255 heads, 63 sectors/track, 784 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/hda1 1 81 650601 83 Linux
    /dev/hda2 82 146 522112+ 82 Linux swap
    /dev/hda3 147 537 3140707+ 83 Linux
    /dev/hda4 * 538 784 1984027+ 83 Linux

    Disk /dev/hdb: 15.3 GB, 15393079296 bytes
    255 heads, 63 sectors/track, 1871 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/hdb1 1 100 803218+ 83 Linux
    /dev/hdb2 101 200 803250 83 Linux
    /dev/hdb3 201 1770 12611025 5 Extended
    /dev/hdb4 1771 1871 811282+ 83 Linux
    /dev/hdb5 201 300 803218+ 83 Linux
    /dev/hdb6 301 400 803218+ 83 Linux
    /dev/hdb7 401 500 803218+ 83 Linux
    /dev/hdb8 501 600 803218+ 83 Linux
    /dev/hdb9 601 700 803218+ 83 Linux
    /dev/hdb10 800 900 811282+ 8e Linux LVM
    /dev/hdb11 701 799 795154+ 8e Linux LVM
    /dev/hdb12 901 1000 803218+ 8e Linux LVM
    /dev/hdb13 1001 1100 803218+ 8e Linux LVM
    /dev/hdb14 1101 1200 803218+ 8e Linux LVM
    /dev/hdb15 1201 1300 803218+ 8e Linux LVM
    /dev/hdb16 1301 1770 3775243+ 8e Linux LVM








    Quote Originally Posted by Dolda2000
    Any time Linux refers to block size, it is almost always 1024 bytes - Linux uses 1024-byte blocks as its primitive units for the buffer cache and everything The only times it isn't is in filesystem-specific drivers, since some filesystems use other granularities (for example, on a normal-sized ext3 filesystem, the filesystem block size is usually 4096 bytes). However, you almost never get to see the filesystem block size; almost the only way to actually see it is to be a kernel hacker or run programs like dumpe2fs.

    What you are referring to with fdisk isn't actually a "block" size, but a cylinder size. A "cylinder" is the primitive unit of the standard PC partition table, and you will never ever have to worry about it except when you are using fdisk (it comes from the old bad days, before IDE hard drives, when the BIOS had to work with disk cylinders).

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The thing with fdisk is that it uses several units. Sample output:
    Code:
    Disk /dev/hda: 20.0 GB, 20020396032 bytes
    255 heads, 63 sectors/track, 2434 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot    Start       End    Blocks   Id  System
    /dev/hda1   *         1        10     80293+  83  Linux
    /dev/hda2            11        43    265072+   6  FAT16
    /dev/hda3            44        59    128520   82  Linux swap
    /dev/hda4            60      2434  19077187+   f  Win95 Ext'd (LBA)
    /dev/hda5            60      1400  10771551   83  Linux
    /dev/hda6          1401      2368   7775428+  83  Linux
    /dev/hda7          2369      2433    522081   82  Linux swap
    As you can see, the "Start" and "End" columns are clearly specified in another unit than the "Blocks" column (unless 10 - 1 actually is 80293... =) ). The Start and End columns are specified in cylinders, and it is the size of the cylinder that is described in the third line of the header ("Units = cylinders of..."). The Blocks column, on the other hand, is described using the same block size as the rest of the system, 1024 bytes.

    Computing the actual disk space is easier than that, though. I don't know if you program in C, but using the stat() syscall, you get st_blksize returned in the stat buffer, which indicates the block size of the filesystem. You also get st_blocks, which indicates the number of blocks used by the file.

    You don't even need to create your own utility for it though; "du" already does that.

  6. #5
    Just Joined!
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    14

    thanks for reply, just want to deep further....

    thanks...your message really helps, thanks, just to clear more doubt as i can not get anyone so familiar with linux around me... .

    before this project, i always thought "block size" refer to file system block size, but now seems it is not really, it also used to describe device (or partition) size (with no file system mount /build on it), all device size output is in blocks, (e.g /proc/partitions or sfdisk -s ), also there are those funny rounding up or down (e.g 80293+, 265072+), which i felt would not accurately reflect the actual disk size.

    yes, i am using C, look at function such as ioctl and stat (thanks for your input), but i want to know the linux internal mechanism before writing the code.

    i think df can not be used if there is not file system, isn't it? just have a test on my system and output sounds weird.

    thanks, but want to make this issue crystal clear.

    Quote Originally Posted by Dolda2000
    The thing with fdisk is that it uses several units. Sample output:
    Code:
    Disk /dev/hda: 20.0 GB, 20020396032 bytes
    255 heads, 63 sectors/track, 2434 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot    Start       End    Blocks   Id  System
    /dev/hda1   *         1        10     80293+  83  Linux
    /dev/hda2            11        43    265072+   6  FAT16
    /dev/hda3            44        59    128520   82  Linux swap
    /dev/hda4            60      2434  19077187+   f  Win95 Ext'd (LBA)
    /dev/hda5            60      1400  10771551   83  Linux
    /dev/hda6          1401      2368   7775428+  83  Linux
    /dev/hda7          2369      2433    522081   82  Linux swap
    As you can see, the "Start" and "End" columns are clearly specified in another unit than the "Blocks" column (unless 10 - 1 actually is 80293... =) ). The Start and End columns are specified in cylinders, and it is the size of the cylinder that is described in the third line of the header ("Units = cylinders of..."). The Blocks column, on the other hand, is described using the same block size as the rest of the system, 1024 bytes.

    Computing the actual disk space is easier than that, though. I don't know if you program in C, but using the stat() syscall, you get st_blksize returned in the stat buffer, which indicates the block size of the filesystem. You also get st_blocks, which indicates the number of blocks used by the file.

    You don't even need to create your own utility for it though; "du" already does that.

  7. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The problem with this is that there are four distinct units that you must be keeping in mind. To make things even worse, two of these units bear the same name. These are the different units:

    1. Hardware block size, "sector size"
    2. Filesystem block size, "block size"
    3. Kernel buffer cache block size, "block size"
    4. Partition table block size, "cylinder size"

    To differentiate between the filesystem block size and the buffer cache block size, I will follow FAT terminology and use "cluster size" for the filesystem block size.

    The sector size is the units that the hardware deals with. This ranges between different hardware types, but most PC-style hardware (floppies, IDE disks, etc.) use 512 byte sectors.

    The cluster size is the allocation unit that the filesystem uses, and is what causes fragmentation - I'm sure you know about that. On a moderately sized ext3 filesystem, this is usually 4096 bytes, but you can check that with dumpe2fs. Remember that these are also usually called "blocks", only that I refer to them as clusters here.
    The cluster size is what gets returned in st_blksize in the stat buffer, in order for programs to be able to calculate the actual disk usage of a file.

    The block size is the size of the buffers that the kernel uses internally when it caches sectors that have been read from storage devices (hence the name "block device"). Since this is the most primitive form of storage in the kernel, all filesystem cluster sizes must be multiples of this. This block size is also what is almost always referred to by userspace programs. For example, when you run "du" without the -h or -H options, it will return how many of these blocks a file takes up. df will also report sizes in these blocks, the "Blocks" column in the fdisk -l output is of this type, and so on. It is what is most commonly referred to as a "block". Two disk sectors fit into each block.

    The cylinder size is only used in the partition table and by the BIOS (and the BIOS isn't used by Linux).

    "df" only operates on filesystems, so, no, it can't be used without a filesystem - without a filesystem, the data that it would return doesn't exist. "du" operates on individual files.

  8. #7
    Just Joined!
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    14
    many thanks guru... wasted one day google up and down read Linux document here and there but can not get a clear answer..but now I am sure I got it.

    it is great pleasure to find this forum and get to know you, thank you very much.... I will visit this forum frequently for now onwards...countless thanks..

  9. #8
    Just Joined!
    Join Date
    Apr 2011
    Posts
    1

    I was wondering about data sizes, was working with an iomega hdd

    I was wondering about data sizes, was working with an iomega hdd.
    It is a network drive that the network component crapped out on it.
    I removed the drive from the case, connected to a USB case and attempted to read it in Windows with no luck. I then plugged it into to a virtual version of Ubuntu.
    I was able to read data but not copy it to another drive.
    I tried sharing the drive on ubuntu but after ten times with Ubuntu not being able to download files to make Samba work I gave up and ordered another iomega drive with the same model number. Hopefully I can get the almost one terabyte of data off it.

    Ed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •