LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Make removable USB hdd mount at fixed mount point (http://www.linuxquestions.org/questions/linux-general-1/make-removable-usb-hdd-mount-at-fixed-mount-point-511917/)

ctkroeker 12-19-2006 08:44 AM

Make removable USB hdd mount at fixed mount point
 
My friend sent me the following email. I agreed to help him but know nothing on this subject.

I have several removable USB hard drives that I use for backups. When I connect a drive, sometimes Ubuntu acknowledges it as /dev/sdb1, other times /dev/sdc1, sometimes /dev/sdd1. Of course my /etc/fstab can only have one entry that points to the filesystem mount point /media/usbhdd, so when the rsync backup script tries to mount the /etc/fstab-specified /dev/sdb1, for example, but it's not there, the whole backup script fails. Ideas on how to fix this? I'm thinking it has something to do w/ udev rules....

b0uncer 12-19-2006 08:48 AM

Yes, udev should know which drive should be mapped at which point. I'm not deeply familiar with udev rules, but have you already tried looking for udev rules how-tos from the web?

A small correction: you can have several entries in fstab that are pointing to the same mountpoint, or at least I'm pretty confident you could have. No idea what happens if you try to mount /mnt/mountpoint (for example), but since you can mount (manually) several devices into one directory (or at least Linux used to let you do that), I see no reason why fstab would prevent you from doing that. Logically thought it should mount every listed device, if available, to that place, but Linux programs don't always work logically..only usually.

ctkroeker 12-19-2006 09:18 AM

For those of you who might need help with this same problem, here is the fix.
When a removable USB device is plugged in/out of a Linux box, there's no telling if Linux will assign that piece of hardware the same ID (ie. /dev/sdc1) each time. This of course wreaks havoc when trying to write an rsync backup script that starts by mounting the removable drive. Here's how to ensure that multiple *identical* removable hdd's can all get mounted and used.
Read this site: http://reactivated.net/writing_udev_rules.html
create the following new file:
nano /etc/udev/rules.d/10-local.rules
Code:

## gk - Persistent name for removable USB hdd's used for backup
BUS=="usb", KERNEL=="sd?1", SYSFS{manufacturer}=="Prolific Technology Inc.", NAME="%k", SYMLINK+="usbhdd1"

note the SYSFS{manufacturer} data comes from this command (while the drive is connected but not mounted on the server):
Code:

udevinfo -a -p $(udevinfo -q path -n /dev/sdc)
once the rule is created, disconnect, then reconnect the removable device so udev re-reads it's ruleset. Now there should be a new symlink, /dev/usbhdd%n, that points to the actual device file, in this case, /dev/sdc1.
modify /etc/fstab so you can mount /dev/usbhdd1 at /media/usbhdd:
nano /etc/fstab and add the following:
Code:

/dev/usbhdd1 /media/usbhdd ext3 rw,user,noauto 0 0
try to mount the device explicitly:
mkdir /media/usbhdd
mount /media/usbhdd
ls -l /media/usbhdd
umount /media/usbhdd


Hope this works for you.

sciphre 12-28-2006 01:39 AM

A simpler way is to use UUID or LABEL mounting.
I'm not sure who provides these, probably udev, but they're available by default in ubuntu 6.06

In /dev/disks (or /dev/disk, not certain atm) you have three directories called by-uuid, by-label and by-id, these contain adequate symlinks to your devices, hotplugged or not.

Using this method, you don't need to hack any config files. If you use UUID they get lost when you mkfs, if you use LABEL you have to assign the labels by hand after a mkfs, and if you use ID you could have device "conflicts" if you have two identical drives - but this would happen with the udev hack too.

Tortanick 12-28-2006 06:02 AM

Nice tip, but on my debian etch I have by-path rather than by-label, just wanted to know what by-path is and if I could get by label if I wanted?

Kropotkin 12-28-2006 08:39 PM

Quote:

Originally Posted by sciphre
and if you use ID you could have device "conflicts" if you have two identical drives - but this would happen with the udev hack too.

Well, if you have two identical drives, as I do, you can also use the serial number to disambiguate between the two, like this:

Code:

BUS=="usb", SYSFS{serial}=="10000E000CC6F65C", NAME="%k", SYMLINK="usbdisk1"
BUS=="usb", SYSFS{serial}=="10000E000CB94AA4", NAME="%k", SYMLINK="usbdisk2"


rm windows 01-05-2007 01:36 PM

I tried setting up a udev rule and it worked like a charm. Many thanks for that. Has anyone worked much with lvm? I have two external HDDs that I just set up rules for, but now I need lvm to reference those symlinks instead of what they were referencing. (sda1, sda2) I don't know if there is a simple text file I can edit or an lvm command that I can run to change that. I'm running fedora 5.
any help would be greatly appreciated.

Jongi 01-07-2007 03:43 AM

This thread has been very helpful

sciphre 01-16-2007 12:14 PM

Well, I can't be arsed to grok the rules, but this is how Ubuntu 6.10 Edgy does /dev/disk/by-label .
Note that this is only the part dealing directly with by-label, there's a lot more of this file.

/etc/udev/rules.d/65-persistent-storage.rules
Code:

# by-label/by-uuid (filesystem properties)
KERNEL=="*[!0-9]", SYSFS{removable}=="1", GOTO="persistent_storage_end"
IMPORT{program}="vol_id --export $tempnode"
ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_UUID}=="?*", SYMLINK+="disk/by-u
uid/$env{ID_FS_UUID}"
ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_SAFE}=="?*", SYMLINK+="dis
k/by-label/$env{ID_FS_LABEL_SAFE}"


cheesus 03-04-2007 07:42 AM

openSuSE 10.2
 
This looks a lot different in SuSE 10.2, but still works if you cut'n paste the output of udevinfo really good :-)

Code:

ATTR{size}=="488359872", SUBSYSTEMS=="scsi", ATTRS{vendor}=="WDC WD25", SYMLINK+="usb_keeper"
ATTR{size}=="625121217", SUBSYSTEMS=="scsi", ATTRS{vendor}=="ST332082", SYMLINK+="usb_void"

A clarification for the hastly reader (like me) the SYMLINK does not mean
the mount point (as in /media/disk etc) but really is a symlink to
the "physical" device node under dev.

This thread helped a lot, thanks,
Tom.

cheesus 03-04-2007 08:06 AM

noauto
 
One more question though.

I need to give "noauto" or else I might have problems booting when
the usb drive is not plugged in.
But since I have that fstab entry, the device is no longer automatically
mounted when plugged in. That is no big deal, but it was a nice
feature to just "plug and play".

Does anyone know how to preserve that behaviour and not risk hanging at boot time ?

Thanks, Tom.

klas_w 05-28-2008 04:20 PM

Quote:

Originally Posted by cheesus (Post 2655687)
One more question though.

I need to give "noauto" or else I might have problems booting when
the usb drive is not plugged in.
But since I have that fstab entry, the device is no longer automatically
mounted when plugged in. That is no big deal, but it was a nice
feature to just "plug and play".

Does anyone know how to preserve that behaviour and not risk hanging at boot time ?

Thanks, Tom.

I think you should only need to give the filesytem in fstab and then you can have auto at the <options> line.

<file system> <mount point> <type> <options> <dump> <pass>

/dev/usbhdd1 /media/usb_backup ext3 rw,noexec,nosuid,user,auto 0 0

In my configuration of /etc/udev/rules.d/10-local.rules in Debian I have both manufacture and the serial. It looks like this:

BUS=="usb", KERNEL=="sd?1", ATTRS{manufacturer}=="Prolific Technology Inc.", ATTRS{serial}=="0", NAME="%k", SYMLINK="usbhdd1"

I have also removed the (+) before ="usbhdd1" Hope this helped somone.

alexcohn 04-20-2009 03:30 AM

followup question: /dev/sdu
 
The techniques revieled in this discussion allow to define "extra" mount points for a USB disk. My system, based on VmWare Ubuntu, is different in that I sometimes have two, and sometimes four "fixed" disks. I would like to have the USB device mounted not sometimes as /dev/sdc and sometimes as /dev/sde, but always as /dev/sdu.

Is this possible at all?

Kropotkin 08-11-2009 08:49 AM

udevinfo deprecated; use udevadm to determine serial nr (etc.)
 
Hi all,

Just now I needed to add a UDEV rule to my 09-local.rules file, and I found to my dismay that the instructions above no longer appear to work. udevinfo has been replaced by udevadm. Unfortunately, the syntax of the latter is obtuse to put it mildly, but this works:
Code:

udevadm info -a -p $(udevadm info -q path -n /dev/sdf) | grep ATTRS{serial}
where /dev/sdf is the USB drive relevant to your situation.

If more than two serial numbers are displayed, run this:
Code:

udevadm info -a -p $(udevadm info -q path -n /dev/sdf) | grep ATTRS{product}
to determine which pertains to which.

The UDEV rules remain the same. In my case, this line the local rules file serves to mount an external USB harddrive at /media/usbdisk1:
Code:

BUS=="usb", ATTRS{serial}=="DCA1280989FF", NAME="%k", SYMLINK="usbdisk1"
I found the above information on a page in the Arch Linux wiki, where there is more detailed info if you want to dig further. There is also a script, which doesn't work in my case.

HTH


All times are GMT -5. The time now is 05:23 AM.