Showing posts with label removable storage. Show all posts
Showing posts with label removable storage. Show all posts

Tuesday, July 17, 2007

Mount USB drives on boot

On Fedora Core 7, leaving a USB drive (a simple flash disk) connected doesn't seem to be mounting after reboot even though it's properly listed in the /etc/fstab. I went through a few solutions to this, like this one, but the only one that worked for me was modifying the /etc/rc.sysinit script as I explain below.

I seem to remember creating an entry in the fstab, and allowing the auto option (which is part of the default specification), would make your USB partition mount on boot. The issue with FC7 seems to be that the usb-storage kernel module isn't being loaded when the fstab is first loaded, and that the USB devices aren't initialized yet by /etc/rc.sysinit. This seems to be common with all newer distros, in accordance with the move to udev, hal and other components, which facilitate plug & play user mounting and they don't need them to be available before entering a GUI. This is great for workstations, but I have a "headless" server configuration, therefor I'm not using GNOME to mount anything on-demand, but rather they should be available statically.

After a few days of trial & error, and inspiration from this post, I added the following lines to the end of my /etc/rc.sysinit. Note that changes to this particular file may be removed by system updates (Using yum) as I explain below.
# Try to mount all USB partitions
# This should be moved to `rc.local' and be prepended with a wait
modprobe usb-storage
mount -a

I believe this is the most most robust method, since simply adding the entry to the fstab will allow it to be mounted after the USB devices are initialized. It is preferred to use the /etc/rc.local script to issue this nature of commands (local/custom configuration), but this script seems to be run before the /etc/rc.sysinit script exits, meaning the USB partitions may not yet be available. Commanding the /etc/rc.local script to wait for the /etc/rc.sysinit script to exit may be a solution.

Finally, note that you can guarantee consistency of the partition before mounting it by carefully editing the corresponding fstab line in the normal way, see man 5 fstab for more.

Saturday, July 14, 2007

Label your EXT3 partitions!

If you have removable drives used for backup or portable media, and you're using EXT3 rather than FAT16 (the default format of most USB flash drives), mounting these drives by their Linux device name is ambiguous. For example, I have a hard drive in a Venus DS-3 with a single EXT3 partition on it. The problem is, making the entry in the /etc/fstab file. The /dev/sd[a-z][1-9] designation is not good enough because it changes with the order of the connections during boot-time or plug-in time.

Making labels for each partition to be mounted fixes the problem entirely. To create a label for an ext2/ext3 partition, use the e2label command:
e2label [device] [label]

My exact command was:
e2label /dev/sde1 "Venus1"

Note that I had to find the right drive using 'fdisk' before I knew it was 'sde1'.

The change takes place right away, and then you can put a line in your /etc/fstab like:
LABEL="Venus1"          /media/venus1           ext3    noauto          0 0

And it will run through the drives to find the right label. We've associated the mount location with the partition on the physical device. This is especially important if you're mounting the drives on a server and are not using any automatic mounting facility.

Some recommend to also label the static partitions if you're using only EXT3. If you're using LVM, the groups and volumes are already labeled.

Alternatively, you may use a UUID, obtained from
udevinfo -q env -n /dev/sdd1

Where sdd1 is your USB device, which you can find from
fdisk -l


There is a lot more info you can get with udevinfo but for now, just grab the ID_FS_UUID and you can use it in your /etc/fstab as follows:
UUID=492bc203-de77-40b6-be4b-49e84fee430e /data ext3 auto,defaults 0 0


See http://www.patrickmin.com/linux/tip.php?name=usbkey_mount and
http://floatingsun.net/articles/howtos/howto-usb-automount.html for more.