Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of the Linux command lsblk

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "the usage of Linux command lsblk". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The lsblk command is used to list information about all available block devices and also shows the dependencies between them, but it does not list information about RAM disks. Block devices include hard drives, flash drives, cd-ROM and so on. The lsblk command is included in the util-linux-ng package, which is now renamed util-linux. This package comes with several other tools, such as dmesg. To install lsblk, you need to download the util-linux package. Fedora users can install the package by using the command sudo yum install util-linux-ng.

1. Command format

Lsblk (option)

2. Option parameters

-a,-- all displays all devices.

-b,-- bytes displays the device size in bytes mode.

-d,-- nodeps does not display slaves or holders.

-D,-- discard print discard capabilities.

-e,-- exclude exclusion device (default: RAM disks).

-f,-- fs displays file system information.

-h,-- help displays help information.

-I-- ascii use ascii characters only.

-m,-- perms displays permission information.

-l,-- list is displayed in list format.

-n,-- noheadings does not display the title.

-o,-- output output column.

-P,-- pairs is displayed in key= "value" format.

-r,-- raw is displayed in the original format.

-t,-- topology displays topology information.

3. Use examples

The lsblk command lists all block devices in a tree by default.

[root@wjq ~] # lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

Sda 8:0 0 70G 0 disk

├─ sda1 8:1 0 1G 0 part / boot

└─ sda2 8:2 0 68G 0 part

├─ cl-root 253:0 0 54.3G 0 lvm /

├─ cl-swap 253:1 0 3G 0 lvm [SWAP]

└─ cl-home 253:2 0 10.7G 0 lvm / home

Sr0 11:0 1 4.1G 0 rom

Description:

NAME: this is the name of the block device.

MAJ:MIN: this column shows the primary and secondary device numbers.

RM: this column shows whether the device is removable. Note that in this example, the RM values of devices sdb and sr0 are equal to 1, indicating that they are removable devices.

SIZE: this column lists the capacity size information of the device. For example, 298.1g indicates that the size of the device is 298.1GB, while 1K indicates that the size of the device is 1KB.

RO: this item indicates whether the device is read-only. In this case, all devices have a Ro value of 0, indicating that they are not read-only.

TYPE: this column shows whether the block device is a disk or a partition on the disk. In this example, sda and sdb are disks, while sr0 is read-only storage (rom).

MOUNTPOINT: this column indicates the mount point of the device.

The default option does not list all empty devices. To view these empty devices, use the following command:

[root@wjq] # lsblk-a

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

Sda 8:0 0 70G 0 disk

├─ sda1 8:1 0 1G 0 part / boot

└─ sda2 8:2 0 68G 0 part

├─ cl-root 253:0 0 54.3G 0 lvm /

├─ cl-swap 253:1 0 3G 0 lvm [SWAP]

└─ cl-home 253:2 0 10.7G 0 lvm / home

Sr0 11:0 1 4.1G 0 rom

The lsblk command can also be used to list the ownership relationships of a particular device, as well as groups and patterns. You can obtain this information with the following command:

[root@wjq] # lsblk-m

NAME SIZE OWNER GROUP MODE

Sda 70G root disk brw-rw

├─ sda1 1G root disk brw-rw

└─ sda2 68G root disk brw-rw

├─ cl-root 54.3G root disk brw-rw

├─ cl-swap 3G root disk brw-rw

└─ cl-home 10.7G root disk brw-rw

Sr0 4.1G root cdrom brw-rw

This command can also get only the information about the specified device. This can be achieved by specifying the device name after the options provided to the lsblk command. For example, you may be interested in knowing how to display your disk drive size in bytes, then you can do this by running the following command:

[root@wjq] # lsblk-b / dev/sda

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

Sda 8:0 0 75161927680 0 disk

├─ sda1 8:1 0 1073741824 0 part / boot

└─ sda2 8:2 0 73013395456 0 part

├─ cl-root 253:0 0 58346962944 0 lvm /

├─ cl-swap 253:1 0 3221225472 0 lvm [SWAP]

└─ cl-home 253:2 0 11433672704 0 lvm / home

[root@wjq ~] #

[root@wjq] # lsblk-- byte / dev/sda

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

Sda 8:0 0 75161927680 0 disk

├─ sda1 8:1 0 1073741824 0 part / boot

└─ sda2 8:2 0 73013395456 0 part

├─ cl-root 253:0 0 58346962944 0 lvm /

├─ cl-swap 253:1 0 3221225472 0 lvm [SWAP]

└─ cl-home 253:2 0 11433672704 0 lvm / home

You can also combine several options to get the specified output. For example, you might want to list devices in a list format instead of the default tree format. You may also be interested in removing headings from different column names. You can combine two different options to get the desired output, as follows:

[root@wjq ~] # lsblk-nl

Sda 8:0 0 70G 0 disk

Sda1 8:1 0 1G 0 part / boot

Sda2 8:2 0 68G 0 part

Cl-root 253:0 0 54.3G 0 lvm /

Cl-swap 253:1 0 3G 0 lvm [SWAP]

Cl-home 253:2 0 10.7G 0 lvm / home

Sr0 11:0 1 4.1G 0 rom

To get a list of SCSI devices, you can only use the-S option. This option is an uppercase S and cannot be confused with the-s option, which is used to print dependencies in reverse order.

[root@wjq] # lsblk-S

NAME HCTL TYPE VENDOR MODEL REV TRAN

Sda 2:0:0:0 disk VMware Virtual disk 1.0 spi

Sr0 1:0:0:0 rom NECVMWar VMware IDE CDR10 1.00 ata

Lsblk lists SCSI devices, and-s is the reverse option (reversing the organizational relationship between devices and partitions), which gives the following output. Enter the command:

[root@wjq] # lsblk-s

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

Sda1 8:1 0 1G 0 part / boot

└─ sda 8:0 0 70G 0 disk

Sr0 11:0 1 4.1G 0 rom

Cl-root 253:0 0 54.3G 0 lvm /

└─ sda2 8:2 0 68G 0 part

└─ sda 8:0 0 70G 0 disk

Cl-swap 253:1 0 3G 0 lvm [SWAP]

└─ sda2 8:2 0 68G 0 part

└─ sda 8:0 0 70G 0 disk

Cl-home 253:2 0 10.7G 0 lvm / home

└─ sda2 8:2 0 68G 0 part

└─ sda 8:0 0 70G 0 disk

Display file system details

[root@wjq] # lsblk-f

NAME FSTYPE LABEL UUID MOUNTPOINT

Sda

├─ sda1 xfs f3393727-7cd4-4019-bb42-58f72a9d6c00 / boot

└─ sda2 LVM2_member 8ROX0o-brye-H5Vw-r1yz-sM54-MWQx-2fwVFT

├─ cl-root xfs fa7442b0-6895-4154-8713-27ac39b0ee70 /

├─ cl-swap swap c0e0d5ee-7268-4bb3-8bee-9083a4d403f1 [SWAP]

└─ cl-home xfs ab05cb7c-c04c-46bc-ace6-46ccdc73fc07 / home

Sr0 iso9660 CentOS 7 x8634 2016-12-05-13-55-45-00

Use key=value format display

[root@wjq] # lsblk-P

NAME= "sda" MAJ:MIN= "8:0" RM= "0" SIZE= "70G" RO= "0" TYPE= "disk" MOUNTPOINT= ""

NAME= "sda1" MAJ:MIN= "8:1" RM= "0" SIZE= "1G" RO= "0" TYPE= "part" MOUNTPOINT= "/ boot"

NAME= "sda2" MAJ:MIN= "8:2" RM= "0" SIZE= "68G" RO= "0" TYPE= "part" MOUNTPOINT= ""

NAME= "cl-root" MAJ:MIN= "253VR 0" RM= "0" SIZE= "54.3G" RO= "0" TYPE= "lvm" MOUNTPOINT= "/"

NAME= "cl-swap" MAJ:MIN= "253 RM=" 0 "SIZE=" 3G "RO=" 0 "TYPE=" lvm "MOUNTPOINT=" [SWAP] "

NAME= "cl-home" MAJ:MIN= "253 RM=" 0 "SIZE=" 10.7G "RO=" 0 "TYPE=" lvm "MOUNTPOINT=" / home "

NAME= "sr0" MAJ:MIN= "11:0" RM= "1" SIZE= "4.1G" RO= "0" TYPE= "rom" MOUNTPOINT= ""

Display topology information

[root@wjq ~] # lsblk-t

NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME

Sda 0 512 0 512 512 1 deadline 128 4096 32M

├─ sda1 0 512 0 512 512 1 deadline 128 4096 32M

└─ sda2 0 512 0 512 512 1 deadline 128 4096 32M

├─ cl-root 0 512 0 512 512 1 128 4096 32M

├─ cl-swap 0 512 0 512 512 1 128 4096 32M

└─ cl-home 0 512 0 512 512 1 128 4096 32M

Sr0 0 2048 0 2048 2048 1 cfq 128 128 0B

This is the end of the introduction to "the usage of Linux Command lsblk". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report