Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mounting a specified USB drive to a specific folder 3

Status
Not open for further replies.

meekrob

MIS
Feb 13, 2002
127
US
The Situation:

I have a rsync set to back up to a couple of usb hard drives. The backup of one server goes to a certain usb drive, let's call it "Backup A" and "Drive A". There is a second backup, "Backup B" that saves to "Drive B". The backups are incremental, so it is imperative that they continue to use the same drives. The OS is CentOS 4.2.

The Problem:

Drive B is unplugged and plugged in frequently. It is difficult to predict where it will mount. Sometimes it is /media/usbdisk1, sometimes usbdisk2. I need to be able to consistently mount the same disk to the same folder. Does anyone have a solution?
 
I would say that you could use a perl or batch script to do this (though I dont know all the quirks of these):

- placing a unique file on the drive
- running a mount script that mounts it, looks for the file and remounts it elsewhere if necessary.

Robert Carpenter
Remember....eternity is much longer than this ~80 years we will spend roaming this earth.
ô¿ô
 
Thanks Robert,

That's an option, if it's my only I'll do it. Does anyone else have any ideas?
 
The good news is that there are lots of ways to do this. The bad news is that they all require a fair degree of knowledge, manual configuration, and quite possibly some non-trivial shell scripting.

As a preliminary, you may want to add a static device symlink for that drive, so that it's always /dev/drive_a. Otherwise, you'll be stuck with the kernel device names which are based on the order in which drives are attached. At the very least, adding a static symlink will allow you to manually mount the device without having to look up the name every time.

You add a symlink for a device by adding a rule to a file under the /etc/udev/rules.d directory. You will need to get the info for that device by running the udevinfo command on the appropriate file under /sys. Here's an example of this from when I was configuring autofs on my PC (about 7 paragraphs down). Whether you use a static symlink or not, you'll want to be familiar with udevinfo.

One (relatively) simple method for automounting is to write a udev script. Here's an example I did last year. With the advent of HAL, this is no longer the preferred method, but it still works. However, when writing the script you have to remember that it will be run for all block devices and code it accordingly.

The recommended method these days is to use a HAL volume manager. GNOME and KDE both have built-in volume managers, but these are somewhat limited in terms of configurability. You might consider installing ivman instead. It allows you to write match rules for HAL events. In other words, you could write a rule that matches the serial number on this drive and execute an arbitrary command when it is inserted.
 
Linux has a HAL now?

Anyway that was a great post! Thanks, I've been looking for this information for a long time.
 
meekrob said:
Linux has a HAL now?
Yup. You can read about it here. It's relatively new (depends on kernel 2.6.15), but it's been embraced by most of the major distributors and the two main desktops. So far it seems to be used mostly for removable media, but hopefully support will spread to all forms of devices.
 
I don't know about CentOS but on my Ubuntu and Gentoo machines I simply used fdisk to label my USB drives and then reference them in the /etc/fstab like this....

LABEL=/Data /local/Data ext2 defaults 0 0
LABEL=/Data-2 /local/Data-2 ext2 defaults 0 0
LABEL=/Data-3 /local/Data-3 ext2 defaults 0 0

They always mount on the correct mountpoint for me.

Gwen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top