How to obtain the partition device name and mount point when the file systemlabel is known?There are several possibilities:LinuxFile system label to device nameThe device name can be obtained with blkid:blkid -l -o device -t LABEL=$label -c /dev/nullDevice name to mount pointI tried obtaining the mount point with blkid, but I failed. Using the -sswitch all other fields can be queried when the label is provided:blkid -l -t LABEL=$label -o value -s LABEL      # yields labelblkid -l -t LABEL=$label -o value -s TYPE       # yields partition typeblkid -l -t LABEL=$label -o value -s UUID       # yields UUIDblkid -l -t LABEL=$label -o value -s MOUNTPOINT # yields nothingObtaining the mount point is not supported apparently, though it is listedwhen the -o list option is given, but not in an easy parseable way:blkid -o list -c /dev/null <device>The next attempt was to use df -P. Here's what I came up with, assuming thedevice is stored in the variable device:export devicemountpoint=$(df -P |  awk --assign dev=$device \    '{if ($1==dev)             \      {for (i=1; i<=NF-5; i++) \        $i=$(i+5);             \        NF-=5;                 \        print                  \      }                        \    }')This code works. However, given it's ugliness I'm not convinced that parsingdf is the preferred way.Other UnicesFile system label to device nameblkid works beautifully on Linux, but it's not available on Solaris orFreeBSD (at least one can't expect it to be installed). The same goes forfindfs.How do I obtain the device name in a portable way on Linux, Solaris andFreeBSD?Device name to mount pointHappily df -P produces very similar output on all tested systems. Theproblem is that my ugly awk script doesn't seem to be portable (tested withSun awk, gawk on Solaris and FreeBSDs awk). What's the preferred way?Related questionsHow to get the mount point of flash drive by using uuid?Problem: Parsing /proc/mounts is not portable and troublesome even on Linux.Parsing mount seems even worse. Perl is generally not available.Is there a command to see where a disk is mounted?Problem: Parses /proc/mounts with a buggy awk script. The solutions aren't portable.SummaryI'd like to obtain the device name and mount point when the file system labelis provided in a portable way (assuming a POSIX shell). The disk label mightcontain white space or other non-ASCII characters which seems to complicatethings even more.         Label-To-Device    Device-To-Mount-Point         ---------------    ---------------------Linux                                (ugly)Solaris         .                    .FreeBSD         .                    .
Obtain device name and mount point if partition label is known
mount;freebsd;solaris;block device;posix