How do I print my logical volume group UUID to file?
Solution 1:
Note: This answer is just example code as I only have one Core Storage Volume to test against, however, if there's more then one, the awk
command could be modified to accommodate accordingly. Although without the output of multiple Core Storage Volumes, I cannot give an example.
If it's the Logical Volume Group UUID
, you can user the following example:
$ lvguuid="$(diskutil coreStorage list | awk '/Logical Volume Group/{print $5}')"
$ echo "$lvguuid"
696AD841-1F53-4D33-9496-3E36D33AB270
$
In the awk
command, you can substitute Logical Volume Group
with Physical Volume
, Logical Volume Family
and change $5
as appropriate. Based on the order of the search string shown in this line, it will be $5
, $4
, $5
.
For Logical Volume
, you'll need to use a regex
, as in the following example:
lvuuid="$(diskutil coreStorage list | awk '/Logical Volume [A-F0-9]{8}-/{print $4}')"
Understanding the regex
:
-
Logical Volume [A-F0-9]{8}-
-
Logical Volume
matches the charactersLogical Volume
literally (case sensitive).
-
-
[A-F0-9]{8}
- Match a single character present in the list below.-
{8}
Quantifier — Matches exactly 8 times. -
A-F
a single character in the range betweenA
(index 65) andF
(index 70) (case sensitive). -
0-9
a single character in the range between0
(index 48) and9
(index 57) (case sensitive). -
-
matches the character-
literally (case sensitive).
-
So, in my example awk
matches Logical Volume 38712F52-
and returns:
38712F52-5967-4A49-87D6-C66D4B199F28
The above examples set a variable that can be called from the command line or script, however, if you what the output to a file, then use the following example:
diskutil coreStorage list | awk '/Logical Volume Group/{print $5}' > /path/to/filename
On my system here's the output of the diskutil coreStorage list
command on an encrypted USB Flash Drive:
$ diskutil coreStorage list
CoreStorage logical volume groups (1 found)
|
+-- Logical Volume Group 696AD841-1F53-4D33-9496-3E36D33AB270
=========================================================
Name: Encrypted
Status: Online
Size: 15661490176 B (15.7 GB)
Free Space: 16777216 B (16.8 MB)
|
+-< Physical Volume E0E76F6B-A4E2-466D-B8E5-D5977ECD0522
| ----------------------------------------------------
| Index: 0
| Disk: disk3s2
| Status: Online
| Size: 15661490176 B (15.7 GB)
|
+-> Logical Volume Family EAF4984B-94C8-49B6-BCC6-76A8724E04D2
----------------------------------------------------------
Encryption Status: Unlocked
Encryption Type: AES-XTS
Conversion Status: Complete
Conversion Direction: -none-
Has Encrypted Extents: Yes
Fully Secure: Yes
Passphrase Required: Yes
|
+-> Logical Volume 38712F52-5967-4A49-87D6-C66D4B199F28
---------------------------------------------------
Disk: disk4
Status: Online
Size (Total): 15325941760 B (15.3 GB)
Size (Converted): -none-
Revertible: Yes (unlock and decryption required)
LV Name: Encrypted
Volume Name: Encrypted
Content Hint: Apple_HFS
$