The  blockdev  command  is  part  of  the  util-linux-ng  package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.

it call block device ioctls from the command line, which allows us to check and set block devices attributes on Linux.

Here are some most used  command examples:

Get block device read ahead buffer size

# blockdev --getra /dev/sda
256

There is another command getfra, to get filesystem read ahead buffer, same as this.

The number 256 is number of blocks, which is 512kb/block, so default read ahead buffer for the block device is 128kb.

Set block device read ahead buffer size

Proper tunned read ahead buffer can significently improve disk read performance.

# blockdev --setra 4096 /dev/sda

The command above set read ahead buffer 2MB for /dev/sda

There is another command setfra, to set filesystem read ahead buffer, same as this.

Set blockdev read only mode

# blockdev --setro /dev/sda

Note: if you want set a blockdev partition to read only mode,

Get sector size

blockdev --getss /dev/sda
512

The nuber is in 512kb size.

Get block device size in sectors

# blockdev --getsz /dev/sda
585725952

Get block size

blockdev --getbss /dev/sda
512

The nuber is in 512kb size.

Set block size, can't do it on the fly

blockdev --setbsz 1024 /dev/sda
BLKBSZSET: Device or resource busy

Get block device size in bytes

# blockdev --getsize64 /dev/sda
299891687424

Get blockdev read only mode

# blockdev --getro /dev/sda
1 # if the read only mode is set

Set blockdev read write mode

# blockdev --setrw /dev/sda

Note: if you want set a blockdev partition to read only mode,

Get blockdev read write mode

# blockdev --getrw /dev/sda
1 # if the read write mode is set

Flush buffer

To flush block device buffer

# blockdev --flushbufs /dev/sda

Reread partition table

In case you want to reread blockdev partition table, run

# blockdev --rereadpt /dev/sda
BLKRRPART: Device or resource busy
# blockdev --rereadpt /dev/sdb

Options

Beside above sub commands, blockdev also offer some options

-V        Print version and exit. 
-q     Be quiet.
-v     Be verbose.
--report Print a report for devices(In 512 byte sector).

Here is a example of option --report

# blockdev --report
RO    RA   SSZ   BSZ   StartSec            Size   Device
rw 16384   512  4096          0    299891687424   /dev/sda
rw 16384   512  1024       2048       212808192   /dev/sda1
rw 16384   512  4096     417689      1571028480   /dev/sda2
rw 16384   512  4096    3486104      2146798080   /dev/sda3
rw 16384   512  1024    7679069    295953800192   /dev/sda4
rw   256   512  4096          0   1649267441664   /dev/sds
rw   256   512  4096          0   1749393866752   /dev/sdr
...