0

when I'm configuring grub2 to unlock an LVM root (rd.luks.name=UUID=cryptroot) I usually just blkid /dev/nvme0n1p3 >> uuid, edit the text and delete all the data that isn't the UUID, and then :r uuid to insert it to the grub config in vim. I know there has to be an easier way to do this with sed but so far the closest I've gotten is as follows:

➜  ~ blkid /dev/nvme0n1p3
/dev/nvme0n1p3: UUID="2276de2b-9370-4577-90ea-3b0191ebea4e" 
TYPE="crypto_LUKS" PARTUUID="b7a643ce-8bca-418f-a631-b0fc8648432c"

➜  ~ blkid /dev/nvme0n1p3 | sed 's/.*UUID="\(.*\)" .*/\1/'        
2276de2b-9370-4577-90ea-3b0191ebea4e" TYPE="crypto_LUKS

Anyone have any idea what I could add to the sed arguments to get rid of everything after the end of the UUID including that quotation mark?

barish
  • 1
  • Possible duplicate of [Non greedy (reluctant) regex matching in sed?](https://stackoverflow.com/questions/1103149/non-greedy-reluctant-regex-matching-in-sed) – Håken Lid Oct 16 '18 at 17:00
  • `blkid /dev/nvme0n1p3 | sed -E 's/.*UUID="([^"]*)".*"/\1/'` – Cyrus Oct 16 '18 at 17:06

1 Answers1

1
blkid -s UUID -o value /dev/nvme0n1p3

or

lsblk -n -o UUID /dev/nvme0n1p3

Output:

2276de2b-9370-4577-90ea-3b0191ebea4e

See: man blkid

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Damn I suck. Thank you so much, both for the solution and reminding me to always check the manual – barish Oct 16 '18 at 17:26