直接输入命令会列出 Linux 系统下所有块设备信息,包括 loopdisklvmpart 等。

$ sudo lsblk 
NAME                  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1                   7:1    0  86.5M  1 loop /snap/core/4407
sdd                     8:48   0    10G  0 disk 
sdb                     8:16   0    20G  0 disk 
└─ubuntu--vg-root     253:0    0  27.5G  0 lvm  /
sr0                    11:0    1  1024M  0 rom  
loop2                   7:2    0  81.7M  1 loop /snap/core/4206
loop0                   7:0    0 180.5M  1 loop /snap/vlc/190
sdc                     8:32   0    10G  0 disk 
sda                     8:0    0    10G  0 disk 
├─sda2                  8:2    0     1K  0 part 
├─sda5                  8:5    0   9.5G  0 part 
│ ├─ubuntu--vg-swap_1 253:1    0     2G  0 lvm  [SWAP]
│ └─ubuntu--vg-root   253:0    0  27.5G  0 lvm  /
└─sda1                  8:1    0   487M  0 part /boot

只查看 scsi 设备

-S 参数

$ sudo lsblk -S
NAME HCTL       TYPE VENDOR   MODEL             REV TRAN
sdd  5:0:0:0    disk ATA      VBOX HARDDISK    1.0  sata
sdb  3:0:0:0    disk ATA      VBOX HARDDISK    1.0  sata
sr0  1:0:0:0    rom  VBOX     CD-ROM           1.0  ata
sdc  4:0:0:0    disk ATA      VBOX HARDDISK    1.0  sata
sda  2:0:0:0    disk ATA      VBOX HARDDISK    1.0  sata

只查看 sata 设备

-I 参数,指定要显示的设备类型,值为 major device numbers

$ sudo lsblk -I 8
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdd                     8:48   0   10G  0 disk 
sdb                     8:16   0   20G  0 disk 
└─ubuntu--vg-root     253:0    0 27.5G  0 lvm  /
sdc                     8:32   0   10G  0 disk 
sda                     8:0    0   10G  0 disk 
├─sda2                  8:2    0    1K  0 part 
├─sda5                  8:5    0  9.5G  0 part 
│ ├─ubuntu--vg-swap_1 253:1    0    2G  0 lvm  [SWAP]
│ └─ubuntu--vg-root   253:0    0 27.5G  0 lvm  /
└─sda1                  8:1    0  487M  0 part /boot

排除 ata 设备

-e 参数,指定要排除的设备类型,值为 major device numbers

$ sudo lsblk -Sp -e 11
NAME     HCTL       TYPE VENDOR   MODEL             REV TRAN
/dev/sdd 5:0:0:0    disk ATA      VBOX HARDDISK    1.0  sata
/dev/sdb 3:0:0:0    disk ATA      VBOX HARDDISK    1.0  sata
/dev/sdc 4:0:0:0    disk ATA      VBOX HARDDISK    1.0  sata
/dev/sda 2:0:0:0    disk ATA      VBOX HARDDISK    1.0  sata

格式化输出

-o 参数

$ sudo lsblk -o NAME,SIZE,TYPE
NAME                    SIZE TYPE
loop1                  86.5M loop
sdd                      10G disk
sdb                      20G disk
└─ubuntu--vg-root      27.5G lvm
sr0                    1024M rom
loop2                  81.7M loop
loop0                 180.5M loop
sdc                      10G disk
sda                      10G disk
├─sda2                    1K part
├─sda5                  9.5G part
│ ├─ubuntu--vg-swap_1     2G lvm
│ └─ubuntu--vg-root    27.5G lvm
└─sda1                  487M part

输出 JSON 格式信息

-J 参数

$ sudo lsblk -JSp -I 8 -o NAME
{
   "blockdevices": [
      {"name": "/dev/sdd"},
      {"name": "/dev/sdb"},
      {"name": "/dev/sdc"},
      {"name": "/dev/sda"}
   ]
}

帮助

$ lsblk --help

Usage:
 lsblk [options] [<device> ...]

List information about block devices.

选项:
 -a, --all            print all devices
 -b, --bytes          print SIZE in bytes rather than in human readable format
 -d, --nodeps         don't print slaves or holders
 -D, --discard        print discard capabilities
 -e, --exclude <list> exclude devices by major number (default: RAM disks)
 -f, --fs             output info about filesystems
 -i, --ascii          use ascii characters only
 -I, --include <list> show only devices with specified major numbers
 -J, --json           use JSON output format
 -l, --list           use list format output
 -m, --perms          output info about permissions
 -n, --noheadings     don't print headings
 -o, --output <list>  output columns
 -O, --output-all     output all columns
 -p, --paths          print complete device path
 -P, --pairs          use key="value" output format
 -r, --raw            use raw output format
 -s, --inverse        inverse dependencies
 -S, --scsi           output info about SCSI devices
 -t, --topology       output info about topology
 -x, --sort <column>  sort output by <column>

 -h, --help     display this help and exit
 -V, --version  output version information and exit

Available columns (for --output):
        NAME  device name
       KNAME  internal kernel device name
     MAJ:MIN  major:minor device number
      FSTYPE  filesystem type
  MOUNTPOINT  where the device is mounted
       LABEL  filesystem LABEL
        UUID  filesystem UUID
    PARTTYPE  partition type UUID
   PARTLABEL  partition LABEL
    PARTUUID  partition UUID
   PARTFLAGS  partition flags
          RA  read-ahead of the device
          RO  read-only device
          RM  removable device
     HOTPLUG  removable or hotplug device (usb, pcmcia, ...)
       MODEL  device identifier
      SERIAL  disk serial number
        SIZE  size of the device
       STATE  state of the device
       OWNER  user name
       GROUP  group name
        MODE  device node permissions
   ALIGNMENT  alignment offset
      MIN-IO  minimum I/O size
      OPT-IO  optimal I/O size
     PHY-SEC  physical sector size
     LOG-SEC  logical sector size
        ROTA  rotational device
       SCHED  I/O scheduler name
     RQ-SIZE  request queue size
        TYPE  device type
    DISC-ALN  discard alignment offset
   DISC-GRAN  discard granularity
    DISC-MAX  discard max bytes
   DISC-ZERO  discard zeroes data
       WSAME  write same max bytes
         WWN  unique storage identifier
        RAND  adds randomness
      PKNAME  internal parent kernel device name
        HCTL  Host:Channel:Target:Lun for SCSI
        TRAN  device transport type
  SUBSYSTEMS  de-duplicated chain of subsystems
         REV  device revision
      VENDOR  device vendor

For more details see lsblk(8).

参考