Originally Posted by
Artif
There is a usual name for HHD's device file:
/dev/vda
The is a usual name for a partition:
/dev/vdaX
where X is a number.
How can I obtain reliably all these names in a script or in any other way?
You can directly read the device files in the /dev directory, then trim the output as required. For example, the HDD device files in my /dev directory -
Code:
~$ ls -1 /dev/sd??
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
/dev/sda6
/dev/sda7
/dev/sda8
To get the device name (in case there are also sdb, sdc... etc. are present with valid partitions on them) -
Code:
~$ ls -1 /dev/sd?? | cut -c 6-8 | sort -u
sda
You can also use "ls -1 /dev/sd? | cut -c 6-", but it will also list the devices which doesn't have a valid partition on it (e.g. - a modem's card reader with no card in it)
To parse the partition numbers -
Code:
$ ls -1 /dev/sd?? | cut -c 8-
a1
a2
a3
a4
a5
a6
a7
a8
Or,
Code:
$ ls -1 /dev/sd?? | cut -c 9
1
2
3
4
5
6
7
8
..if only the last number is required. But that may be confusing if more than one device is present.
But anyway, I hope it gives you an idea to parse the parts of interest, then use them as they are or further strip them as you wish.
Bookmarks