Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 10-02-2007, 06:06 PM   #1
Registered: Jul 2007
Posts: 30

Rep: Reputation: 15
Permanently labeling an external USB storage drive


I have 2 USB drives connected to my Ubuntu system.
I've added an entry in /etc/rc.local to mount the 2 USB drives to its mounting points.
mount /dev/sda /mnt/USB1
mount /dev/sdb /mnt/USB2
The 1st USB usually shows up as /dev/sda and the other /dev/sdb and sometimes the device shows up the other way around upon reboot, 1st USB as /dev/sdb and the 2nd USB as /dev/sda.
So after a reboot, when this happens, the USBs get mounted in wrong order.
Is there a way to permanently label an external USB drive so that even when the USB drives show up in reverse order, it still gets mounted correctly like the 1st USB as USB1 and the 2nd USB as USB2?
Old 10-02-2007, 06:45 PM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
First of all, you should have /dev/sda1 and /dev/sdb1 instead of /dev/sda & /dev/sdb.

What are the filesystems on each drive. I have used the mlabel program to label FAT partitions. For example, I have an SD card labeled "podcasts". Inserting it, it is automounted as /media/PODCASTS. You could also create an entry in /etc/fstab using "LABEL=<Label Name>", e.g. "LABEL=PODCASTS" instead of /dev/sdb1.

You can also use the UUID number of the filesystem in place of the device entry in /etc/fstab.

One of the commands that is handy in looking up the label or UUID of a partition is the "udevinfo" command
udevinfo -q env -n /dev/sdb1
Install the "mtools" package if you have it. This package supplies the "mlabel" package. Add the following line to
drive p: file="/dev/sdb1". The p: device name is arbitrary. The default config will cover your floppy drives, but adding such a line will probably be needed to assign a dos type device name to a linux device. The /etc/mtools.conf file is well commented with plenty of commented out examples.

Use the appropriate value for the device, either /dev/sda1 or /dev/sdb1 in your case.
Now you can use mlabel to relabel the drive like this:
mlabel p:label

Using my example:
sudo mlabel -s p:
 Volume label is CruzerMini256 (abbr=CRUZERMINI2)
jschiwal@hpamd64:~> sudo mlabel  p:XMasMusic
You will need to safely eject the drive, and then reinsert it. It should automount with the new label.


If these are removable drives you don't want to have them mounted when you boot. If one of them is disconnected, it will cause a stall or a failure to boot up successfully.

If your system doesn't use udev, and drives don't automount, then you could have entries in /etc/fstab that include the options "noauto,user,uid=username,gid=groupname".

This will allow you to mount these drives as a normal user without having to use sudo or enter a password. You would need to create a mount point for it, but this would allow you to include the mount commands in your ~/.profile file.

Here is how the XMASMUSIC pendrive automounted:
/dev/sdb1 on /media/XMASMUSIC type vfat (rw,nosuid,nodev,noatime,flush,uid=1000,utf8,shortname=lower
So if I wanted to use an fstab entry I would probably use:
LABEL=XMAS /media/XMAS  vfat rw,nosuid,nodev,noatime,flush,uid=jschiwal,fmask=117,dmask=007,utf8,shortname=lower

Last edited by jschiwal; 10-02-2007 at 06:56 PM.
Old 10-02-2007, 07:13 PM   #3
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,812

Rep: Reputation: 2168Reputation: 2168Reputation: 2168Reputation: 2168Reputation: 2168Reputation: 2168Reputation: 2168Reputation: 2168Reputation: 2168Reputation: 2168Reputation: 2168
Another option is udev rules - then it doesn't matter if the device(s) are plugged in at boot.
Gets messy if you bring in a lot of drives "one-off" from friends. Works o.k. for a (small) finite set of drives.
Old 10-10-2007, 10:53 AM   #4
Registered: Jul 2007
Posts: 30

Original Poster
Rep: Reputation: 15
Thanks, I'll give them a try.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SCSI error&External USB Storage Device kennithwang Linux - Kernel 12 08-23-2007 07:40 AM
external usb storage device not detected tokehs Linux - Hardware 4 10-27-2006 12:08 PM
External storage for Linux/Windows: Samba or USB 2.0 attached Hard Drive? SparceMatrix Linux - Hardware 1 02-04-2005 02:33 PM
External USB Mass Storage (ALI Chipset) Jimbo99 Linux - Hardware 3 05-12-2004 10:42 AM
External USB Mass storage ALI chipset based Jimbo99 Linux - Software 1 04-21-2004 11:09 AM > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 09:42 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration