Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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....
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.
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:
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.
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.
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.
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.
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 ?
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.
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.
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.