介绍:
blkid命令对查询设备上所采用文件系统类型进行查询。blkid主要用来对系统的块设备(包括交换分区)所使用的文件系统类型、LABEL、UUID等信息进行查询。
具体用法:
man blkid
NAME
blkid - locate/print block device attributes
SYNOPSIS
blkid --label label | --uuid uuid
blkid [--no-encoding --garbage-collect --list-one --cache-file file] [--output format] [--match-tag tag] [--match-token NAME=value] [device ...]
blkid --probe [--offset offset] [--output format] [--size size] [--match-tag tag] [--match-types list] [--usages list] device ...
blkid --info [--output format] [--match-tag tag] device ...
DESCRIPTION
The blkid program is the command-line interface to working with the libblkid(3) library. It can determine the type of content (e.g. filesystem or swap) that a block device
holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).
holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).
It is recommended to use lsblk(8) command to get information about block devices, or lsblk --fs to get an overview of filesystems, or findmnt(8) to search in already mounted
filesystems.
lsblk(8) provides more information, better control on output formatting, easy to use in scripts and it does not require root permissions to get actual information.
blkid reads information directly from devices and for non-root users it returns cached unverified information. blkid is mostly designed for system services and to test
libblkid functionality.
When device is specified, tokens from only this device are displayed. It is possible to specify multiple device arguments on the command line. If none is given, all devices
which appear in /proc/partitions are shown, if they are recognized.
blkid has two main forms of operation: either searching for a device with a specific NAME=value pair, or displaying NAME=value pairs for one or more specified devices.
For security reasons blkid silently ignores all devices where the probing result is ambivalent (multiple colliding filesystems are detected). The low-level probing mode (-p)
provides more information and extra return code in this case. It's recommended to use wipefs(8) to get a detailed overview and to erase obsolete stuff (magic strings) from
the device.
OPTIONS
The size and offset arguments may be followed by the multiplicative suffixes like KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is op‐
tional, e.g. "K" has the same meaning as "KiB"), or the suffixes KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB and YB.
-c, --cache-file cachefile
Read from cachefile instead of reading from the default cache file (see the CONFIGURATION FILE section for more details). If you want to start with a clean cache (i.e.
don't report devices previously scanned but not necessarily available at this time), specify /dev/null.
don't report devices previously scanned but not necessarily available at this time), specify /dev/null.
-d, --no-encoding
Don't encode non-printing characters. The non-printing characters are encoded by ^ and M- notation by default. Note that the --output udev output format uses a dif‐
ferent encoding which cannot be disabled.
-g, --garbage-collect
Perform a garbage collection pass on the blkid cache to remove devices which no longer exist.
-h, --help
Display a usage message and exit.
-i, --info
Display information about I/O Limits (aka I/O topology). The 'export' output format is automatically enabled. This option can be used together with the --probe op‐
Display information about I/O Limits (aka I/O topology). The 'export' output format is automatically enabled. This option can be used together with the --probe op‐
tion.
-k, --list-filesystems
List all known filesystems and RAIDs and exit.
-l, --list-one
Look up only one device that matches the search parameter specified with the --match-token option. If there are multiple devices that match the specified search param‐
eter, then the device with the highest priority is returned, and/or the first device found at a given priority. Device types in order of decreasing priority are: De‐
vice Mapper, EVMS, LVM, MD, and finally regular block devices. If this option is not specified, blkid will print all of the devices that match the search parameter.
-L, --label label
Look up the device that uses this filesystem label; this is equal to --list-one --output device --match-token LABEL=label. This lookup method is able to reliably use
-L, --label label
Look up the device that uses this filesystem label; this is equal to --list-one --output device --match-token LABEL=label. This lookup method is able to reliably use
/dev/disk/by-label udev symlinks (dependent on a setting in /etc/blkid.conf). Avoid using the symlinks directly; it is not reliable to use the symlinks without verifi‐
cation. The --label option works on systems with and without udev.
Unfortunately, the original blkid(8) from e2fsprogs uses the -L option as a synonym for -o list. For better portability, use -l -o device -t LABEL=label and -o list in
your scripts rather than the -L option.
-n, --match-types list
Restrict the probing functions to the specified (comma-separated) list of superblock types (names). The list items may be prefixed with "no" to specify the types which
should be ignored. For example:
blkid --probe --match-types vfat,ext3,ext4 /dev/sda1
probes for vfat, ext3 and ext4 filesystems, and
blkid --probe --match-types nominix /dev/sda1
probes for all supported formats except minix filesystems. This option is only useful together with --probe.
-o, --output format
Use the specified output format. Note that the order of variables and devices is not fixed. See also option -s. The format parameter may be:
Use the specified output format. Note that the order of variables and devices is not fixed. See also option -s. The format parameter may be:
full print all tags (the default)
value print the value of the tags
list print the devices in a user-friendly format; this output format is unsupported for low-level probing (--probe or --info).
This output format is DEPRECATED in favour of the lsblk(8) command.
device print the device name only; this output format is always enabled for the --label and --uuid options
udev print key="value" pairs for easy import into the udev environment; the keys are prefixed by ID_FS_ or ID_PART_ prefixes. The value may be modified to be safe
for udev environment; allowed is plain ASCII, hex-escaping and valid UTF-8, everything else (including whitespaces) is replaced with '_'. The keys with _ENC
postfix use hex-escaping for unsafe chars.
The udev output returns the ID_FS_AMBIVALENT tag if more superblocks are detected, and ID_PART_ENTRY_* tags are always returned for all partitions including
empty partitions.
This output format is DEPRECATED.
export print key=value pairs for easy import into the environment; this output format is automatically enabled when I/O Limits (--info option) are requested.
The non-printing characters are encoded by ^ and M- notation and all potentially unsafe characters are escaped.
-O, --offset offset
Probe at the given offset (only useful with --probe). This option can be used together with the --info option.
-p, --probe
Switch to low-level superblock probing mode (bypassing the cache).
Note that low-level probing also returns information about partition table type (PTTYPE tag) and partitions (PART_ENTRY_* tags). The tag names produced by low-level
probing are based on names used internally by libblkid and it may be different than when executed without --probe (for example PART_ENTRY_UUID= vs PARTUUID=).
-s, --match-tag tag
For each (specified) device, show only the tags that match tag. It is possible to specify multiple --match-tag options. If no tag is specified, then all tokens are
shown for all (specified) devices. In order to just refresh the cache without showing any tokens, use --match-tag none with no other options.
-S, --size size
Override the size of device/file (only useful with --probe).
-t, --match-token NAME=value
Search for block devices with tokens named NAME that have the value value, and display any devices which are found. Common values for NAME include TYPE, LABEL, and
UUID. If there are no devices specified on the command line, all block devices will be searched; otherwise only the specified devices are searched.
-u, --usages list
Restrict the probing functions to the specified (comma-separated) list of "usage" types. Supported usage types are: filesystem, raid, crypto and other. The list items
may be prefixed with "no" to specify the usage types which should be ignored. For example:
blkid --probe --usages filesystem,other /dev/sda1
probes for all filesystem and other (e.g. swap) formats, and
Manual page blkid(8) line 98 (press h for help or q to quit)
大致如下:
-c <file> 指定cache文件(default: /etc/blkid.tab, /dev/null = none)
-d don't encode non-printing characters
-h 显示帮助信息
-g garbage collect the blkid cache
-o <format> 指定输出格式
-k list all known filesystems/RAIDs and exit
-s <tag> 显示指定信息,默认显示所有信息
-t <token> find device with a specific token (NAME=value pair)
-l look up only first device with token specified by -t
-L <label> convert LABEL to device name
-U <uuid> convert UUID to device name
-v 显示版本信息
-w <file> write cache to different file (/dev/null = no write)
<dev> specify device(s) to probe (default: all devices)
Low-level probing options:
-p low-level superblocks probing (bypass cache)
-i gather information about I/O limits
-S <size> overwrite device size
-O <offset> probe at the given offset
-u <list> filter by "usage" (e.g. -u filesystem,raid)
-n <list> filter by filesystem type (e.g. -n vfat,ext3)
实例
1.列出当前系统所有已挂载文件系统的类型:
sudo blkid
/dev/mmcblk1p1: PARTLABEL="uboot" PARTUUID="8589c6a2-c8ee-4ee0-b2fe-91d7a889bf35"
/dev/mmcblk1p2: PARTLABEL="trust" PARTUUID="a44dd545-1b58-48ed-bf69-e97e6690d257"
/dev/mmcblk1p3: PARTLABEL="misc" PARTUUID="f742a48a-08f9-4c23-947a-7fc970f8ba95"
/dev/mmcblk1p4: PARTLABEL="boot" PARTUUID="764b8c92-b2da-40eb-84e9-65466489b325"
/dev/mmcblk1p5: PARTLABEL="recovery" PARTUUID="79e2234c-79f5-4db7-850b-64a5bb2dc796"
/dev/mmcblk1p6: PARTLABEL="backup" PARTUUID="26da19a4-bf97-40c0-9426-da14be71a6a1"
/dev/mmcblk1p7: PARTLABEL="splash" PARTUUID="528e0fc0-6035-4491-aff7-45126902df8f"
/dev/mmcblk1p8: UUID="55fa08b1-29f9-437b-8b81-b80832a03768" BLOCK_SIZE="4096" TYPE="ext2" PARTLABEL="userdata" PARTUUID="33b5afbc-ad69-4672-bb9c-b2356f536d1a"
/dev/mmcblk1p9: UUID="5effb51b-cf45-4296-bd2e-d84f5efe00e6" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="rootfs" PARTUUID="b59e03fb-e478-4ba9-9bb2-f2f6a06135b5"
由此可知,此系统有8个分:uboot、trust、misc、boot、recovery、backup、userdata和rootfs。
2.显示指定设备 UUID:
sudo blkid -s UUID /dev/mmcblk1p8
/dev/mmcblk1p8: UUID="55fa08b1-29f9-437b-8b81-b80832a03768"
3.列出所有设备的UUID:
sudo blkid -s UUID
/dev/mmcblk1p8: UUID="55fa08b1-29f9-437b-8b81-b80832a03768"
/dev/mmcblk1p9: UUID="5effb51b-cf45-4296-bd2e-d84f5efe00e6"
4.显示指定设备 LABEL:
sudo blkid -s LABEL /dev/mmcblk1p8
5.显示所有设备 LABEL:
sudo blkid -s LABEL
6.显示所有设备文件系统:
sudo blkid -s TYPE
/dev/mmcblk1p8: TYPE="ext2"
/dev/mmcblk1p9: TYPE="ext4"
7.显示所有设备:
sudo blkid -o device
/dev/mmcblk1p8
/dev/mmcblk1p9
/dev/mmcblk1p1
/dev/mmcblk1p2
/dev/mmcblk1p3
/dev/mmcblk1p4
/dev/mmcblk1p5
/dev/mmcblk1p6
/dev/mmcblk1p7
8.以列表方式查看详细信息:
sudo blkid -o list
device fs_type label mount point UUID
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/dev/mmcblk1p8 ext2 /boot 55fa08b1-29f9-437b-8b81-b80832a03768
/dev/mmcblk1p9 ext4 / 5effb51b-cf45-4296-bd2e-d84f5efe00e6
/dev/mmcblk1p1 (not mounted)
/dev/mmcblk1p2 (not mounted)
/dev/mmcblk1p3 (not mounted)
/dev/mmcblk1p4 (not mounted)
/dev/mmcblk1p5 (not mounted)
/dev/mmcblk1p6 (not mounted)
/dev/mmcblk1p7 (not mounted)