How to get drive SERIAL number from mountpoint?
These options will print your disk serial without headings: lsblk -n -o SERIAL /dev/sda
Options explained, and that can be found at the manpages:
-n, --noheadings
Do not print a header line.
This option will remove headers like Serial:
from the command output.
-o, --output list
Specify which output columns to print. Use --help to get a list of all supported columns.
Select what information to print about disks.
This will be enough to bring you only the serial. Unfortunately, lsblk
does not work with mountpoints, since the serial is an attribute of the disk, not the partition. Taking a look at the synopsis
:
Synopsis
lsblk [options]
lsblk [options] device...
You will have to make a huge effort to extract from the mountpoint the partition, trim the disk information and then, supply it as parameter to lsblk
. This will probably do the trick:
mount| grep /run/media/main/mydrive | awk 'NR==1{print $1}'|sed 's/[0-9]*//g'
mount
will list all mountpoints, grep
will get the line of your mountpoint, awk
will get the partition column and sed
will remove numbers, that are the representation of partitions. Summing all:
lsblk -n -o SERIAL `mount| grep /run/media/main/mydrive | awk 'NR==1{print $1}'|sed 's/[0-9]*//g'`