Skip to content

How to get disk block size in Linux

homepage-banner

Introduction

When working with storage devices in Linux, it is important to know the block size of your disk. The block size is the smallest unit of data that can be read or written to a storage device. Understanding the block size is important when formatting disks, setting up file systems, and performing disk operations. In this blog post, we will discuss how to check disk block size in Linux.

Using the lsblk Command

One way to check the block size of your disk in Linux is by using the lsblk command. The lsblk command lists all the available block devices along with their attributes such as size, mount point, and block size. To use the lsblk command, open a terminal and type the following command:

lsblk -o NAME,SIZE,PHY-SEC

This command will display a table with the name, size, and physical sector size of all block devices.

Using the blockdev Command

Another way to check disk block size in Linux is by using the blockdev command. The blockdev command is used to set or display block device attributes. To check the block size of your disk, open a terminal and type the following command:

blockdev --getbsz /dev/sda

Replace /dev/sda with the name of your block device. This command will display the block size of your disk in bytes.

Using the file Command

You can also use the file command to check the block size of your disk in Linux. The file command is used to determine the type of a file. To check the block size of your disk, open a terminal and type the following command:

file -s /dev/sda

Replace /dev/sda with the name of your block device. This command will display a summary of the file system on the disk, including the block size.

Using tune2fs Command

tune2fs -l /dev/vda1 | grep "Block size"
tune2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          /
Filesystem UUID:          927497f9-eae9-4a2b-bd8b-162997d80076
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              1770496
Block count:              7339472
Reserved block count:     366953
Free blocks:              5384282
Free inodes:              1576749
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      243
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         7904
Inode blocks per group:   494
Flex block group size:    16
Filesystem created:       Thu Oct 10 06:31:31 2019
Last mount time:          Fri Feb 12 02:14:14 2021
Last write time:          Fri Feb 12 02:14:10 2021
Mount count:              13
Maximum mount count:      -1
Last checked:             Sun Jan 17 03:21:58 2021
Check interval:           0 (<none>)
Lifetime writes:          5965 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
First orphan inode:       6649
Default directory hash:   half_md4
Directory Hash Seed:      19cc95a6-03cd-4dc2-86d2-78b70b1bbbba
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x1377592d

Conclusion

In this blog post, we discussed three ways to check disk block size in Linux. Knowing the block size of your disk is important when working with storage devices in Linux. The lsblk, blockdev, and file commands are all useful tools for checking the block size of your disk. By using these commands, you can ensure that your disk is properly formatted and optimized for performance.

Leave a message







Disclaimer
  • Welcome to visit the knowledge base of SRE and DevOps!
  • License under CC BY-NC 4.0
  • Made with Material for MkDocs and improve writing by generative AI tools
  • Copyright issue feedback me#imzye.com, replace # with @