Auto mount USB drive to specified mount point after reboot
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Auto mount USB drive to specified mount point after reboot
I have servers installed with RHEL 4 2.6.9-89.0.9 ELsmp. I tried using uuid and label in /etc/fstab to automount usb drives to mountpoints that I specify after reboot. Unfortunately, it just does not work in all my RHEL4 servers. After every reboot, /etc/fstab will be automatically modified and all configurations related to my USB drives will be changed. Irregardless of whether i use UUID or LABEL in my /etc/fstab.
However, it works on RHEL5. But, upgrading is not an option in my environment. I have been googling around looking for alternatives but everything seems to point back to using UUID or LABEL in /etc/fstab.
Anyone has tried something that works? Please help me, thank you.
While the article is intended for Ubuntu users, it shouldn't be too much trouble to adapt the procedure to a RHEL system. For one, leave out all the 'sudo' prefixes to commands if you're already root (but I didn't have to tell you that).
Further to what Tim wrote, if you do end up needing UDEV rules for this to work right, there are several excellent articles around the net; just Google for "Writing UDEV Rules" and you will find them. The trick is, UDEV is something of a moving target, and has had MANY release versions over the years; with every so many release versions, the syntax of the rules has changed a lot over time, so one tutorial may not apply as well to your version of udev as another tutorial (and your version is bound to be rather old on RHEL4) - so reference & compare syntax in several tutorials if you are getting errors from udev about your rules.
Thank you so much for your prompt response. If I write UDEV rules, and I plug out those USB drives, will it cause any error upon reboot? I don't want the hal daemon to keep on looping to look for the drive and causes an infinite loop. The USB drives will be left in the server for a few months and after that we might change to a different USB drives hence we need flexibility but also some fixed configurations.
The UDEV rules which will apply for the USB drives will simply not have any effect if the drive is not present in the machine upon power-up, and will effectively be skipped. So, neither HAL nor UDEV should get stuck in a loop looking for a device that is not present. As long as the drive *is* present, the rules will have their effect during power-up.
If you write a rule to apply specifically to a particular device (based on device serial # and/or some other unique characteristics) then the rule will apply only to that very device (fixed configuration - this is what I use for my USB sticks); but if you write a rule(s) which can apply to more than one particular device, then whatever device gets inserted, the rule will act upon (somewhat flexible configuration) - however, I'm not sure what might happen if you have one device already plugged in & mounted, and then you plug in a second device which the UDEV rule says to mount at the same location. Either a passive error from UDEV or from the kernel, or maybe the drive will get auto-mounted somewhere that you didn't expect it to.
My choice would be to write an individual rule for each of any drive(s) you currently use, and when you get some new drives, add some new rules for them at that time. Writing multiple rules is simple once you get the first one working - then it's just a copy & paste and a little editing of the serial # or whatever unique identifier(s) you have chosen.
If you search LQ a little for threads about UDEV and USB sticks, you will find several that describe your situation here, at least one of which were posted by me, describing how I created the rules for my USB sticks. If you want them and can't find them, I'll find the threads for you and provide links.
Thanks a lot! I tried a few rules yesterday and I think there is some sort of syntax error. I got rather confused with the == or the = used. Some examples I read use == whereas some use =. If you can enlighten me on that, it'd be great. As a result of this syntax error, when I plugged in new disks, it couldn't be detected! I had a shock of my life time haha. It only worked when I deleted the faulty rules created by me.
The thread that you previously talked abou this would be of great help to me, if you can locate and send me the link.
Some updates to share. I finally got the syntax correct. The syntax really differs from OS to OS i assume. However, after managing to create those fixed names for each device, the fstab still changes my entries after reboot. For example,
/dev/cg2 /mnt/cg2 ext3 ....
is changed to
/dev/cg2 /media/cg2 ext3 ....
How do i stop fstab from changing my entries? I still end up having to mount those devices by myself. At least the good news is, I somehow have a simple name to refer to so that I know which device contains what information.
Yes, because of all the different versions of UDEV out there over the years, various OS's all have different versions installed, so as mentioned, small changes to the rules' syntax over time means that rules from one machine won't necessarily work perfectly on another machine without some tuning. The UDEV administrative tools & commands have also changed.
As to why your fstab file is being changed upon reboot, I have no clue. I hope that either another user of RHEL4 can offer something on that subject, or that you can find the reason for this either in the RHEL documentation or perhaps on the RH website(s). I'm confident that the answer is out there -- Google might be your best friend.
Here are a couple threads where other members and I talked about udev rules for USB hard-disks, card-readers and usb sticks (which are all the same idea - SCSI disks), and where I have posted examples of my udev rules for some of those devices, and how I got the information I needed to create the rules. Again, keep in mind that your UDEV version is probably different from any I may have been using at that time, so the exact commands & syntax you end up using might be slightly different from those I've shown. Other members have commented in those threads about, for example, using the command udevadm instead of udevinfo, depending on the UDEV or OS version. Anyhow, here's some links - I hope this helps you in some way: