automounting USB drives

Place to discuss Fedora and/or Red Hat
Post Reply
User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

automounting USB drives

Post by Calum » Mon Sep 10, 2007 1:59 am

hi! Fedora 6.

Okay, so i have more than one external usb storage device. In particular there's a TEAC floppy drive and a 40GB external hard drive, that are going to always be plugged in, and there are the camera and USB stick which will be ocassionally plugged in. My question is, how can i get the hard drive and floppy drive to always mount on the same mount locations? fedora is doing this via something, hal? something other than just sticking it into the fstab anyway. Any pointers towards a nice easy howto i can read to get to grips with this?

thanks.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Sep 10, 2007 8:19 am

On my USB hard drive I have it labeled (ext3 file system with label). It always mounts under /media/labelname. I'm pretty sure it does it with labels on other file system types as well. I thought my floppy drive mounts under /media/floppy. Yours is different?

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Fri Sep 14, 2007 8:31 am

yes i have a feeling i had had some problems with the convention of using labels and so i think i habitually replace label names with device names in fstab, ever since. Also, my real floppy drive was buggered a long time ago so i had removed it and am now using an external TEAC floppy drive for an IBM T40 series laptop instead. As a USB device i don't think it has a label.

But can i use this label thing with removable USB devices or will they have to be plugged in the whole time for it to stay consistent? that's not really a probelm too much, just wondering. will have to run away and read about labeling drives really.

thanks for the pointer!

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Fri Sep 14, 2007 11:23 am

I'm talking about the automount stuff that automatically mounts under /media. In this case you don't add anything to the /etc/fstab. It should mount the device under /media/filesystemlabel. If you don't have a label on the file system it will mount it with it's partition name. My USB hard drive has two partitions. One is ext3 with a label of "/backup" and the other is a FAT32 file system with a label of "fat" and when I plug it in it automatically mounts the /backup file system under /media/backup and the FAT32 file system under /media/fat. Manually mounting (/etc/fstab) is completely separate.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Wed Sep 19, 2007 10:17 am

so... what do i do then?

my usb hdd appears to mount as /media/disk except when the USB fdd is also plugged in. If both are plugged in at bootup time, then the hdd gets mounted as /media/disk-1 while the fdd is /media/disk however if i wait till the hdd mounts as /media/disk then plug in the fdd then it mounts as /media/disk-1

to be honest i wouldn't mind if we could just go back to the good old days of /mnt/floppy but the automounting situation seems a lot better nowadays than back then and i'm frightened in case i break it if i change too much!

so what do you reckon? i really want the hdd to be /media/disk the whole time and i also want to have the peace of mind (if possible) of knowing i can plug the drives into different ports and not have to worry they'll all get remounted wrongly, not sure if this is an issue, but thought i should mention it.

by the way i have at least one usb ram stick too that i will occasionally want to plug in in the hope it won't mess anything up too.

Tux
guru
guru
Posts: 689
Joined: Wed Jan 08, 2003 10:40 am

Post by Tux » Wed Sep 19, 2007 12:09 pm

What desktop environment do you use?
I know in KDE, for example that you can right click on the icon of an automount device navigate to properties and set a persistent mount location, permissions etc.


If you don't then you need to delve into the udev mount rules yourself.
This tutorial sets you in the right track but you have to use your common, as always.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Wed Sep 19, 2007 4:54 pm

So setting the label on the file system on your hard drive did not work? Maybe that's new in Fedora 7. It seems like forever ago since I've run Fedora 6. :) What file system is on that partition and what is the label set to?

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Thu Sep 20, 2007 4:26 am

okay. thanks for the replies.

I haven't actually done anything yet. i hadn't got round to taking any action, and then saw your reply void main, and thought i might as well reply too.

So, i need to set a label for each volume, and specify a mountpoint based on the labels? I can look that up i am sure.

re: the volumes, the USB HDD is currently one partition of vfat but i am thinking of changing it to be ext3 (again one partition). Would that change require relabeling and so on, assuming i do the reformat to ext3 after i sort out the mounting? I imagine so.

Re: desktop environment, i use gnome, and don't have KDE installed, and don't really want to, i don't think i have space for it! I also have xfce installed, and prefer its components to gnome's. I really don't like fiddling with mounting and things within the desktop environment though because in my opinion it's not a UI issue, it is an admin/config issue. Also, things set up within a UI are usually user specific, no? I really don't like using graphical tools as root, not for any real reason, i just feel like it's "wrong".

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Thu Sep 20, 2007 10:35 am

The label is part of the file system so if you create a new file system you would have to label it. To do this with ext2/ext3 you would use the "e2label" command (or tune2fs). For a FAT file system you would use "dosfslabel", ntfs = ntfslabel (assuming you have the proper packages installed).

Now, what I was referring to before about mounting automatically under /media/labelname was in the case of plugging a USB drive in while your system is already up and you are logged in. I see now that you want this to work at boot time. I "believe" all you should have to do is add /etc/fstab entries using the "LABEL=labelname" syntax. I will test this tonight to make sure.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Thu Sep 20, 2007 9:22 pm

Ok, I had a chance to test this and was able to do what I had suggested (although on F7 and not FC6). Here's what I have:

- External 250GB USB hard drive with 2 ext3 partitions
- External USB floppy with vfat floppy disk

Now, without adding anything to /etc/fstab if I plug these in while booted and logged in the combination of hal and the desktop environment will detect they were plugged in and automatically mount them under /media/labelname. If the file system does not have a label I believe it mounts them as disk, disk-1, disk-2 etc as you mention. So I create the labels:

# e2label /dev/sdb1 hdpart1
# e2label /dev/sdb2 hdpart2
# dosfslabel /dev/sdc floppy

Now if I plug them in they get mounted as /media/hdpart1, /media/hdpart2, and /media/floppy. I realize that you want to have them automatically mounted at boot time so I added this to my /etc/fstab:

Code: Select all

LABEL=hdpart1            /mnt/hdpart1             ext3    defaults        1 2
LABEL=hdpart2            /mnt/hdpart2             ext3    defaults        1 2
LABEL=floppy             /mnt/floppy              vfat    defaults        1 2
and created my mount points:

# mkdir /mnt/hdpart1
# mkdir /mnt/hdpart2
# mkdir /mnt/floppy

Now I rebooted but they didn't get automatically mounted. I realized that the usb modules didn't get loaded since they were plugged in before the system was booted. So, I just added a /etc/sysconfig/modules/usb.modules script containing this:

Code: Select all

#!/bin/sh
modprobe usb_storage
Don't forget to make it executable (chmod +x /etc/sysconfig/modules/usb.modules). Now when I reboot the partitions are mounted exactly where I want them without specifying what the underlying device name is (/dev/sdb1, /dev/sdc, etc). Again, this is F7 and not FC6 so I can't say for sure that this works the same way on FC6. I also am not sure if adding the /etc/sysconfig/modules/usb.modules script is the best way to load the usb module at boot, just the first thing that came to mind.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Fri Sep 21, 2007 6:33 am

hi void! thanks for going to so much effort for this! that's actually all stuff i should have been able to figure out myself.

i used to have to add several modprobe lines to the startup scripts with slack, including usb-storage. So, should the module be usb-storage or usb_storage? i remember it being usb-storage but you typed usb_storage, and google seems to mention both(!)

Also, if this isn't getting loaded early enough, how come it does get loaded in time for hotplugging usb devices in? i suppose this must be part of the job of the hal automounting stuff.

re: the best place to modprobe, i would put it in one of the startup scripts in slack under /etc/rc.d/ (if my patchy memory serves it would have been in rc.modules, i think?) but i usually find that when i look for startup scripts on fedora they don't exist where i expect them. i expect what you said to do is the "right" thing for fedora.

so , label the volumes, edit fstab and modprobe usb_storage in the init scripts, got it! thanks again!

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Fri Sep 21, 2007 7:56 am

Calum wrote:i used to have to add several modprobe lines to the startup scripts with slack, including usb-storage. So, should the module be usb-storage or usb_storage? i remember it being usb-storage but you typed usb_storage, and google seems to mention both(!)
Actually it works either way (like magic).
Also, if this isn't getting loaded early enough, how come it does get loaded in time for hotplugging usb devices in? i suppose this must be part of the job of the hal automounting stuff.
That very same question came across my mind and I suspect the same as you (that hal detects a device getting plugged in after boot and loads the appropriate modules).
re: the best place to modprobe, i would put it in one of the startup scripts in slack under /etc/rc.d/ (if my patchy memory serves it would have been in rc.modules, i think?) but i usually find that when i look for startup scripts on fedora they don't exist where i expect them. i expect what you said to do is the "right" thing for fedora.
I believe /etc/rc.d/rc.modules would also have worked. It seems that /etc/sysconfig/modules is the Fedora preferred way though and it might even be an LSB method as far as I know.
so , label the volumes, edit fstab and modprobe usb_storage in the init scripts, got it! thanks again!
That *should* do it but as I said, I no longer have access to an FC6 system at home to test on but I think it should work.

Post Reply