LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-19-2006, 08:44 AM   #1
ctkroeker
Senior Member
 
Registered: May 2005
Posts: 1,565
Blog Entries: 1

Rep: Reputation: 50
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....

Last edited by ctkroeker; 12-19-2006 at 08:59 AM.
 
Old 12-19-2006, 08:48 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
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.
 
Old 12-19-2006, 09:18 AM   #3
ctkroeker
Senior Member
 
Registered: May 2005
Posts: 1,565

Original Poster
Blog Entries: 1

Rep: Reputation: 50
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.

Last edited by ctkroeker; 12-19-2006 at 03:49 PM.
 
Old 12-28-2006, 01:39 AM   #4
sciphre
LQ Newbie
 
Registered: Oct 2005
Posts: 2

Rep: Reputation: 0
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.
 
Old 12-28-2006, 06:02 AM   #5
Tortanick
Member
 
Registered: Jul 2006
Distribution: Debian Testing
Posts: 299

Rep: Reputation: 30
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?
 
Old 12-28-2006, 08:39 PM   #6
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Mint, Ubuntu server, FreeBSD, Android
Posts: 362

Rep: Reputation: 32
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"

Last edited by Kropotkin; 12-28-2006 at 08:41 PM.
 
Old 01-05-2007, 01:36 PM   #7
rm windows
LQ Newbie
 
Registered: Jan 2007
Distribution: fedora 4/5/6, rhel, suse, ubuntu
Posts: 1

Rep: Reputation: 0
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.
 
Old 01-07-2007, 03:43 AM   #8
Jongi
Senior Member
 
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070

Rep: Reputation: 45
This thread has been very helpful
 
Old 01-16-2007, 12:14 PM   #9
sciphre
LQ Newbie
 
Registered: Oct 2005
Posts: 2

Rep: Reputation: 0
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}"

Last edited by sciphre; 01-16-2007 at 12:18 PM.
 
Old 03-04-2007, 07:42 AM   #10
cheesus
Member
 
Registered: Jan 2005
Location: Munich, Germany
Distribution: SuSE
Posts: 186

Rep: Reputation: 25
Thumbs up 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.
 
Old 03-04-2007, 08:06 AM   #11
cheesus
Member
 
Registered: Jan 2005
Location: Munich, Germany
Distribution: SuSE
Posts: 186

Rep: Reputation: 25
Wink 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.
 
Old 05-28-2008, 04:20 PM   #12
klas_w
LQ Newbie
 
Registered: May 2008
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by cheesus View Post
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.
 
Old 04-20-2009, 03:30 AM   #13
alexcohn
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
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?
 
Old 08-11-2009, 08:49 AM   #14
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Mint, Ubuntu server, FreeBSD, Android
Posts: 362

Rep: Reputation: 32
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
 
  


Reply

Tags
device, drive, fstab, hard, hdd, name, permanent, removable, udev, usb



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to give not-root user ability to mount devices to any mount point??? jdupre Linux - General 8 02-04-2012 10:03 AM
removable (usb-)devices mount points zlin50 Slackware 6 05-29-2006 04:34 PM
Where to find mount point for USB Removable device bobbelfield Mandriva 3 02-17-2006 10:37 PM
make hdc the mount point for dvdd again? verbose Linux - Hardware 6 01-02-2006 01:49 PM
would it make sense to have 2 mount point for 1 device? sirpelidor Linux - Hardware 3 12-27-2003 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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