How To: Get drive volume label with Bash?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

How To: Get drive volume label with Bash?

#1 Post by sunburnt »

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.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#2 Post by amigo »

'blkid' is what you need -it will retrieve the label from nearly any filesytem type:

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#3 Post by MU »

pdrive shows labels:
http://www.murga-linux.com/puppy/viewtopic.php?t=21200

the relevant part is in /usr/local/pdrive/func_probe:

Code: Select all

	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
Last edited by MU on Fri 16 Oct 2009, 12:33, edited 1 time in total.
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#4 Post by MU »

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":
/dev/sde13: UUID="863af64f-1da4-4994-9798-cbc686dbe217" TYPE="ext2" LABEL="testlabel"


Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#5 Post by sunburnt »

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.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#6 Post by amigo »

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!

Post Reply