blkid

disk managementlinux
The blkid command is one of the most frequently used commands in Linux/Unix-like operating systems. blkid The blkid command is a utility to locate and print block device attributes such as filesystem type, UUID, and volume label. It's commonly used for device identification and mounting filesystems.

Quick Reference

Command Name:

blkid

Category:

disk management

Platform:

linux

Basic Usage:

blkid [options] [arguments]

Common Use Cases

    Syntax

    blkid [options] [device...]

    Options

    Option Description
    -c, --cache Read from or write to the specified cache file (default: /etc/blkid.tab)
    -g, --garbage-collect Garbage collect the blkid cache
    -h, --help Display help information and exit
    -i, --info Display block device information in name=value format
    -k, --list-filesystems List all known filesystems/RAIDs and exit
    -l, --list-one List one device that matches the search parameter
    -L, --label Look up the device that uses this filesystem label
    -n, --match-types Restrict probing functions to the specified list of filesystem types
    -o, --output Specify output format (full, value, list, device, udev, export)
    -p, --probe Low-level probe of block devices (bypass the cache)
    -s, --match-tag Show only the tags that match the specified names
    -t, --match-token Search for block devices with the specified NAME=value
    -U, --uuid Look up the device that uses this UUID
    -v, --version Display version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the blkid command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    #

    Basic Examples:

    # Display information for all block devices
    blkid
    # Show information for a specific device blkid /dev/sda1
    # Display UUID only for a specific device blkid -s UUID /dev/sda1
    # Output in a name=value format blkid -o value -s UUID /dev/sda1
    # List all devices with ext4 filesystem blkid -t TYPE=ext4

    Advanced Examples:

    # List all available tags for a device
    blkid -o full /dev/sda1
    # Output in JSON format blkid -o json # Low-level probing (bypass the cache) blkid -p /dev/sda1 # Find device by UUID blkid -U 13f63f5f-7cd5-4b4f-8b00-d3c0955b47ea # Find device by filesystem LABEL blkid -L "ROOT_FS" # Check if a device has a specific filesystem type if blkid -p -n ext4 /dev/sda1 &>/dev/null; then echo "ext4 filesystem found" fi # Use blkid output in a script to mount by UUID UUID=$(blkid -s UUID -o value /dev/sda1) mount UUID=$UUID /mnt/myfs # Create a list of partitions with their filesystem types blkid -o device -s TYPE | sort

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    Key Features:

    The blkid command is a critical utility for system administration:

    • Identifies block devices and their attributes
    • Determines filesystem types without mounting them
    • Shows universally unique identifiers (UUIDs) for filesystems
    • Displays volume labels if available
    • Supports a wide range of filesystem formats and RAID configurations
    • Can search for devices by UUID, LABEL, or TYPE

    Common Tags:

    • UUID: Universally Unique Identifier for the filesystem
    • TYPE: Filesystem type (ext4, xfs, btrfs, ntfs, etc.)
    • LABEL: Filesystem label or name
    • PARTLABEL: Partition label for GPT partition tables
    • PARTUUID: UUID of the GPT partition
    • FSTYPE: Same as TYPE, the filesystem type
    • USAGE: Usage type (filesystem, raid, crypto, etc.)
    • PTTYPE: Partition table type (dos, gpt, etc.)

    Usage in System Configuration:

    • fstab entries: Use blkid to get UUIDs for persistent device naming in /etc/fstab
    • GRUB configuration: Identify root filesystem UUID for bootloader configuration
    • Automounting: Create udev rules based on blkid information
    • System recovery: Identify partitions without relying on potentially changing device names

    Cache Management:

    • blkid maintains a cache file (typically /etc/blkid.tab or /run/blkid/blkid.tab)
    • Use -c option to specify an alternate cache file
    • The -p (probe) option bypasses the cache for direct device inspection
    • Cache garbage collection can be performed with the -g option

    Advantages of Using UUIDs:

    • Device-independent identification of filesystems
    • Consistent mapping even if disk order changes
    • Reliable mounting in systems with multiple storage devices
    • Protection against device name changes after hardware modifications

    Security Considerations:

    • blkid typically requires root privileges to access all block devices
    • Regular users may have limited visibility of device information
    • The cache file may contain sensitive system information

    Related Commands

    These commands are frequently used alongside blkid or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the blkid command works in different scenarios.

    $ blkid
    View All Commands