How to get volume name of hard disc partition and usb key partition


Any body knows how to get volume name of hard disc partition and usb key partition like MS Windows displays on my computer. Can't find for half a day. So maybe you, experts, know something?

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can create label for device or display with command e2label

example :
create label
e2label /dev/hda2 name
e2label /dev/hda2

same it will be with usb ...
check man page for e2label

# man e2label

besideAuthor Commented:
this doesn't work with fat filesystem...

e2label gives me:

e2label: Bad magic number in super-block while trying to open /dev/sda1
Couldn't find valid filesystem superblock.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mkfs.vfat can set name for device with vfat

mkfs.vfat -n name /dev/hda2
but do not use if you have already data on it.


when you use -v it will also display label name

this command set and display name for vfat
mkfs.vfat -v /dev/hda2 -n name
besideAuthor Commented:
yes everything works except, how to view volume label without chaning it? :)

mkfs.vfat -v /dev/hda2

doesn't display volume label
but if I use as you said mkfs.vfat -v /dev/hda2 -n name
then it show name, but it change label too.

How to view label without changing it?
cfdisk will display volume name...

Depends on what distro you have you may need install cfdisk

besideAuthor Commented:
I know that cfdisk displays volume name, but I need some automation, so cfdisk is not the choise. Maybe there command line tools for this?
if you can determine label name and you need to automate something just create file with appropriate label names and drives. then just read this file ! what excactly do you need?
besideAuthor Commented:
After booting system I want to check if connected usb key consist of fat32 partition and correct volume label (I expect for example "update" label). If yes, then I do something if not do something else. So I need command line tool that gets volume label for /dev/sda1.
here is a hacked up python script which works on my FAT32 formatted usb disk (there is no error handling there, but hey, what'ya expect for 100 pts ;) :
#!/usr/bin/env python

import sys

f = open(sys.argv[1], "r")

In short, I did a dd on the partition, found the index where the label start and I happen to know that fat volume labels are max 11 characters...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
besideAuthor Commented:
Thank you EinarTh, your method is working nicely :) just on my two usb keys Windows FAT32 partition label starts on 43 byte. I rewrited program on C and everything works great. Thank you one more time. And thanks to Luxana. I split the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.