How to Get UUID in Linux [5 Best Methods]

Written by

Reviewed by

Last updated: July 12, 2024

Expert verified

SVG Image

TL;DR

To learn how to get UUID in Linux, you can try this method:

  1. Launch your Linux system’s Terminal.
  2. Type blkid and press Enter to display a list of devices along with their UUIDs.
  3. Optionally, use blkid -s UUID to show only the UUIDs of the devices.

Learn more about how to get UUID in Linux Terminal with five proven methods and how to change the UUID of partition in Linux.

Ever had trouble identifying your devices or files in Linux? Knowing how to find and manage UUIDs (Universally Unique Identifiers) can make this a lot easier. In this post, I’ll show you how to check and change UUIDs in Linux. You’ll learn simple methods to get UUIDs, change them, and fix common errors. With step-by-step instructions using commands like blkid, lsblk, and hwinfo, you’ll gain the skills to handle UUIDs confidently and manage your system more efficiently.

What is UUID?

A UUID, or Universally Unique Identifier, is a unique number used to identify information in computer systems. Think of it as a serial number for your devices and files. A UUID is a 128-bit number and it helps identify devices, files, or data uniquely without any overlap, ensuring smooth operation and avoiding conflicts.

Structure of a UUID

A typical UUID looks like this: 550e8400-e29b-41d4-a716-446655440000

  • 128 Bits Long: This length ensures that UUIDs have an extremely low chance of being duplicated.
  • 32 Characters: The UUID has 32 characters divided into five groups, separated by hyphens.
  • Hexadecimal Digits: It uses hexadecimal digits (0-9 and a-f).

Breakdown of the UUID Structure

  1. Time-Based: Part of the UUID is based on the current time.
  2. Randomness: Another part is random, ensuring even more uniqueness.

How to Get UUID in Linux?

To check UUID Linux, you can use the blkid command, which provides a straightforward and direct way to list the UUIDs along with other filesystem information. Open your terminal and type sudo blkid, and this command will display the UUIDs for all recognized block devices. Ensure you have the necessary permissions to execute this command, as it may require superuser privileges.

Here is the step-by-step guide to using the blkid command and four more methods to find UUID in Linux:

1. blkid Command

The blkid command is a powerful utility that allows you to locate UUIDs in Linux. This method lets you quickly retrieve UUID information for your devices and filesystems. Follow these steps to use the blkid command effectively:

  1. Open a Terminal on your Linux system.
opening-terminal
  1. Type the following command and press Enter to execute the command: 
blkid

The output will display a list of devices and their corresponding UUIDs in Linux. 

    command-to-find-UUID-in-Linux
    1. Use the -s option only to view UUIDs.
    displaying-UUID-strings

    2. Checking /etc/fstab

    The /etc/fstab file contains vital information about the filesystems mounted on your Linux system. This method allows you to find UUIds in Linux by examining the contents of this file. You can find UUID in Linux by following these steps:

    1. Launch the terminal window on your Linux system. Use a text editor to open the /etc/fstab file and run the following command:
    sudo nano /etc/fstab

    This command will show UUID in a nano text editor.

      using-nano-editor-to-view-UUID
      1. Look for lines that contain UUID= followed by a UUID string.
      displaying-UUID-strings

      3. lsblk Command

      The lsblk command allows you to list block devices along with their UUIDs. By employing this method, you can obtain a comprehensive view of the devices and their associated UUIDs. To employ this method, follow these steps:

      1. Launch a terminal on your Linux system and execute the command: 
      lsblk -o name,uuid

      The output will present a list of devices along with their corresponding UUIDs. 

        listing-devices-and-their-UUID

        4. Using hwinfo

        hwinfo is a powerful tool for reporting detailed information about the hardware configuration of the machine. It can also display UUIDs for storage devices among a wide range of other hardware details. 

        1. Open your terminal and run the following command to install hwinfo on your system:
        sudo apt-get install hwinfo

        This command downloads and installs the hwinfo utility from the repository.

        installing hwinfo on ubuntu
        1. After installation, execute the command:
        sudo hwinfo --disk

        This command scans and reports detailed information about all disk devices, including their UUIDs. Review the output displayed in your terminal to locate the UUIDs, which are typically listed under the information for each disk device.

        viewing disks uuid using hwinfo

          5. Exploring /dev/disk/by-uuid/

          The /dev/disk/by-uuid/ directory in Linux contains symbolic links that map UUIDs to their corresponding device files. This setup is crucial for ensuring devices are identified consistently and reliably, regardless of changes in the system’s hardware configuration.

          1. Open your Terminal and change to the /dev/disk/by-uuid/ directory to view all storage devices identified by their UUIDs:
            cd /dev/disk/by-uuid/

            This command changes the current directory to /dev/disk/by-uuid/, where you can see links representing each disk partition.

            changing directory to disk partitions
            1. Execute the command to list the contents of the directory:
            ls -l

            This command provides a detailed list of all symbolic links in the directory, showing each UUID linked to its respective device file. The result will display symbolic links formatted like this:

            1. 90b1…… represents the UUID of the partition.
            2. ../../sda3 indicates the actual device name corresponding to this UUID.
            listing disk partitions uuids

            How to Change the UUID of Partition in Linux?

            Changing the UUID of partition in Linux is a process that should be done with caution, as it can affect system behavior, especially if the UUID is referenced in system configuration files like /etc/fstab. Here’s how to change the UUID of partition in Linux:

            Prerequisites

            • Backup your data: Before making any changes to the disk partition, it’s wise to back up any important data.
            • Identify the partition: You should know the specific partition whose UUID you wish to change.

            Changing the UUID for EXT4 Partitions

            1. You can list all partitions and their current UUIDs using the blkid command.
            blkid
            listing all current disk partitions and uuids 1
            1. Before you change the UUID, you need to unmount the partition if it is in use. You can unmount it using:
            sudo umount /dev/sdXn

            Replace /dev/sdXn with your partition’s device identifier.

            unmounting disk partition
            1. Use tune2fs to change the UUID of the EXT4 partition:
            sudo tune2fs -U random /dev/sdXn

            This command sets a new random UUID to the partition. You can also set a specific UUID by replacing random with the new UUID string.

            changing uuid of a disk partition
            1. Use blkid to confirm that the UUID has been changed:
            sudo blkid /dev/sdXn
            successfully changed the uuid

            Common Errors When Checking Linux UUID

            When working with UUIDs in Linux, it’s important to be aware of common errors that can occur. By understanding these errors, you can troubleshoot and resolve them effectively. Here are four common errors related to UUIDs:

            • UUID Not Found: This error happens when you reference a non-existent or incorrect UUID. To fix it, double-check the UUID you are using. Verify the UUID with blkid /dev/sda1, and update your configuration files or commands with the correct UUID.
            • 🔀 UUID Conflict: A conflict occurs when two partitions share the same UUID, causing confusion and potential data loss. Change the UUID of one partition using sudo tune2fs -U new_uuid /dev/sda1 or mkfs with the -U option. Update your system configuration and references accordingly.
            • Incorrect UUID Reference: Errors can arise from incorrect UUID references in configuration files or scripts. Review the affected files and ensure the UUIDs are accurate. Update the references with the correct UUIDs to restore functionality.
            • 🔄 UUID Changes After Disk Replacement: Replacing a disk or migrating data can change the UUID of a partition. Update your configuration files, scripts, or commands with the new UUID. Use blkid /dev/sdb1 to find the new UUID and make the necessary changes in your system.

            Linux Get UUID: Final Thoughts

            In this guide, I showed you various methods to check UUIDs in Linux, such as using blkid, lsblk, and hwinfo, and by exploring the /etc/fstab file and the /dev/disk/by-uuid/ directory. I also covered how to change a partition’s UUID with tune2fs and how to handle common UUID-related errors for smooth system management.

            If you found this article helpful, I recommend learning more about:

            Frequently Asked Questions 

            How do I restore a missing UUID in Linux?

            To restore a missing UUID in Linux, you’ll need to first identify the device without a UUID using a tool like blkid. Then, use a filesystem-specific command, such as tune2fs for EXT4, to assign a new UUID, for example, sudo tune2fs -U random /dev/sdx.

            Can UUIDs be the same on two different devices?

            No, UUIDs cannot be the same on two different devices. Each UUID is designed to be universally unique to ensure that each filesystem or partition can be identified distinctly without any ambiguity, regardless of the device or system it’s on.

            How can I find the UUID of a specific partition?

            To find the UUID of a specific partition in Linux, you can utilize the blkid command along with the device name. By specifying the device name, you can retrieve the UUID associated with that particular partition. For example, to find the UUID of the /dev/sda1 partition, you can use the following command: blkid /dev/sda1. Upon execution, the command will display the UUID of the specified partition.

            Can I use the UUID to mount a partition from the command line?

            Certainly! The UUID of a partition can be used to mount it from the command line in Linux. To mount a partition using its UUID, you can utilize the mount command, the UUID, and the desired mount point. For example, the following command can be used: sudo mount UUID=<UUID> /mnt. Replace <UUID> with the actual UUID of the partition you want to mount and /mnt with the desired mount point directory. This approach offers a convenient and reliable way to mount specific partitions without relying solely on device names.

            Ojash

            Author

            Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

            Akshat

            Reviewer

            Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

            Share this article
            Shareable URL
            Prev Post

            How to Install Snort on Ubuntu [7 Proven Steps]

            Next Post

            How to Install Go on Ubuntu[3 Easy Methods]

            Leave a Reply

            Your email address will not be published. Required fields are marked *

            Read next