Loading

Linux查询块设备信息之 blkid

blkid 语法

查看块设备的文件系统类型、LABEL、UUID等信息,有软件包util-linux提供。

[root@localhost ~]# blkid --help
用法:
blkid --label <label> | --uuid <uuid>

blkid [--cache-file <file>] [-ghlLv] [--output <format>] [--match-tag <tag>] 
[--match-token <token>] [<dev> ...]

blkid -p [--match-tag <tag>] [--offset <offset>] [--size <size>] 
[--output <format>] <dev> ...

blkid -i [--match-tag <tag>] [--output <format>] <dev> ...

选项:

-c, --cache-file <file>    read from <file> instead of reading from the default
cache file (-c /dev/null means no cache)。指定缓存文件,如果指定为-c /dev/null表示不缓存
-d, --no-encoding          don't encode non-printing characters。不编码非打印字符,默认显示为^
-g, --garbage-collect      garbage collect the blkid cache。回收blkid缓存
-o, --output <format>      output format; can be one of:
value, device, export or full; (default: full)。指定输出格式,可选项为value,device,export,full(默认)
-k, --list-filesystems     list all known filesystems/RAIDs and exit。显示所有已知的文件系统格式和RAID分区格式
-s, --match-tag <tag>      show specified tag(s) (default show all tags)
-t, --match-token <token>  find device with a specific token (NAME=value pair)。指定设备属性,token为(NAME=value),NAME可选项为TYPE, LABEL, and UUID
-l, --list-one             look up only first device with token specified by -t。配合-t选项只显示第一个设备
-L, --label <label>        convert LABEL to device name。转换LABEL为设备名称
-U, --uuid <uuid>          convert UUID to device name。转换UUID为设备名称
<dev>                      specify device(s) to probe (default: all devices)

Low-level probing options:
-p, --probe                low-level superblocks probing (bypass cache)
-i, --info                 gather information about I/O limits
-S, --size <size>          overwrite device size
-O, --offset <offset>      probe at the given offset
-u, --usages <list>        filter by "usage" (e.g. -u filesystem,raid)
-n, --match-types <list>   filter by filesystem type (e.g. -n vfat,ext3)
-D, --no-part-details      don't print info from partition table

-h, --help                 display this help
-V, --version              display version

更多信息请参阅 blkid(8)。

实例

1、默认显示所有设备

通常使用blkid命令,不加任何参数就可以获取我们需要的UUID等数据。UUID是我们经常要查询的值,在格式化完磁盘,配置/etc/fstab时建议使用UUID,这样可以避免驱动器编号变化,文件系统无法挂载而导致无法开机的问题。

[root@localhost ~]# blkid
/dev/mapper/rhel-root: UUID="ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc" BLOCK_SIZE="512" TYPE="xfs"
/dev/nvme0n1p2: UUID="qFOF2o-ZCQm-Sg5C-eAOh-Dt3f-bS2r-TybHeS" TYPE="LVM2_member" PARTUUID="753318d0-02"
/dev/nvme0n1p1: UUID="1d8d4eb6-5674-4e34-988f-2fa036850b45" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="753318d0-01"
/dev/sr0: BLOCK_SIZE="2048" UUID="2022-04-20-16-41-14-00" LABEL="RHEL-8-6-0-BaseOS-x86_64" TYPE="iso9660" PTUUID="3f7fc886" PTTYPE="dos"
/dev/mapper/rhel-swap: UUID="8f707b9a-f43c-4793-b3b6-95d1eb4c473f" TYPE="swap"
/dev/nvme0n1: PTUUID="753318d0" PTTYPE="dos"

2、显示指定设备信息

[root@localhost ~]# blkid /dev/mapper/rhel-root 
/dev/mapper/rhel-root: UUID="ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc" BLOCK_SIZE="512" TYPE="xfs"

3、显示所有设备 UUID

[root@localhost ~]# blkid -s UUID
/dev/mapper/rhel-root: UUID="ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc"
/dev/nvme0n1p2: UUID="qFOF2o-ZCQm-Sg5C-eAOh-Dt3f-bS2r-TybHeS"
/dev/nvme0n1p1: UUID="1d8d4eb6-5674-4e34-988f-2fa036850b45"
/dev/sr0: UUID="2022-04-20-16-41-14-00"
/dev/mapper/rhel-swap: UUID="8f707b9a-f43c-4793-b3b6-95d1eb4c473f"

4、显示所有设备 LABEL

[root@localhost ~]# blkid -s LABEL
/dev/sr0: LABEL="RHEL-8-6-0-BaseOS-x86_64"
[root@localhost ~]# blkid -s LABEL /dev/nvme0n1p1

5、显示所有设备文件系统

[root@localhost ~]# blkid -s TYPE
/dev/mapper/rhel-root: TYPE="xfs"
/dev/nvme0n1p2: TYPE="LVM2_member"
/dev/nvme0n1p1: TYPE="xfs"
/dev/sr0: TYPE="iso9660"
/dev/mapper/rhel-swap: TYPE="swap"

6、显示所有设备

[root@localhost ~]# blkid -o device
/dev/mapper/rhel-root
/dev/nvme0n1p2
/dev/nvme0n1p1
/dev/sr0
/dev/mapper/rhel-swap
/dev/nvme0n1

7、以方便用户使用的格式列印设备;这种输出格式不支持低级探测

[root@localhost ~]# blkid -o list
device                               fs_type       label          mount point                              UUID
-----------------------------------------------------------------------------------------------------------------------------------------------
/dev/mapper/rhel-root                xfs                          /                                        ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc
/dev/nvme0n1p2                       LVM2_member                  (in use)                                 qFOF2o-ZCQm-Sg5C-eAOh-Dt3f-bS2r-TybHeS
/dev/nvme0n1p1                       xfs                          /boot                                    1d8d4eb6-5674-4e34-988f-2fa036850b45
/dev/sr0                             iso9660       RHEL-8-6-0-BaseOS-x86_64 /run/media/root/RHEL-8-6-0-BaseOS-x86_64 2022-04-20-16-41-14-00
/dev/mapper/rhel-swap                swap                         [SWAP]                                   8f707b9a-f43c-4793-b3b6-95d1eb4c473f
/dev/nvme0n1                                                      (in use)

8、以键值对的方式显示

[root@localhost ~]# blkid -o export
DEVNAME=/dev/mapper/rhel-root
UUID=ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc
BLOCK_SIZE=512
TYPE=xfs

DEVNAME=/dev/nvme0n1p2
UUID=qFOF2o-ZCQm-Sg5C-eAOh-Dt3f-bS2r-TybHeS
TYPE=LVM2_member
PARTUUID=753318d0-02
略......

9、-t过滤类型,如只显示xfs类型的分区

[root@localhost ~]# blkid -t TYPE=xfs
/dev/mapper/rhel-root: UUID="ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc" BLOCK_SIZE="512" TYPE="xfs"
/dev/nvme0n1p1: UUID="1d8d4eb6-5674-4e34-988f-2fa036850b45" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="753318d0-01"
[root@localhost ~]# 
[root@localhost ~]# blkid -t UUID="ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc"
/dev/mapper/rhel-root: UUID="ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc" BLOCK_SIZE="512" TYPE="xfs"

10、-U转换UUID为设备名称

[root@localhost ~]# blkid -U ccd7fed8-17ad-4a2f-8a54-8edf10d55fbc
/dev/mapper/rhel-root
posted @ 2022-11-04 17:02  五月的麦田  阅读(389)  评论(0编辑  收藏  举报