Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Managing various removable FAT drives

0 views
Skip to first unread message

Stephen Cornell

unread,
Sep 11, 2003, 11:30:41 AM9/11/03
to
I have two removable USB drives, a camera and a key drive, which need
to be formatted as DOS filesystems for compatibility purposes. The
physical devices (/dev/sd*) to which they correspond depends upon the
order in which they are attached after boot time, which means that in
order to mount them I have to be root and root around in the system
logs. Ideally, I'd like to add a line to /etc/fstab so I can mount
them straightforwardly and as a normal user.

A solution would apparently be offered by the -L and -U options to the
mount command, which allow one to mount a device by volume label or
UUID rather than by physical device. I already use this for another
USB hard disk, which is formatted as ext3. However, the -L option
doesn't seem to work with my DOS disks. Using Windows, I added a
volume label MJU300 to the disk device corresponding to my digital
camera, but if I try

% mount -t vfat -L MJU300 /mnt/camera

I get the error message

mount: no such partition not found

The same error message occurs if I have a line in /etc/fstab of the form:

LABEL=MJU300 /mnt/camera vfat noauto 0 0

and try " mount /mnt/camera "

Does anyone know whether this `should' work? If not, should I be able
to use the -U option instead, and if so how do I go about finding the
UUID for a DOS partition? The man page for mount suggests that this
information should be found in /proc/partitions, but as a non-expert I
can't interpret this file. This is Red Hat 7.2 with a 2.4.20-*
kernel.
--
Stephen Cornell cor...@zoo.cam.ac.uk Tel/fax +44-1223-336644
University of Cambridge, Zoology Department, Downing Street, CAMBRIDGE CB2 3EJ

Dances With Crows

unread,
Sep 11, 2003, 2:29:02 PM9/11/03
to
On 11 Sep 2003 16:30:41 +0100, Stephen Cornell staggered into the Black

Sun and said:
> I have two removable USB drives, a camera and a key drive, which need
> to be formatted as DOS filesystems for compatibility purposes. The
> physical devices (/dev/sd*) to which they correspond depends upon the
> order in which they are attached after boot time, which means that in
> order to mount them I have to be root and root around in the system
> logs. Ideally, I'd like to add a line to /etc/fstab so I can mount
> them straightforwardly and as a normal user.

Yah, like so:

# in /etc/fstab
/dev/sda1 /mnt/drive1 vfat noauto,user,umask=000 0 0
/dev/sdb1 /mnt/drive2 vfat noauto,user,umask=000 0 0
# end /etc/fstab thing

...first drive you plug in is drive1, second is drive2. A little
hackish, but it works--I use something similar to manage multiple PCMCIA
CF and SmartMedia adapters.

> A solution would apparently be offered by the -L and -U options to the

> mount command, However, the -L option doesn't seem to work with my DOS


> disks. Using Windows, I added a volume label MJU300 to the disk
> device corresponding to my digital camera, but if I try

The -L option is, AFAICT, only for ext[23] and XFS. Only those
filesystems have support for labels in mount.

> % mount -t vfat -L MJU300 /mnt/camera

> mount: no such partition not found
>

> LABEL=MJU300 /mnt/camera vfat noauto 0 0

Using LABEL= instead of device nodes isn't really advisable for various
reasons, as some folks found out when they tried to put 2 separate
installs of Redhat 8 on some systems.

> Does anyone know whether this `should' work?

I don't think it will. It sounds like it'd be a neat feature, though.
The location of the volume label on a FAT filesystem won't change
(backwards combatability) so it might be possible to add this to mount.

> to use the -U option instead, and if so how do I go about finding the
> UUID for a DOS partition?

FAT filesystems don't have UUIDs. Only ext[23], ReiserFS, and maybe XFS
do.

> The man page for mount suggests that this information should be found
> in /proc/partitions,

Funny, neither UUID nor label is displayed in my /proc/partitions files.
Finding the UUID or label on ext[23] filesystems involves "dumpe2fs -h
/dev/NNN". Don't know for sure about ReiserFS, but maybe "debugreiserfs
/dev/NNN" would tell you those things for Reiser.

--
Matt G|There is no Darkness in Eternity/But only Light too dim for us to see
Brainbench MVP for Linux Admin /
http://www.brainbench.com / "He is a rhythmic movement of the
-----------------------------/ penguins, is Tux." --MegaHAL

Stephen Cornell

unread,
Sep 12, 2003, 6:26:59 AM9/12/03
to
Dances With Crows <dancesw...@usa.net> writes:

> On 11 Sep 2003 16:30:41 +0100, Stephen Cornell staggered into the Black
> Sun and said:
> > I have two removable USB drives

> > [...] Ideally, I'd like to add a line to /etc/fstab so I can mount


> > them straightforwardly and as a normal user.
>

> # in /etc/fstab
> /dev/sda1 /mnt/drive1 vfat noauto,user,umask=000 0 0
> /dev/sdb1 /mnt/drive2 vfat noauto,user,umask=000 0 0
> # end /etc/fstab thing
>
> ...first drive you plug in is drive1, second is drive2.

Thanks for the reply. This unfortunately still needs some user
intervention, whereas I was looking for a no-brainer user experience
(e.g. select the menu option `Digital camera', and it mounts the
device and opens an image viewer in the correct directory; exit the
viewer and the device is unmounted). Things get still more
complicated as I have other USB drives that I want to be handled
differently (different filesystems, not user-mountable). I suppose
this can be achieved by more hackery, though.

> Using LABEL= instead of device nodes isn't really advisable for various
> reasons, as some folks found out when they tried to put 2 separate
> installs of Redhat 8 on some systems.

Well, in some circumstances it's a good thing that LABEL can refer to
two different physical drives, provided you're careful not to attach
the two at the same time. I use this for backup drives.

> The location of the volume label on a FAT filesystem won't change
> (backwards combatability) so it might be possible to add this to mount.

Yes, and some Linux tools (e.g. mkdosfs) already access the volume
label, so it's bizarre that this label can't actually be used for
anything.

Dances With Crows

unread,
Sep 12, 2003, 7:20:40 PM9/12/03
to
On 12 Sep 2003 11:26:59 +0100, Stephen Cornell staggered into the Black

Sun and said:
> Dances With Crows <dancesw...@usa.net> writes:
>> On 11 Sep 2003 16:30:41 +0100, Stephen Cornell staggered into the
>> Black Sun and said:
>> > I have two removable USB drives
>> > [...] Ideally, I'd like to add a line to /etc/fstab so I can mount
>> > them straightforwardly and as a normal user.
>>
>> # in /etc/fstab
>> /dev/sda1 /mnt/drive1 vfat noauto,user,umask=000 0 0
>> /dev/sdb1 /mnt/drive2 vfat noauto,user,umask=000 0 0
>> # end /etc/fstab thing
>>
>> ...first drive you plug in is drive1, second is drive2.
>
> Thanks for the reply. This unfortunately still needs some user
> intervention, whereas I was looking for a no-brainer user experience
> (e.g. select the menu option `Digital camera', and it mounts the
> device and opens an image viewer in the correct directory; exit the
> viewer and the device is unmounted). Things get still more
> complicated as I have other USB drives that I want to be handled
> differently (different filesystems, not user-mountable). I suppose
> this can be achieved by more hackery, though.

Ah... found it. http://www.lerhaupt.com/devlabel/devlabel.html may
provide a solution to your problem. The author says it'll work for
things which don't have filesystems , like swap partitions(!) , so a
FAT32 partition should work OK.

>> Using LABEL= instead of device nodes isn't really advisable for
>> various reasons, as some folks found out when they tried to put 2
>> separate installs of Redhat 8 on some systems.
> Well, in some circumstances it's a good thing that LABEL can refer to
> two different physical drives, provided you're careful not to attach
> the two at the same time.

The people who did this didn't make sure that was the case, so chaos
ensued. You can use UUID= instead of LABEL= in fstab, which would be a
far better idea in terms of robustness... but it's less friendly.
(Anyone mucking with fstab directly instead of using Redhat's
pointy-clicky tools should be able to learn what a UUID is and how to
fiddle with it, but maybe that's asking too much.)

>> The location of the volume label on a FAT filesystem won't change
>> (backwards combatability) so it might be possible to add this to mount.
> Yes, and some Linux tools (e.g. mkdosfs) already access the volume
> label, so it's bizarre that this label can't actually be used for
> anything.

Hmm. I'm looking at the code for mount in the util-linux package, and I
think it'd be almost trivially easy--so easy *I* could do it! I'm going
to try something; if it works, I'll see about contacting the maintainer.
Thanks for bringing this to my attention; I've been helping people out
with Linux on Usenet since ~2000, and now I may have a chance to
contribute some actual code....

Dances With Crows

unread,
Sep 19, 2003, 9:46:35 PM9/19/03
to
On 12 Sep 2003 23:20:40 GMT, Dances With Crows staggered into the Black
Sun and said:

Oog. Sorry about the delay; fecal matter has been impacting rotating
bladed objects at work and stuff, and fun/useful things like this have
suffered....

> On 12 Sep 2003 11:26:59 +0100, Stephen Cornell staggered into the
> Black Sun and said:
>> Dances With Crows <dancesw...@usa.net> writes:
>>> On 11 Sep 2003 16:30:41 +0100, Stephen Cornell staggered into the
>>> Black Sun and said:
>>> > I have two removable USB drives
>>> > [...] Ideally, I'd like to add a line to /etc/fstab so I can mount
>>> > them straightforwardly and as a normal user.
>>>
>>> # in /etc/fstab
>>> /dev/sda1 /mnt/drive1 vfat noauto,user,umask=000 0 0
>>> /dev/sdb1 /mnt/drive2 vfat noauto,user,umask=000 0 0
>>

>> Thanks for the reply. This unfortunately still needs some user
>> intervention, whereas I was looking for a no-brainer user experience

> Ah... found it. http://www.lerhaupt.com/devlabel/devlabel.html may
> provide a solution to your problem.

How'd that work?

>>> The location of the volume label on a FAT filesystem won't change
>>> (backwards combatability) so it might be possible to add this to
>>> mount.
>> Yes, and some Linux tools (e.g. mkdosfs) already access the volume
>> label,

> Hmm. I'm looking at the code for mount in the util-linux package, and
> I think it'd be almost trivially easy

...not quite as easy as I thought, mostly because of trying to write
code when tired. But I've got an ugly little thing in get_label_uuid.c
that does extract the right thing for the volume label that mkdosfs
writes for a FAT32 filesystem from a FAT superblock, etcetera. The
problem is that there are 2 volume labels in a FAT superblock. One is
apparently only used for FAT16 filesystems, but who knows how things
work in the real world? Oh well... holler at my E-mail if you want the
code; I'm going to ping the maintainer of util-linux and see what he has
to say....

Stephen Cornell

unread,
Sep 22, 2003, 7:37:35 AM9/22/03
to
Sorry, I meant to post a follow-up to your message last week but I was
also pretty busy...


Dances With Crows <dancesw...@usa.net> writes:
> On 12 Sep 2003 23:20:40 GMT, Dances With Crows staggered into the Black
> Sun and said:
> > Ah... found it. http://www.lerhaupt.com/devlabel/devlabel.html may
> > provide a solution to your problem.
>
> How'd that work?

I had a look at that, and it does indeed address my problem. However,
I didn't pursue it, as I try to restrict the provenance of programs I
run as root.

Instead, I hacked a script [see end] that reads /proc/scsi/*, tries to
figure out which device is attached to which /dev/sd*, mounts it, and
creates a user-friendly link. It's not guaranteed to work on another
computer, because I haven't been careful about how the USB devices are
mapped onto SCSI device names. The script is called as " usbmount
[mount,umount] [camera,key] ", and I have desktop menu entries that
run "usbmount mount camera ; gqview ~/camera ; usbmount umount camera"
etc.

This script can be run as user, because I have generic entries in
/etc/fstab as you mentioned. This doesn't compromise the security of
my ext3 USB drives, because their entries refer to their LABEL, and as
they do not have a FAT filesystem the user will be unable to mount
them.

> > Hmm. I'm looking at the code for mount in the util-linux package, and
> > I think it'd be almost trivially easy
>

> [...]


> work in the real world? Oh well... holler at my E-mail if you want the
> code; I'm going to ping the maintainer of util-linux and see what he has
> to say....

Thanks for addressing such a useful issue. Good luck getting your
code accepted!

The script:


#!/bin/bash
case "$2" in
camera)
VENDOR=OLYMPUS
;;
key)
VENDOR=LEXR
;;
*)
exit 1
esac

for i in /proc/scsi/usb-storage-*
do cd $i
for j in *
do k=`cat $j | grep -c $VENDOR`
if [ x$k != x0 ]; then
l=$j
fi
done
done

DRIVE=/mnt/drive$l
case "$1" in
mount)
mount $DRIVE
ln -s $DRIVE $HOME/$2
;;
umount)
rm $HOME/$2
umount $DRIVE
;;
*)
exit 1
esac

0 new messages