LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Permanently labeling an external USB storage drive (https://www.linuxquestions.org/questions/linux-hardware-18/permanently-labeling-an-external-usb-storage-drive-588986/)

apachenew 10-02-2007 06:06 PM

Permanently labeling an external USB storage drive
 
Hello,

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?

jschiwal 10-02-2007 06:45 PM

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
Code:

udevinfo -q env -n /dev/sdb1
ID_VENDOR=SanDisk
ID_MODEL=Cruzer_Mini
ID_REVISION=0.1
ID_SERIAL=SanDisk_Cruzer_Mini_200517395007FC20132F
ID_TYPE=disk
ID_BUS=usb
ID_PATH=pci-0000:00:02.1-usb-0:1.2:1.0-scsi-0:0:0:0
ID_FS_USAGE=filesystem
ID_FS_TYPE=vfat
ID_FS_VERSION=FAT16
ID_FS_UUID=3B69-1AFD
[/b]ID_FS_LABEL=CRUZERMINI2[/b]
ID_FS_LABEL_SAFE=CRUZERMINI2

Install the "mtools" package if you have it. This package supplies the "mlabel" package. Add the following line to
/etc/mtools.conf:
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:
Code:

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:
Code:

/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:
Code:

LABEL=XMAS /media/XMAS  vfat rw,nosuid,nodev,noatime,flush,uid=jschiwal,fmask=117,dmask=007,utf8,shortname=lower

syg00 10-02-2007 07:13 PM

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.

apachenew 10-10-2007 10:53 AM

Thanks, I'll give them a try.


All times are GMT -5. The time now is 06:52 PM.