lsblk的使用
2022-04-25 21:24 abce 阅读(730) 评论(0) 编辑 收藏 举报lsblk使用说明
用途:列出块设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 231.9G 0 part
└─luks-5794a0b4-7082-4769-b86b-bd27a544361a 253:0 0 231.9G 0 crypt
├─fingolfin_vg-root_lv 253:1 0 35G 0 lvm /
├─fingolfin_vg-swap_lv 253:2 0 6G 0 lvm [SWAP]
├─fingolfin_vg-home_lv 253:3 0 15G 0 lvm /home
└─fingolfin_vg-data_lv 253:4 0 170G 0 lvm /mnt/data
sr0 11:0 1 1024M 0 rom
zram0 252:0 0 2.8G 0 disk [SWAP]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 150G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 149G 0 part
├─vg_os-root 253:0 0 100G 0 lvm /
└─vg_os-swap 253:1 0 8G 0 lvm [SWAP]
sdb 8:16 0 150G 0 disk
sr0 11:0 1 1024M 0 rom
树形结构有助于显示识别设备和分区信息,以及他们在设备上是如何组织的。在我们这个例子里,设备sda上有两个分区sda1、sda2。
这里是标准分区,通过type列可以看到,这里是part类型。当前被挂载在/boot下。
sda2也是一个标准分区,但是通过上面可以看到,sda2有子设备。第一个是LUKS容器,标识符是luks-5794a0b4-7082-4769-b86b-bd27a544361a(这是设备映射名)。系统被安装在luks的逻辑卷上,这里luks容器自身被标识为物理卷,上面包含了一些逻辑卷,逻辑卷被挂载在系统的不同的部分。
第一列:NAME
从输出的第一列,可以看到设备的名字,默认是只显示设备名,不显示完全路径。要想显示完全路径,需要加上参数-p
比如:
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 150G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 149G 0 part
├─vg_os-root 253:0 0 291G 0 lvm /
└─vg_os-swap 253:1 0 8G 0 lvm [SWAP]
sdb 8:16 0 150G 0 disk
└─vg_os-root 253:0 0 291G 0 lvm /
sr0 11:0 1 1024M 0 rom
# lsblk -p
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
/dev/sda 8:0 0 150G 0 disk
├─/dev/sda1 8:1 0 1G 0 part /boot
└─/dev/sda2 8:2 0 149G 0 part
├─/dev/mapper/vg_os-root 253:0 0 291G 0 lvm /
└─/dev/mapper/vg_os-swap 253:1 0 8G 0 lvm [SWAP]
/dev/sdb 8:16 0 150G 0 disk
└─/dev/mapper/vg_os-root 253:0 0 291G 0 lvm /
/dev/sr0 11:0 1 1024M 0 rom
第二列:MAJ:MIN是内核内部用来识别设备的编号,第一个数字表示类型,比如8表示scsi设备。
第三列:RM,表示设备是否可移动,1表示可移动。在第一个例子中,只有一个是可以移动的:sr0,是一个可选设备。
第四列:SIZE,即对应设备的大小。
第五列:RO,用于执行设备是否是只读的。1表示是只读的。
第六列:TYPE,表示设备或者分区的类型。例如,从第一个例子可以看到,crypt被用来标识luks容器;lvm被用来标识逻辑设备;disk被用来标识裸设备,比如sda。
第七列:表示挂载点
收集指定设备的信息
需要指定全路径
# lsblk /dev/sda1
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda1 8:1 0 1G 0 part /boot
lsblk显示指定的列
-o 表示output
# lsblk -o NAME,FSTYPE
NAME FSTYPE
sda
├─sda1 ext2
└─sda2 crypto_LUKS
└─luks-5794a0b4-7082-4769-b86b-bd27a544361a LVM2_member
├─fingolfin_vg-root_lv ext4
├─fingolfin_vg-swap_lv swap
├─fingolfin_vg-home_lv ext4
└─fingolfin_vg-data_lv ext4
sr0
zram0
lsblk帮助查看
# lsblk -h
Usage:
lsblk [options] [<device> ...]
Options:
-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)
-I, --include <list> show only devices with specified major numbers
-f, --fs output info about filesystems
-h, --help usage information (this)
-i, --ascii use ascii characters only
-m, --perms output info about permissions
-l, --list use list format output
-n, --noheadings don't print headings
-o, --output <list> output columns
-p, --paths print complate device path
-P, --pairs use key="value" output format
-r, --raw use raw output format
-s, --inverse inverse dependencies
-t, --topology output info about topology
-S, --scsi output info about SCSI devices
-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
PARTLABEL partition LABEL
PARTUUID partition UUID
RA read-ahead of the device
RO read-only device
RM removable device
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
REV device revision
VENDOR device vendor
For more details see lsblk(8).
lsblk结果定制化输出
只显示父节点
lsblk -d,其中-d表示--nodeps
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
sr0 11:0 1 1024M 0 rom
zram0 252:0 0 2.8G 0 disk [SWAP]
以json格式显示
lsblk -J,其中-J表示--json
$ lsblk -J
{
"blockdevices": [
{"name":"sda", "maj:min":"8:0", "rm":false, "size":"232.9G", "ro":false, "type":"disk", "mountpoint":null,
"children": [
{"name":"sda1", "maj:min":"8:1", "rm":false, "size":"1G", "ro":false, "type":"part", "mountpoint":"/boot"},
{"name":"sda2", "maj:min":"8:2", "rm":false, "size":"231.9G", "ro":false, "type":"part", "mountpoint":null,
"children": [
{"name":"luks-5794a0b4-7082-4769-b86b-bd27a544361a", "maj:min":"253:0", "rm":false, "size":"231.9G", "ro":false, "type":"crypt", "mountpoint":null,
"children": [
{"name":"fingolfin_vg-root_lv", "maj:min":"253:1", "rm":false, "size":"35G", "ro":false, "type":"lvm", "mountpoint":"/"},
{"name":"fingolfin_vg-swap_lv", "maj:min":"253:2", "rm":false, "size":"6G", "ro":false, "type":"lvm", "mountpoint":"[SWAP]"},
{"name":"fingolfin_vg-home_lv", "maj:min":"253:3", "rm":false, "size":"15G", "ro":false, "type":"lvm", "mountpoint":"/home"},
{"name":"fingolfin_vg-data_lv", "maj:min":"253:4", "rm":false, "size":"170G", "ro":false, "type":"lvm", "mountpoint":"/mnt/data"}
]
}
]
}
]
},
{"name":"sr0", "maj:min":"11:0", "rm":true, "size":"1024M", "ro":false, "type":"rom", "mountpoint":null},
{"name":"zram0", "maj:min":"252:0", "rm":false, "size":"2.8G", "ro":false, "type":"disk", "mountpoint":"[SWAP]"}
]
}
脚本中使用lsblk
-n或者--noheadings,去掉标题
$ fsys="$(lsblk --noheadings -o FSTYPE /dev/sda1)"