?
Solved

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

Posted on 2004-11-16
12
Medium Priority
?
558 Views
Last Modified: 2008-01-09
Hello,

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
0
Comment
Question by:beside
  • 6
  • 5
12 Comments
 
LVL 10

Expert Comment

by:Luxana
ID: 12592227
You can create label for device or display with command e2label

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

same it will be with usb ...
0
 
LVL 10

Expert Comment

by:Luxana
ID: 12592236
check man page for e2label

# man e2label

./lubo
0
 

Author Comment

by:beside
ID: 12592245
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Luxana
ID: 12592334
mkfs.vfat can set name for device with vfat

mkfs.vfat -n name /dev/hda2
0
 
LVL 10

Assisted Solution

by:Luxana
Luxana earned 140 total points
ID: 12592379
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
0
 

Author Comment

by:beside
ID: 12592399
yes everything works except, how to view volume label without chaning it? :)

because:
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?
0
 
LVL 10

Expert Comment

by:Luxana
ID: 12592482
cfdisk will display volume name...

Depends on what distro you have you may need install cfdisk

0
 

Author Comment

by:beside
ID: 12592498
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?
0
 
LVL 10

Expert Comment

by:Luxana
ID: 12592764
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?
0
 

Author Comment

by:beside
ID: 12592793
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.
0
 
LVL 4

Accepted Solution

by:
EinarTh earned 260 total points
ID: 12596312
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")
print f.read(128)[71:82]
f.close()
-----------------------

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...

HTH
0
 

Author Comment

by:beside
ID: 12602547
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.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question