[转帖]lsblk命令详解

lsblk,命令,详解 · 浏览次数 : 0

小编点评

生成内容时需要带简单的排版,以下是生成内容时需要带的排版: 1. **排版字段:** 将需要排版的字段设置到 `NAME` 和 `FIELD` 中。 2. **排版顺序:** 将需要排版的顺序设置到 `REV` 中。 3. **排版类型:** 将需要排版的类型设置到 `TYPE` 中。 4. **排版值:** 将需要排版的值设置到 `RO` 中。 5. **排版格式:** 将需要排版的格式设置到 `NAME` 中。

正文

https://www.cnblogs.com/ishmaelwanglin/p/11043918.html

 


lsblk命令用来查看block设备的信息.

主要应用场景: 获取wwnid,获取块设备列表,获取块设备类型(ssd,hdd),获取块设备的size等信息.

数据来源: /sys/dev/block

返回码:

0: success
1: failure
32: 找不到所有指定设备
64: 一些设备找到了,一些设备没找到

类似的命令:

findmnt , blkid, ls

帮助信息:

➜  ~ 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, 0是不可旋转(ssd),1是可旋转(hdd)
       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

lsblk 命令输出 default 参数是-a, --all

➜  ~ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1    7:1    0  55.8M  1 loop /snap/kata-containers/288
sdd      8:48   0   1.8T  0 disk 
└─sdd1   8:49   0   1.8T  0 part 
sdb      8:16   0 119.2G  0 disk 
├─sdb2   8:18   0   915M  0 part 
└─sdb1   8:17   0 118.4G  0 part 
loop4    7:4    0  69.8M  1 loop /snap/kata-containers/352
sr0     11:0    1  1024M  0 rom  
loop2    7:2    0  89.4M  1 loop /snap/core/6818
loop0    7:0    0  88.4M  1 loop /snap/core/6964
sde      8:64   0   1.8T  0 disk 
├─sde2   8:66   0   1.8T  0 part 
└─sde1   8:65   0   128M  0 part 
sdc      8:32   0   477G  0 disk 
├─sdc2   8:34   0   372G  0 part /home
├─sdc5   8:37   0   9.5G  0 part [SWAP]
├─sdc3   8:35   0     1K  0 part 
└─sdc1   8:33   0  95.4G  0 part /
loop3    7:3    0  89.3M  1 loop /snap/core/6673

lsblk -b , --bytes ,输出单位为字节

➜  ~ lsblk -b
NAME   MAJ:MIN RM          SIZE RO TYPE MOUNTPOINT
loop1    7:1    0      58478592  1 loop /snap/kata-containers/288
sdd      8:48   0 2000398934016  0 disk 
└─sdd1   8:49   0 2000397795328  0 part 
sdb      8:16   0  128035676160  0 disk 
├─sdb2   8:18   0     959447040  0 part 
└─sdb1   8:17   0  127071901696  0 part 
loop4    7:4    0      73129984  1 loop /snap/kata-containers/352
sr0     11:0    1    1073741312  0 rom  
loop2    7:2    0      93720576  1 loop /snap/core/6818
loop0    7:0    0      92733440  1 loop /snap/core/6964
sde      8:64   0 2000398934016  0 disk 
├─sde2   8:66   0 2000263577600  0 part 
└─sde1   8:65   0     134217728  0 part 
sdc      8:32   0  512110190592  0 disk 
├─sdc2   8:34   0  399469707264  0 part /home
├─sdc5   8:37   0   10239344640  0 part [SWAP]
├─sdc3   8:35   0          1024  0 part 
└─sdc1   8:33   0  102398689280  0 part /
loop3    7:3    0      93581312  1 loop /snap/core/6673

lsblk -D , --discard, 打印discard信息, (没详细查),针对SSD盘,trim相关

➜  ~ lsblk -D
NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
loop1         0        4K       4G         0
sdd           0        4K       2G         0
└─sdd1        0        4K       2G         0
sdb           0      512B       2G         0
├─sdb2        0      512B       2G         0
└─sdb1        0      512B       2G         0
loop4         0        4K       4G         0
sr0           0        0B       0B         0
loop2         0        4K       4G         0
loop0         0        4K       4G         0
sde           0        0B       0B         0
├─sde2        0        0B       0B         0
└─sde1        0        0B       0B         0
sdc           0      512B       2G         0
├─sdc2        0      512B       2G         0
├─sdc5        0      512B       2G         0
├─sdc3        0      512B       2G         0
└─sdc1        0      512B       2G         0
loop3         0        4K       4G         0

DISC-GRAN DISC-MAX 非0说明支持fstrim

lsblk -d [/dev/sdx], --nodeps ,打印指定设备的信息,或者打印所有设备的信息

➜  ~ lsblk -d
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1   7:1    0  55.8M  1 loop /snap/kata-containers/288
sdd     8:48   0   1.8T  0 disk 
sdb     8:16   0 119.2G  0 disk 
loop4   7:4    0  69.8M  1 loop /snap/kata-containers/352
sr0    11:0    1  1024M  0 rom  
loop2   7:2    0  89.4M  1 loop /snap/core/6818
loop0   7:0    0  88.4M  1 loop /snap/core/6964
sde     8:64   0   1.8T  0 disk 
sdc     8:32   0   477G  0 disk 
loop3   7:3    0  89.3M  1 loop /snap/core/6673

➜  ~ lsblk -d /dev/sdc
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdc    8:32   0  477G  0 disk

lsblk -e, --exclude list , 排除major id列表

➜  ~ lsblk -e 7
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdd      8:48   0   1.8T  0 disk 
└─sdd1   8:49   0   1.8T  0 part 
sdb      8:16   0 119.2G  0 disk 
├─sdb2   8:18   0   915M  0 part 
└─sdb1   8:17   0 118.4G  0 part 
sr0     11:0    1  1024M  0 rom  
sde      8:64   0   1.8T  0 disk 
├─sde2   8:66   0   1.8T  0 part 
└─sde1   8:65   0   128M  0 part 
sdc      8:32   0   477G  0 disk 
├─sdc2   8:34   0   372G  0 part /home
├─sdc5   8:37   0   9.5G  0 part [SWAP]
├─sdc3   8:35   0     1K  0 part 
└─sdc1   8:33   0  95.4G  0 part /
➜  ~ lsblk -e 7,8
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0   11:0    1 1024M  0 rom  

lsblk -f, --fs , 输出设备的文件系统信息

同lsblk -o NAME,FSTYPE,LABEL,UUID,MOUNTPOINT

➜  ~ lsblk -f       
NAME   FSTYPE   LABEL    UUID                                 MOUNTPOINT
loop1  squashfs                                               /snap/kata-containers/288
sdd                                                           
└─sdd1 ntfs     Volume2  CA9015A6901599D1                     
sdb                                                           
├─sdb2 ntfs              30EAC3FEEAC3BE7A                     
└─sdb1 ntfs     OS_WIN10 0600EC5800EC4FEB                     
loop4  squashfs                                               /snap/kata-containers/352
sr0                                                           
loop2  squashfs                                               /snap/core/6818
loop0  squashfs                                               /snap/core/6964
sde                                                           
├─sde2 ntfs     专用存储 B6D47A52D47A1539                     
└─sde1                                                        
sdc                                                           
├─sdc2 ext4              53842090-4ad6-4472-ad35-53b4d7b33bf8 /home
├─sdc5 swap              382e4b22-503e-4911-bf2f-1167af3f3cda [SWAP]
├─sdc3                                                        
└─sdc1 ext4              6b5618d0-a2b0-41f3-a3a5-9eb5a524b0a8 /
loop3  squashfs                                               /snap/core/6673

lsblk -I , --include list ,打印major id列表

➜  ~ lsblk -I 7,8
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1    7:1    0  55.8M  1 loop /snap/kata-containers/288
sdd      8:48   0   1.8T  0 disk 
└─sdd1   8:49   0   1.8T  0 part 
sdb      8:16   0 119.2G  0 disk 
├─sdb2   8:18   0   915M  0 part 
└─sdb1   8:17   0 118.4G  0 part 
loop4    7:4    0  69.8M  1 loop /snap/kata-containers/352
loop2    7:2    0  89.4M  1 loop /snap/core/6818
loop0    7:0    0  88.4M  1 loop /snap/core/6964
sde      8:64   0   1.8T  0 disk 
├─sde2   8:66   0   1.8T  0 part 
└─sde1   8:65   0   128M  0 part 
sdc      8:32   0   477G  0 disk 
├─sdc2   8:34   0   372G  0 part /home
├─sdc5   8:37   0   9.5G  0 part [SWAP]
├─sdc3   8:35   0     1K  0 part 
└─sdc1   8:33   0  95.4G  0 part /
loop3    7:3    0  89.3M  1 loop /snap/core/6673

lsblk -i , --ascii ,将输出信息的字符用ascii码打印

➜  ~ lsblk -i
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1    7:1    0  55.8M  1 loop /snap/kata-containers/288
sdd      8:48   0   1.8T  0 disk 
`-sdd1   8:49   0   1.8T  0 part 
sdb      8:16   0 119.2G  0 disk 
|-sdb2   8:18   0   915M  0 part 
`-sdb1   8:17   0 118.4G  0 part 
loop4    7:4    0  69.8M  1 loop /snap/kata-containers/352
sr0     11:0    1  1024M  0 rom  
loop2    7:2    0  89.4M  1 loop /snap/core/6818
loop0    7:0    0  88.4M  1 loop /snap/core/6964
sde      8:64   0   1.8T  0 disk 
|-sde2   8:66   0   1.8T  0 part 
`-sde1   8:65   0   128M  0 part 
sdc      8:32   0   477G  0 disk 
|-sdc2   8:34   0   372G  0 part /home
|-sdc5   8:37   0   9.5G  0 part [SWAP]
|-sdc3   8:35   0     1K  0 part 
`-sdc1   8:33   0  95.4G  0 part /
loop3    7:3    0  89.3M  1 loop /snap/core/6673

lsblk -J , --json 用json格式输出

➜  ~ lsblk -J
{
   "blockdevices": [
      {"name": "loop1", "maj:min": "7:1", "rm": "0", "size": "55.8M", "ro": "1", "type": "loop", "mountpoint": "/snap/kata-containers/288"},
      {"name": "sdd", "maj:min": "8:48", "rm": "0", "size": "1.8T", "ro": "0", "type": "disk", "mountpoint": null,
         "children": [
            {"name": "sdd1", "maj:min": "8:49", "rm": "0", "size": "1.8T", "ro": "0", "type": "part", "mountpoint": null}
         ]
      },
      {"name": "sdb", "maj:min": "8:16", "rm": "0", "size": "119.2G", "ro": "0", "type": "disk", "mountpoint": null,
         "children": [
            {"name": "sdb2", "maj:min": "8:18", "rm": "0", "size": "915M", "ro": "0", "type": "part", "mountpoint": null},
            {"name": "sdb1", "maj:min": "8:17", "rm": "0", "size": "118.4G", "ro": "0", "type": "part", "mountpoint": null}
         ]
      },
      {"name": "loop4", "maj:min": "7:4", "rm": "0", "size": "69.8M", "ro": "1", "type": "loop", "mountpoint": "/snap/kata-containers/352"},
      {"name": "sr0", "maj:min": "11:0", "rm": "1", "size": "1024M", "ro": "0", "type": "rom", "mountpoint": null},
      {"name": "loop2", "maj:min": "7:2", "rm": "0", "size": "89.4M", "ro": "1", "type": "loop", "mountpoint": "/snap/core/6818"},
      {"name": "loop0", "maj:min": "7:0", "rm": "0", "size": "88.4M", "ro": "1", "type": "loop", "mountpoint": "/snap/core/6964"},
      {"name": "sde", "maj:min": "8:64", "rm": "0", "size": "1.8T", "ro": "0", "type": "disk", "mountpoint": null,
         "children": [
            {"name": "sde2", "maj:min": "8:66", "rm": "0", "size": "1.8T", "ro": "0", "type": "part", "mountpoint": null},
            {"name": "sde1", "maj:min": "8:65", "rm": "0", "size": "128M", "ro": "0", "type": "part", "mountpoint": null}
         ]
      },
      {"name": "sdc", "maj:min": "8:32", "rm": "0", "size": "477G", "ro": "0", "type": "disk", "mountpoint": null,
         "children": [
            {"name": "sdc2", "maj:min": "8:34", "rm": "0", "size": "372G", "ro": "0", "type": "part", "mountpoint": "/home"},
            {"name": "sdc5", "maj:min": "8:37", "rm": "0", "size": "9.5G", "ro": "0", "type": "part", "mountpoint": "[SWAP]"},
            {"name": "sdc3", "maj:min": "8:35", "rm": "0", "size": "1K", "ro": "0", "type": "part", "mountpoint": null},
            {"name": "sdc1", "maj:min": "8:33", "rm": "0", "size": "95.4G", "ro": "0", "type": "part", "mountpoint": "/"}
         ]
      },
      {"name": "loop3", "maj:min": "7:3", "rm": "0", "size": "89.3M", "ro": "1", "type": "loop", "mountpoint": "/snap/core/6673"}
   ]
}

lsblk -l, --list , 打印一个表格格式的输出

➜  ~ lsblk -l
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1   7:1    0  55.8M  1 loop /snap/kata-containers/288
sdd     8:48   0   1.8T  0 disk 
sdd1    8:49   0   1.8T  0 part 
sdb     8:16   0 119.2G  0 disk 
sdb2    8:18   0   915M  0 part 
sdb1    8:17   0 118.4G  0 part 
loop4   7:4    0  69.8M  1 loop /snap/kata-containers/352
sr0    11:0    1  1024M  0 rom  
loop2   7:2    0  89.4M  1 loop /snap/core/6818
loop0   7:0    0  88.4M  1 loop /snap/core/6964
sde     8:64   0   1.8T  0 disk 
sde2    8:66   0   1.8T  0 part 
sde1    8:65   0   128M  0 part 
sdc     8:32   0   477G  0 disk 
sdc2    8:34   0   372G  0 part /home
sdc5    8:37   0   9.5G  0 part [SWAP]
sdc3    8:35   0     1K  0 part 
sdc1    8:33   0  95.4G  0 part /
loop3   7:3    0  89.3M  1 loop /snap/core/6673

lsblk -m, --perms , 输出设备的权限,属主属组信息

同lsblk -o NAME,SIZE,OWNER,GROUP,MODE

➜  ~ lsblk -m
NAME     SIZE OWNER GROUP MODE
loop1   55.8M root  disk  brw-rw----
sdd      1.8T root  disk  brw-rw----
└─sdd1   1.8T root  disk  brw-rw----
sdb    119.2G root  disk  brw-rw----
├─sdb2   915M root  disk  brw-rw----
└─sdb1 118.4G root  disk  brw-rw----
loop4   69.8M root  disk  brw-rw----
sr0     1024M root  cdrom brw-rw----
loop2   89.4M root  disk  brw-rw----
loop0   88.4M root  disk  brw-rw----
sde      1.8T root  disk  brw-rw----
├─sde2   1.8T root  disk  brw-rw----
└─sde1   128M root  disk  brw-rw----
sdc      477G root  disk  brw-rw----
├─sdc2   372G root  disk  brw-rw----
├─sdc5   9.5G root  disk  brw-rw----
├─sdc3     1K root  disk  brw-rw----
└─sdc1  95.4G root  disk  brw-rw----
loop3   89.3M root  disk  brw-rw----

lsblk -n, --noheadings, 不打印标题

➜  ~ lsblk -n
loop1    7:1    0  55.8M  1 loop /snap/kata-containers/288
sdd      8:48   0   1.8T  0 disk 
└─sdd1   8:49   0   1.8T  0 part 
sdb      8:16   0 119.2G  0 disk 
├─sdb2   8:18   0   915M  0 part 
└─sdb1   8:17   0 118.4G  0 part 
loop4    7:4    0  69.8M  1 loop /snap/kata-containers/352
sr0     11:0    1  1024M  0 rom  
loop2    7:2    0  89.4M  1 loop /snap/core/6818
loop0    7:0    0  88.4M  1 loop /snap/core/6964
sde      8:64   0   1.8T  0 disk 
├─sde2   8:66   0   1.8T  0 part 
└─sde1   8:65   0   128M  0 part 
sdc      8:32   0   477G  0 disk 
├─sdc2   8:34   0   372G  0 part /home
├─sdc5   8:37   0   9.5G  0 part [SWAP]
├─sdc3   8:35   0     1K  0 part 
└─sdc1   8:33   0  95.4G  0 part /
loop3    7:3    0  89.3M  1 loop /snap/core/6673

lsblk -o , --output list, 打印指定字段细腻系,

或者lsblk -o +UUID, 表示在默认输出的后边加一列字段名为UUID的信息

➜  ~ lsblk -o +UUID
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT                UUID
loop1    7:1    0  55.8M  1 loop /snap/kata-containers/288 
sdd      8:48   0   1.8T  0 disk                           
└─sdd1   8:49   0   1.8T  0 part                           CA9015A6901599D1
sdb      8:16   0 119.2G  0 disk                           
├─sdb2   8:18   0   915M  0 part                           30EAC3FEEAC3BE7A
└─sdb1   8:17   0 118.4G  0 part                           0600EC5800EC4FEB
loop4    7:4    0  69.8M  1 loop /snap/kata-containers/352 
sr0     11:0    1  1024M  0 rom                            
loop2    7:2    0  89.4M  1 loop /snap/core/6818           
loop0    7:0    0  88.4M  1 loop /snap/core/6964           
sde      8:64   0   1.8T  0 disk                           
├─sde2   8:66   0   1.8T  0 part                           B6D47A52D47A1539
└─sde1   8:65   0   128M  0 part                           
sdc      8:32   0   477G  0 disk                           
├─sdc2   8:34   0   372G  0 part /home                     53842090-4ad6-4472-ad35-53b4d7b33bf8
├─sdc5   8:37   0   9.5G  0 part [SWAP]                    382e4b22-503e-4911-bf2f-1167af3f3cda
├─sdc3   8:35   0     1K  0 part                           
└─sdc1   8:33   0  95.4G  0 part /                         6b5618d0-a2b0-41f3-a3a5-9eb5a524b0a8
loop3    7:3    0  89.3M  1 loop /snap/core/6673   

lsblk -O, --output-all,输出所有列的信息

➜  ~ lsblk -O
NAME   KNAME MAJ:MIN FSTYPE   MOUNTPOINT LABEL    UUID                                 PARTTYPE                             PARTLABEL PARTUUID                             PARTFLAGS  RA RO RM HOTPLUG MODEL     SERIAL      SIZE STATE OWNER GROUP MODE       ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE TYPE DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO WSAME WWN                RAND PKNAME HCTL       TRAN   SUBSYSTEMS  REV VENDOR
loop1  loop1   7:1   squashfs /snap/kata                                                                                                                                             128  1  0       0                      55.8M       root  disk  brw-rw----         0    512      0     512     512    1 none      128 loop        0        4K       4G         0    0B                       0                          block           
sdd    sdd     8:48                                                                                                                                                                  128  0  0       0 ST2000DM0 WFL10Z4B    1.8T runni root  disk  brw-rw----         0   4096      0    4096     512    1 cfq       128 disk        0        4K       2G         0    0B 0x5000c500be0e12fc    1        2:0:0:0    sata   block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                      0001 ATA     
└─sdd1 sdd1    8:49  ntfs                Volume2  CA9015A6901599D1                     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 Basic data partition
                                                                                                                                      fbbcfa40-06d8-4d43-9b2e-18b04089e30d           128  0  0       0                       1.8T       root  disk  brw-rw----         0   4096      0    4096     512    1 cfq       128 part        0        4K       2G         0    0B 0x5000c500be0e12fc    1 sdd                      block:scsi:pci
                                                                                                                                                                                                                                                                                                                                                                                                                                            
sdb    sdb     8:16                                                                                                                                                                  128  0  0       0 M4-CT128M 000000001 119.2G runni root  disk  brw-rw----         0    512      0     512     512    0 cfq       128 disk        0      512B       2G         0    0B 0x500a075109112598    0        0:0:0:0    sata   block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                      000F ATA     
├─sdb2 sdb2    8:18  ntfs                         30EAC3FEEAC3BE7A                     0x27                                           4051264b-02                                    128  0  0       0                       915M       root  disk  brw-rw----         0    512      0     512     512    0 cfq       128 part        0      512B       2G         0    0B 0x500a075109112598    0 sdb                      block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                           
└─sdb1 sdb1    8:17  ntfs                OS_WIN10 0600EC5800EC4FEB                     0x7                                            4051264b-01                          0x80      128  0  0       0                     118.4G       root  disk  brw-rw----         0    512      0     512     512    0 cfq       128 part        0      512B       2G         0    0B 0x500a075109112598    0 sdb                      block:scsi:pci
                                                                                                                                                                                                                                                                                                                                                                                                                                            
loop4  loop4   7:4   squashfs /snap/kata                                                                                                                                             128  1  0       0                      69.8M       root  disk  brw-rw----         0    512      0     512     512    1 none      128 loop        0        4K       4G         0    0B                       0                          block           
sr0    sr0    11:0                                                                                                                                                                   128  0  1       1 DRW-24D3S KSTD3N812  1024M runni root  cdrom brw-rw----         0    512      0     512     512    1 cfq       128 rom         0        0B       0B         0    0B 0x5001480000000000    1        5:0:0:0    sata   block:scsi:pci
                                                                                                                                                                                                                                                                                                                                                                                                                                       1.01 ASUS    
loop2  loop2   7:2   squashfs /snap/core                                                                                                                                             128  1  0       0                      89.4M       root  disk  brw-rw----         0    512      0     512     512    1 none      128 loop        0        4K       4G         0    0B                       0                          block           
loop0  loop0   7:0   squashfs /snap/core                                                                                                                                             128  1  0       0                      88.4M       root  disk  brw-rw----         0    512      0     512     512    1 none      128 loop        0        4K       4G         0    0B                       0                          block           
sde    sde     8:64                                                                                                                                                                  128  0  0       0 WDC WD20E WD-WCC4ML   1.8T runni root  disk  brw-rw----         0   4096      0    4096     512    1 cfq       128 disk        0        0B       0B         0    0B 0x50014ee2b52d7844    1        4:0:0:0    sata   block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                      0A80 ATA     
├─sde2 sde2    8:66  ntfs                专用存储 B6D47A52D47A1539                     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 Basic data partition
│                                                                                                                                     42732d06-bb6d-4e0c-80fc-5e2746300ea7           128  0  0       0                       1.8T       root  disk  brw-rw----         0   4096      0    4096     512    1 cfq       128 part        0        0B       0B         0    0B 0x50014ee2b52d7844    1 sde                      block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                           
└─sde1 sde1    8:65                                                                    e3c9e316-0b5c-4db8-817d-f92df00215ae Microsoft reserved partition
                                                                                                                                      731fb900-205e-4c54-b9c7-b78946f2ac12           128  0  0       0                       128M       root  disk  brw-rw----      3072   4096      0    4096     512    1 cfq       128 part        0        0B       0B         0    0B 0x50014ee2b52d7844    1 sde                      block:scsi:pci
                                                                                                                                                                                                                                                                                                                                                                                                                                            
sdc    sdc     8:32                                                                                                                                                                  128  0  0       0 INTEL SSD BTLA82430   477G runni root  disk  brw-rw----         0    512      0     512     512    0 cfq       128 disk        0      512B       2G         0    0B 0x55cd2e414f7acc09    0        1:0:0:0    sata   block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                      002C ATA     
├─sdc2 sdc2    8:34  ext4     /home               53842090-4ad6-4472-ad35-53b4d7b33bf8 0x83                                           2ab59d7a-02                                    128  0  0       0                       372G       root  disk  brw-rw----         0    512      0     512     512    0 cfq       128 part        0      512B       2G         0    0B 0x55cd2e414f7acc09    0 sdc                      block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                           
├─sdc5 sdc5    8:37  swap     [SWAP]              382e4b22-503e-4911-bf2f-1167af3f3cda 0x82                                           2ab59d7a-05                                    128  0  0       0                       9.5G       root  disk  brw-rw----         0    512      0     512     512    0 cfq       128 part        0      512B       2G         0    0B 0x55cd2e414f7acc09    0 sdc                      block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                           
├─sdc3 sdc3    8:35                                                                    0x5                                            2ab59d7a-03                                    128  0  0       0                         1K       root  disk  brw-rw----         0    512      0     512     512    0 cfq       128 part        0      512B       2G         0    0B 0x55cd2e414f7acc09    0 sdc                      block:scsi:pci
│                                                                                                                                                                                                                                                                                                                                                                                                                                           
└─sdc1 sdc1    8:33  ext4     /                   6b5618d0-a2b0-41f3-a3a5-9eb5a524b0a8 0x83                                           2ab59d7a-01                          0x80      128  0  0       0                      95.4G       root  disk  brw-rw----         0    512      0     512     512    0 cfq       128 part        0      512B       2G         0    0B 0x55cd2e414f7acc09    0 sdc                      block:scsi:pci
                                                                                                                                                                                                                                                                                                                                                                                                                                            
loop3  loop3   7:3   squashfs /snap/core                                                                                                                                             128  1  0       0                      89.3M       root  disk  brw-rw----         0    512      0     512     512    1 none      128 loop        0        4K       4G         0    0B                       0                          block   

lsblk -P, --pairs 打印成html需要的unsafe格式字符

➜  ~ lsblk -P 
NAME="loop1" MAJ:MIN="7:1" RM="0" SIZE="55.8M" RO="1" TYPE="loop" MOUNTPOINT="/snap/kata-containers/288"
NAME="sdd" MAJ:MIN="8:48" RM="0" SIZE="1.8T" RO="0" TYPE="disk" MOUNTPOINT=""
NAME="sdd1" MAJ:MIN="8:49" RM="0" SIZE="1.8T" RO="0" TYPE="part" MOUNTPOINT=""
NAME="sdb" MAJ:MIN="8:16" RM="0" SIZE="119.2G" RO="0" TYPE="disk" MOUNTPOINT=""
NAME="sdb2" MAJ:MIN="8:18" RM="0" SIZE="915M" RO="0" TYPE="part" MOUNTPOINT=""
NAME="sdb1" MAJ:MIN="8:17" RM="0" SIZE="118.4G" RO="0" TYPE="part" MOUNTPOINT=""
NAME="loop4" MAJ:MIN="7:4" RM="0" SIZE="69.8M" RO="1" TYPE="loop" MOUNTPOINT="/snap/kata-containers/352"
NAME="sr0" MAJ:MIN="11:0" RM="1" SIZE="1024M" RO="0" TYPE="rom" MOUNTPOINT=""
NAME="loop2" MAJ:MIN="7:2" RM="0" SIZE="89.4M" RO="1" TYPE="loop" MOUNTPOINT="/snap/core/6818"
NAME="loop0" MAJ:MIN="7:0" RM="0" SIZE="88.4M" RO="1" TYPE="loop" MOUNTPOINT="/snap/core/6964"
NAME="sde" MAJ:MIN="8:64" RM="0" SIZE="1.8T" RO="0" TYPE="disk" MOUNTPOINT=""
NAME="sde2" MAJ:MIN="8:66" RM="0" SIZE="1.8T" RO="0" TYPE="part" MOUNTPOINT=""
NAME="sde1" MAJ:MIN="8:65" RM="0" SIZE="128M" RO="0" TYPE="part" MOUNTPOINT=""
NAME="sdc" MAJ:MIN="8:32" RM="0" SIZE="477G" RO="0" TYPE="disk" MOUNTPOINT=""
NAME="sdc2" MAJ:MIN="8:34" RM="0" SIZE="372G" RO="0" TYPE="part" MOUNTPOINT="/home"
NAME="sdc5" MAJ:MIN="8:37" RM="0" SIZE="9.5G" RO="0" TYPE="part" MOUNTPOINT="[SWAP]"
NAME="sdc3" MAJ:MIN="8:35" RM="0" SIZE="1K" RO="0" TYPE="part" MOUNTPOINT=""
NAME="sdc1" MAJ:MIN="8:33" RM="0" SIZE="95.4G" RO="0" TYPE="part" MOUNTPOINT="/"
NAME="loop3" MAJ:MIN="7:3" RM="0" SIZE="89.3M" RO="1" TYPE="loop" MOUNTPOINT="/snap/core/6673"

lsblk -p, --paths, 打印设备的全部路径

➜  ~ lsblk -p
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
/dev/loop1    7:1    0  55.8M  1 loop /snap/kata-containers/288
/dev/sdd      8:48   0   1.8T  0 disk 
└─/dev/sdd1   8:49   0   1.8T  0 part 
/dev/sdb      8:16   0 119.2G  0 disk 
├─/dev/sdb2   8:18   0   915M  0 part 
└─/dev/sdb1   8:17   0 118.4G  0 part 
/dev/loop4    7:4    0  69.8M  1 loop /snap/kata-containers/352
/dev/sr0     11:0    1  1024M  0 rom  
/dev/loop2    7:2    0  89.4M  1 loop /snap/core/6818
/dev/loop0    7:0    0  88.4M  1 loop /snap/core/6964
/dev/sde      8:64   0   1.8T  0 disk 
├─/dev/sde2   8:66   0   1.8T  0 part 
└─/dev/sde1   8:65   0   128M  0 part 
/dev/sdc      8:32   0   477G  0 disk 
├─/dev/sdc2   8:34   0   372G  0 part /home
├─/dev/sdc5   8:37   0   9.5G  0 part [SWAP]
├─/dev/sdc3   8:35   0     1K  0 part 
└─/dev/sdc1   8:33   0  95.4G  0 part /
/dev/loop3    7:3    0  89.3M  1 loop /snap/core/6673

lsblk -r, --raw , 裸格式输出

➜  ~ lsblk -r
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop1 7:1 0 55.8M 1 loop /snap/kata-containers/288
sdd 8:48 0 1.8T 0 disk 
sdd1 8:49 0 1.8T 0 part 
sdb 8:16 0 119.2G 0 disk 
sdb2 8:18 0 915M 0 part 
sdb1 8:17 0 118.4G 0 part 
loop4 7:4 0 69.8M 1 loop /snap/kata-containers/352
sr0 11:0 1 1024M 0 rom 
loop2 7:2 0 89.4M 1 loop /snap/core/6818
loop0 7:0 0 88.4M 1 loop /snap/core/6964
sde 8:64 0 1.8T 0 disk 
sde2 8:66 0 1.8T 0 part 
sde1 8:65 0 128M 0 part 
sdc 8:32 0 477G 0 disk 
sdc2 8:34 0 372G 0 part /home
sdc5 8:37 0 9.5G 0 part [SWAP]
sdc3 8:35 0 1K 0 part 
sdc1 8:33 0 95.4G 0 part /
loop3 7:3 0 89.3M 1 loop /snap/core/6673

lsblk -S, --scsi 输出scsi设备(物理设备)的信息

➜  ~ lsblk -S
NAME HCTL       TYPE VENDOR   MODEL             REV TRAN
sdd  2:0:0:0    disk ATA      ST2000DM008-2FR1 0001 sata
sdb  0:0:0:0    disk ATA      M4-CT128M4SSD1   000F sata
sr0  5:0:0:0    rom  ASUS     DRW-24D3ST       1.01 sata
sde  4:0:0:0    disk ATA      WDC WD20EZRX-00D 0A80 sata
sdc  1:0:0:0    disk ATA      INTEL SSDSC2KW51 002C sata

lsblk -s, --inverse , 打印分区的依赖设备反序列输出,分区指向设备.

➜  ~ lsblk -s
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1   7:1    0  55.8M  1 loop /snap/kata-containers/288
sdd1    8:49   0   1.8T  0 part 
└─sdd   8:48   0   1.8T  0 disk 
sdb2    8:18   0   915M  0 part 
└─sdb   8:16   0 119.2G  0 disk 
sdb1    8:17   0 118.4G  0 part 
└─sdb   8:16   0 119.2G  0 disk 
loop4   7:4    0  69.8M  1 loop /snap/kata-containers/352
sr0    11:0    1  1024M  0 rom  
loop2   7:2    0  89.4M  1 loop /snap/core/6818
loop0   7:0    0  88.4M  1 loop /snap/core/6964
sde2    8:66   0   1.8T  0 part 
└─sde   8:64   0   1.8T  0 disk 
sde1    8:65   0   128M  0 part 
└─sde   8:64   0   1.8T  0 disk 
sdc2    8:34   0   372G  0 part /home
└─sdc   8:32   0   477G  0 disk 
sdc5    8:37   0   9.5G  0 part [SWAP]
└─sdc   8:32   0   477G  0 disk 
sdc3    8:35   0     1K  0 part 
└─sdc   8:32   0   477G  0 disk 
sdc1    8:33   0  95.4G  0 part /
└─sdc   8:32   0   477G  0 disk 
loop3   7:3    0  89.3M  1 loop /snap/core/6673

lsblk -t, --topology 打印块设备的拓扑结构.

同 lsblk -o NAME,ALIGN-MENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,RA,WSAME.

➜  ~ lsblk -t
NAME   ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE  RA WSAME
loop1          0    512      0     512     512    1 none      128 128    0B
sdd            0   4096      0    4096     512    1 cfq       128 128    0B
└─sdd1         0   4096      0    4096     512    1 cfq       128 128    0B
sdb            0    512      0     512     512    0 cfq       128 128    0B
├─sdb2         0    512      0     512     512    0 cfq       128 128    0B
└─sdb1         0    512      0     512     512    0 cfq       128 128    0B
loop4          0    512      0     512     512    1 none      128 128    0B
sr0            0    512      0     512     512    1 cfq       128 128    0B
loop2          0    512      0     512     512    1 none      128 128    0B
loop0          0    512      0     512     512    1 none      128 128    0B
sde            0   4096      0    4096     512    1 cfq       128 128    0B
├─sde2         0   4096      0    4096     512    1 cfq       128 128    0B
└─sde1      3072   4096      0    4096     512    1 cfq       128 128    0B
sdc            0    512      0     512     512    0 cfq       128 128    0B
├─sdc2         0    512      0     512     512    0 cfq       128 128    0B
├─sdc5         0    512      0     512     512    0 cfq       128 128    0B
├─sdc3         0    512      0     512     512    0 cfq       128 128    0B
└─sdc1         0    512      0     512     512    0 cfq       128 128    0B
loop3          0    512      0     512     512    1 none      128 128    0B

lsblk -V, --version 查看版本号

➜  ~ lsblk -V
lsblk,来自 util-linux 2.27.1

lsblk -x, --sort colum, 指定字段对输出信息排序

➜  ~ lsblk -S -x NAME
NAME HCTL       TYPE VENDOR   MODEL             REV TRAN
sdb  0:0:0:0    disk ATA      M4-CT128M4SSD1   000F sata
sdc  1:0:0:0    disk ATA      INTEL SSDSC2KW51 002C sata
sdd  2:0:0:0    disk ATA      ST2000DM008-2FR1 0001 sata
sde  4:0:0:0    disk ATA      WDC WD20EZRX-00D 0A80 sata
sr0  5:0:0:0    rom  ASUS     DRW-24D3ST       1.01 sata

应用场景:

  1. 确认从磁盘上会否ssd

    lsblk -d -o +rota

    ➜  ~ lsblk -d -o +rota
    NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT                ROTA
    loop1   7:1    0  55.8M  1 loop /snap/kata-containers/288    1
    sdd     8:48   0   1.8T  0 disk                              1
    sdb     8:16   0 119.2G  0 disk                              0
    loop4   7:4    0  69.8M  1 loop /snap/kata-containers/352    1
    sr0    11:0    1  1024M  0 rom                               1
    loop2   7:2    0  89.4M  1 loop /snap/core/6818              1
    loop0   7:0    0  88.4M  1 loop /snap/core/6964              1
    sde     8:64   0   1.8T  0 disk                              1
    sdc     8:32   0   477G  0 disk                              0
    loop3   7:3    0  89.3M  1 loop /snap/core/6673              1

与[转帖]lsblk命令详解 相似的内容:

[转帖]lsblk命令详解

https://www.cnblogs.com/ishmaelwanglin/p/11043918.html lsblk命令用来查看block设备的信息. 主要应用场景: 获取wwnid,获取块设备列表,获取块设备类型(ssd,hdd),获取块设备的size等信息. 数据来源: /sys/dev/b

[转帖]Linux下lshw,lsscsi,lscpu,lsusb,lsblk硬件查看命令

注意:如有提示命令找不到command not found,请自行安装所需命令。 1、lshw查看所有硬件摘要信息 下面命令可以查看所有硬件摘要信息,并输出成一个html文件,把此html文件导出到电脑上,直接打开,可以清楚的看到硬件信息: [root@localhost /]# lshw -htm

[转帖]

Linux ubuntu20.04 网络配置(图文教程) 因为我是刚装好的最小系统,所以很多东西都没有,在开始配置之前需要做下准备 环境准备 系统:ubuntu20.04网卡:双网卡 网卡一:供连接互联网使用网卡二:供连接内网使用(看情况,如果一张网卡足够,没必要做第二张网卡) 工具: net-to

[转帖]

https://cloud.tencent.com/developer/article/2168105?areaSource=104001.13&traceId=zcVNsKTUApF9rNJSkcCbB 前言 Redis作为高性能的内存数据库,在大数据量的情况下也会遇到性能瓶颈,日常开发中只有时刻

[转帖]ISV 、OSV、 SIG 概念

ISV 、OSV、 SIG 概念 2022-10-14 12:29530原创大杂烩 本文链接:https://www.cndba.cn/dave/article/108699 1. ISV: Independent Software Vendors “独立软件开发商”,特指专门从事软件的开发、生产、

[转帖]Redis 7 参数 修改 说明

2022-06-16 14:491800原创Redis 本文链接:https://www.cndba.cn/dave/article/108066 在之前的博客我们介绍了Redis 7 的安装和配置,如下: Linux 7.8 平台 Redis 7 安装并配置开机自启动 操作手册https://ww

[转帖]HTTPS中间人攻击原理

https://www.zhihu.com/people/bei-ji-85/posts 背景 前一段时间,公司北京地区上线了一个HTTPS防火墙,用来监听HTTPS流量。防火墙上线之前,邮件通知给管理层,我从我老大那里听说这个事情的时候,说这个有风险,然后意外地发现,很多人原来都不知道HTTPS防

[转帖]关于字节序(大小端)的一点想法

https://www.zhihu.com/people/bei-ji-85/posts 今天在一个技术群里有人问起来了,当时有一些讨论(不完全都是我个人的观点),整理一下: 为什么网络字节序(多数情况下)是大端? 早年设备的缓存很小,先接收高字节能快速的判断报文信息:包长度(需要准备多大缓存)、地

[转帖]awk提取某一行某一列的数据

https://www.jianshu.com/p/dbcb7fe2da56 1、提取文件中第1列数据 awk '{print $1}' filename > out.txt 2、提取前2列的文件 awk `{print $1,$2}' filename > out.txt 3、打印完第一列,然后打

[转帖]awk 中 FS的用法

https://www.cnblogs.com/rohens-hbg/p/5510890.html 在openwrt文件 ar71xx.sh中 查询设备类型时,有这么一句, machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /