1

I have an unmounted and unpartitioned hard drive and I need to get it's UUID. Is there a way to retrieve the UUID of this hard drive?

Running the command lsblk just gets me the information below enter image description here

In the disk utility program, this is all that it shows for the /dev/sdb hard drive(yes it says sdc, took the wrong screenshot but sdb shows the same thing)

enter image description here

Do I have to mount it or create a partition just to obtain the UUID of the hardrive at /dev/sdb?

CodeRich
  • 157

3 Answers3

6

Running blkid like this

sudo blkid -o list

will provide its UUID.

4

unmounted and unpartitioned hard drive and I need to get it's UUID

UUID is a property of filesystem or format, unformatted hard drives don't have UUIDs. You can get PARTUUID for partitions and PTUUID for partition tables, see this question, but that also doesn't apply for an empty disk.

Unique identifier for disks is WWID/WWN provided by the disk itself. You can get it either from sysfs

$ cat /sys/block/sda/device/wwid 
naa.5002538e40aa0206

or from a symlink in /dev/disk/by-id

$ ls -la /dev/disk/by-id/ | grep sda
lrwxrwxrwx. 1 root root   9 Mar 10 07:21 wwn-0x5002538e40aa0206 -> ../../sda

or UDev (which is in charge of creating the symlink)

$ udevadm info /dev/sda | grep ID_WWN
E: ID_WWN=0x5002538e40aa0206
E: ID_WWN_WITH_EXTENSION=0x5002538e40aa0206
0

blkid should work with unmounted disks, but you must make sure that the disk is formatted.

List disks:

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  1,7T  0 disk
sdb      8:16   0  300G  0 disk
sdc      8:32   0   64G  0 disk
├─sdc1   8:33   0   63G  0 part /
├─sdc2   8:34   0    1K  0 part
└─sdc5   8:37   0  975M  0 part [SWAP]

Before format:

$ blkid -o list
device                       fs_type     label        mount point                      UUID
----------------------------------------------------------------------------------------------------------------------------
/dev/sdc1                    ext4                     /                                9c49994f-6ffd-496a-945b-85e3b04a84ef
/dev/sdc5                    swap                     [SWAP]                           f14ea985-e1e6-43a8-ba09-12a273604c96

Note: /dev/sdb is not shown.

Format disk with ext4:

$ mkfs.ext4 /dev/sdb
mke2fs 1.46.2 (28-Feb-2021)
Discarding device blocks: done
Creating filesystem with 78643200 4k blocks and 19660800 inodes
Filesystem UUID: d4b71992-fbc3-4263-b974-e5933a1ebfe4
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Allocating group tables: done Writing inode tables: done Creating journal (262144 blocks): done Writing superblocks and filesystem accounting information: done

Now running blkid again:

$ blkid -o list
device                                          fs_type         label            mount point                                         UUID
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/dev/sdc1                                       ext4                             /                                                   9c49994f-6ffd-496a-945b-85e3b04a84ef
/dev/sdc5                                       swap                             [SWAP]                                              f14ea985-e1e6-43a8-ba09-12a273604c96
/dev/sdb                                        ext4                             (not mounted)                                       d4b71992-fbc3-4263-b974-e5933a1ebfe4
wjentner
  • 101