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 <<EOT
#!/bin/sh

/bin/mount /mnt/usbhd

# restart services that broke after usbhd removed and inserted again
if [ -f /var/tmp/usbhd_removed ] ; then

        /bin/rm -f /var/tmp/usbhd_removed

        /usr/sbin/service minidlna restart
        
        # more services here
fi
EOT

chmod 755 /usr/local/bin/usbhd_added.sh

So, whenever the drive is plugged, it is mounted automatically, and dependent services are restarted as needed.

voyage/setup_external_hard_drive.txt · Last modified: 2011-11-01 12:37 by admin
Back to top
GNU Free Documentation License 1.3
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0