Article 6FM1C [SOLVED] Partition numbering (as in /dev/sda1 sda2 and so on)

[SOLVED] Partition numbering (as in /dev/sda1 sda2 and so on)

by
trafikpolisen
from LinuxQuestions.org on (#6FM1C)
Hi!

I have a simple question, which I can't really seem to find a definite answer to.
I'm working on a script to automate the process of encrypting drives with cryptsetup/LUKS. Something like this: Ask to completely erase drive with dd or not -> Create GPT partition table and a new empty partition with parted -> Create a new encrypted volume in that empty partition with cryptsetup -> Unlock the new encrypted volume -> Run the mkfs.ext4 command to create an ext4 filesystem within the encrypted volume -> Lock the volume -> Done:)

Now to the problem: When running parted to create the partition table and partition, I of course reference the device by /dev/sdb for example. But when it's time to create the LUKS volume, I need the "partition", i.e. /dev/sdb1. Is the only partition on a drive ALWAYS going to be "1", i.e. /dev/sdb1, /dev/sdc1, etc? If so, it would be very easy to just use my variable, which holds "/dev/sdb" for example and just add the number "1". But if not, my solution at the moment is a somewhat "overengineered" one, where I use blkid to list the UUID's of the device (which is only going to be one after creating the single partition) and then feed that UUID into blkid again to get the "/dev/sdb1" for example.
How do I most reliably get the "/dev/sdX[NUMBER]" from "/dev/sdX"?

All the best!
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments