Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 28 Jul 2014, 16:31
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How To: Get drive volume label with Bash?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: 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
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2221

PostPosted: 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
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: 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
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: 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 Smile
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
View user's profile Send private message Visit poster's website 
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: 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
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2221

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0579s ][ Queries: 12 (0.0106s) ][ GZIP on ]