====== Setup external hard drive ====== You should choose an external hard drive that will spin down automatically after idle(no I/O activity) for some time. And in order to let it idle, you need to dismount the drive; that leads to the use of **''autofs''**. ===== Configure autofs ===== Add this to ''/etc/auto.master'': # dismount after no file access for 120 seconds: /mnt /etc/auto.mnt --timeout=120 Create file ''etc/auto.mnt'' with this: usbhd -fstype=ext3,rw :/dev/disk/by-label/USB40G Add thsi line to ''/etc/nsswitch.conf'': automount: files Restart autofs to take effect. After that, whenever you access ''/mnt/usbhd'', the partition labeled ''USB40G'' will be auto mounted. ---- The following is for something that needs the usb drive always online. ===== Setup persistent storage ===== First, **don't use autofs for the drive**. ==== Label the drive ==== tune2fs -L "USB1TB" /dev/sda1 ==== Update /etc/fstab ==== /dev/disk/by-label/USB1TB /mnt/usbhd ext3 defaults,noauto,relatime,data=ordered 0 0 Use **noauto** or not??? ==== Set udev rule ==== Add these line to ''/etc/udev/rules.d/mount-usb.rules'': ENV{ID_FS_LABEL}=="USB1TB", ACTION=="add", RUN+="/usr/local/bin/usbhd_added.sh" ENV{ID_FS_LABEL}=="USB1TB", ACTION=="remove", RUN+="/bin/umount /mnt/usbhd", RUN+="/bin/touch /var/tmp/usbhd_removed" Create file ''/usr/local/bin/usbhd_added.sh'': cat > /usr/local/bin/usbhd_added.sh < So, whenever the drive is plugged, it is mounted automatically, and dependent services are restarted as needed.