LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Get devise name from uuid (https://www.linuxquestions.org/questions/linux-general-1/get-devise-name-from-uuid-4175736718/)

Cannondale 05-04-2024 07:43 PM

Get devise name from uuid
 
Is there an easy way to get a devise name from given uuid?

frankbell 05-04-2024 08:24 PM

I don't think so.

As far as I can determine, the two are independent variables. One is not related to the other.

If I am, as my old boss used to say, "in error," I trust someone with straighten me out.

colorpurple21859 05-04-2024 08:38 PM

maybe this:
sudo blkid |grep uuid

Cannondale 05-05-2024 05:34 AM

Thanks for the reply guys.

I actually stumbled onto to a simple solution and wanted to post it here for future reference.

The sample code below will return the device name (/dev/sdXX). Of course, insert your own actual UUID for valid results.


Code:

blkid -U 2a4a9f2e-3233-4936-84d9-3aa507d6b2bd

GazL 05-05-2024 05:59 AM


findfs UUID=<insert-uuid-here>

boughtonp 05-05-2024 09:39 AM

Quote:

Originally Posted by frankbell (Post 6499891)
If I am, as my old boss used to say, "in error," I trust someone with straighten me out.

Ok, since you asked... a post like that after less than an hour is not constructive.

When a thread has no replies, it stays in the zero reply list - making it easier for people to find threads that have yet to be answered. Threads without replies get auto-bumped twice, to cater for different timezones.

When someone posts with a "I dunno" reply, it takes the thread out of that list and does not help the person asking for help, and - when done within an hour - reduces the number of people who might see it, and thus is even less helpful.

If someone waits a few days and then invokes Cunningham's Law, they can still enjoy looking foolish, but without reducing the number of people who see a thread and thus might be able to help the person asking.

(Hopefully this is all taken in the constructive manner intended, and also encourages other LQ users to consider if they should post immediately or to wait a few days before removing threads from the Zero Reply list.)

-

Anyhow, back to device names and UUIDs there are (at least) three options for getting a block device name from uuid:
Code:

blkid -U YOUR_UUID
findfs UUID=YOUR_UUID
findmnt UUID=YOUR_UUID

blkid - locate/print block device attributes
findfs - find a filesystem by label or UUID
findmnt - find a filesystem (may be specified by device name, major:minor numbers, filesystem label or UUID, or partition label or UUID.)

None of them need grep.
The first two are in /sbin but - depending on permissions - it might be enough to use /sbin/blkid or /sbin/findfs to run as non-root user; or just use findmnt which doesn't

To go in the other direction, and output the UUID give a device name, neither of these options need root/sudo...
Code:

findmnt -o UUID /dev/sdXY
lsblk -o UUID /dev/sdXY

(Consult --help and/or the manpages for formatting and other available options.)



All times are GMT -5. The time now is 02:20 PM.