I have a USB hard disk that I want to mount on boot and in a specific location. How can I make that drive mount and stay available (say for local backups, etc.) even though no one's logged in?

It seems that udev or something similar grabs hold of the disk. If I put an entry in /etc/fstab that tries to specifically mount this disk (by UUID), then that mount process and the udev mount process seem to end up in a battle with each other and the disk doesn't get mounted.

  • Can you add the line you added in /etc/fstab? Are there any log messages when you plug your drive in? Maybe it helps to raise the log level in /etc/udev/udev.conf. – qbi Aug 8 '10 at 8:47
  • How does you fstab line look? It should look somthing like this "UUID=48a26dbe-e707-4e45-bd55-fc7936292ee1 /data ext4 errors=remount-ro 0 2" – LassePoulsen Aug 8 '10 at 9:44

Mount the disk using udev. Place the rules from this wiki into /etc/udev/user.rules and reboot (or reconnect the USB HDD) . There are several favors of rules in the wiki (that's why I didn't list them here), choose the one that best suits your needs (e.g. you need a specific normal user to be able to unmount it).

Perusing /lib/udev/rules.d/80-udisks.rules will help you understand what's udev doing to your hard disk.

Besides the udev rules I mentioned above I think there's another approach you can take: instruct udisks (through udev) to leave your disk alone and then mount it through fstab.

This code works on my system

ACTION!="add|change", GOTO="my_udisks_end"
SUBSYSTEM!="block", GOTO="my_udisks_end"

ENV{ID_TYPE}!="disk", GOTO="my_udisks_end"
ENV{ID_BUS}!="ata", GOTO="my_udisks_end"
ENV{DEVTYPE}!="partition", GOTO="my_udisks_end"



but is generic and includes all partitions. To be able to target your particular hdd/partition use udevadm info --query=all -n /dev/sdX and then match on some of those particular atributes in the udev rules.

A good resource to help you in this is Writing udev rules. Unfortunately it contains some outdated info (udevinfo was replaced by udevadm indo). I assure you, though, it's a worthwhile read -- udev is a central piece of architecture nowadays and you can accomplish a lot by using it. It's also pretty flexible.

It's also easy to make mistakes in udev rules :). Use udevadm test $(udevadm info -q path -n /dev/sdX) to take a 'peek' at what's udev doing.

  • Awesome. This looks very much like what I was looking for. Seems I have some reading to do... – Don Faulkner Aug 17 '10 at 21:12

You could try referencing it by /dev/... instead of by UUID. It is most likely /dev/sdb*, you can check this by going to System -> Administration -> System Monitor and clicking on the 'File Systems' tab. You will need to have inserted the USB drive first and let it be automatically mounted. Replace 'UUID=uuid' with the '/dev/sdb*' in /etc/fstab. It's always a good idea to back up fstab before editing it.

  • 4
    Referencing mass storage devices directly to device-nodes is a bad idea! BIOS settings and removed devices might screw up the device order. – LassePoulsen Aug 8 '10 at 9:42
  • You're probably right but I was under the impression that the UUID is regenerated every time a USB device is removed and plugged back in. This would mean that fstab would need to be edited each time the device is removed and plugged back in again. – dv3500ea Aug 8 '10 at 10:08
  • Actually, I was wrong, UUID remains the same. – dv3500ea Aug 8 '10 at 10:15
  • 3
    UUID is the filsystems Unique ID and have notting to do with the bus location or device. It will even survive if you copy an entire filesystem from one device to another. – LassePoulsen Aug 8 '10 at 22:59
  • 1
    The filesystem permanence is what I was looking for with mount-by-uuid. This is my "local backup" device, and I want /backup (or wherever I mount it) to always have this filesystem, even if I add or re-arrange devices. That's the advantage of by-uuid or by-label mounting. – Don Faulkner Aug 9 '10 at 14:42

Your Answer

