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 Thu 30 Oct 2014, 14:21
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 Posts_count  
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5039
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: 2263

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

Edited_time_total
Back to top
View user's profile Send_private_message Visit_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_website 
sunburnt


Joined: 08 Jun 2005
Posts: 5039
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: 2263

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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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