| Author |
Message |
sunburnt

Joined: 08 Jun 2005 Posts: 4005 Location: Arizona, U.S.A.
|
Posted: Fri 16 Oct 2009, 03:51 Post subject:
How To: Get drive volume label with Bash? |
|
I Googled for over an hour and cfdisk was suggested, but no workie.
There`s e2label for ext2 partitions, but no e3label or M$ label utility.
It was suggested that the rox and gtk bookmarks have the volume label.
If a USB pen is labeled: Puppy, then the bookmarks show: Puppy /mnt/sda1.
|
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 1759
|
Posted: Fri 16 Oct 2009, 07:59 Post subject:
|
|
'blkid' is what you need -it will retrieve the label from nearly any filesytem type:
|
|
Back to top
|
|
 |
MU

Joined: 24 Aug 2005 Posts: 13642 Location: Karlsruhe, Germany
|
Posted: Fri 16 Oct 2009, 08:30 Post subject:
|
|
pdrive shows labels:
http://www.murga-linux.com/puppy/viewtopic.php?t=21200
the relevant part is in /usr/local/pdrive/func_probe:
| Code: | VOLUME_LABEL=""
case "$ONEFS" in
ntfs)
if [ `ntfslabel -f $ONEDEV 2> /dev/null` ]; then VOLUME_LABEL="`ntfslabel -f $ONEDEV 2> /dev/null`"; fi;;
vfat)
if [ `mlabel -i $ONEDEV -s :: 2> /dev/null | cut -d " " -f 4` ]; then
VOLUME_LABEL="`mlabel -i $ONEDEV -s :: 2> /dev/null | cut -d " " -f 5`"; fi;;
ext*)
if [ `e2label $ONEDEV 2> /dev/null` ]; then VOLUME_LABEL="`e2label $ONEDEV`"; fi;;
esac
#--- |
So e2label seems to be used also for ext3.
For ntfs you use "ntfslabel", and for fat "mlabel".
Mark
_________________ my recommended links
Last edited by MU on Fri 16 Oct 2009, 08:33; edited 1 time in total
|
|
Back to top
|
|
 |
MU

Joined: 24 Aug 2005 Posts: 13642 Location: Karlsruhe, Germany
|
Posted: Fri 16 Oct 2009, 08:33 Post subject:
|
|
oh, Amigo was faster.
Yes, he is correct, blkid shows my testlabel that I just added, too
A much better solution that is.
result from "blkid":
| Quote: | | /dev/sde13: UUID="863af64f-1da4-4994-9798-cbc686dbe217" TYPE="ext2" LABEL="testlabel" |
Mark
_________________ my recommended links
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4005 Location: Arizona, U.S.A.
|
Posted: Fri 16 Oct 2009, 12:05 Post subject:
|
|
Thanks guys, it`s amazing how difficult it is to find info some times.
And other times it appears immediately, this one was slightly obscure.
I looked at mtools too, but I knew it was much more than was required.
|
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 1759
|
Posted: Fri 16 Oct 2009, 16:09 Post subject:
|
|
blkid is a great tool -much better than using 'fdisk -l' to find disks as well. I use it for my USB-auto-mounting program. One thing to be aware of is that running it creates a file /etc/blkid.tab with the info. Successively running blkid will not always refresh this file, so if you use blkid to identify disks, be sure to remove /etc/blkid.tab first so you get fresh info.
blkid is even more accurate than looking at /proc/partitions as the proc info can also become stale under certain circumstances.
Cheers!
|
|
Back to top
|
|
 |
|