pm_drive (safe power-switching mount/umount)

What is it and what does it do?

External hard drives with multiple TB of storage are cheap and offer space aplenty. If you have a few of these hard drives hooked up to a home server you probably do not need to have them running 24/7. Some cheap USB-SATA-bridges will not spin down the drives when not in use, which makes the situation even worse. 3.5″ HDDs typically draw up to 10 Watts when idling, not counting the amount of power lost by inefficient AC/DC adapters. If you combine these external hard drives, each coming with their own power brick, with remote-switchable power outlets, there is a lot of potential to save power and reducing the wear on the hardware. Therefore removing and powering down the unused external drives is desirable. However, uncontrolled and unmanaged cutting of power can be disastrous.
This is where pm_drive comes in:

pm_drive is a helper script that will safely mount and umount one or more external hard drives (or multiple partitions for that matter) connected to a switchable power outlet. It will power up the outlet for a specified mount-point, wait for the drive to spin up and then mount the file system. Once every mount-point provided by one or multiple hard drives connected to a specific outlet is unmounted, pm_drive will power down the outlet again.
pm_drive currently supports the Gembird SilverShield (m)SiS-PM series of USB-switchable power outlets via sispmctl.
Support for FHEM-controllable 868 MHz power outlets is planned.

Use cases / Stunts

1. When I am at home I usually have at least one (thin-)client running which accesses shares on my home server. Luckily both Samba and Netatalk can be configured to execute a command once a share is accessed (root preexec). We can use this method to pmmount the mount-point the share is pointing to. Regularly trying to pmumount the mount-point via cron should succeed once all connections to the shares are closed.

2. I hate RAID with a vengeance. It has been failing too many times on me. That is why I keep mirrors of my data drives. These additional backup drives are pmmounted and replicated/synced to every night via rsync and cron. After the process has finished they are pmumounted to save power.

Download

Install-Your-Own TM: BZipped source tarball

Just move pm_drive, pmmount and pmumount to /usr/local/bin or /usr/bin.

Make sure to install sispmctl beforehand. This should be as simple as doing: apt-get install sispmctl

Configuration

pm_drive uses a simple config file in /etc/pm_drive.conf to map outlet numbers to specific mount-points. These mount-point shall be defined in your /etc/fstab beforehand, preferably with a device-node-agnostic UUID.

The syntax of pm_drive.conf is simple:

[outlet number]:[mount-point1];[mount-point2];…

Example /etc/pm_drive.conf :

1:/mnt/Terastore;/mnt/Terastore2
2:/mnt/TerastoreBackup;/mnt/Terastore2Backup
4:/mnt/Backup

Excerpt /etc/fstab :

UUID=c643a083-0ffa-4302-b8a1-24fa563b32da       /mnt/Terastore          ext4    noatime,noauto,errors=remount-ro        0       1
UUID=60ae208a-f725-4f76-a7e9-000f70404439       /mnt/TerastoreBackup    ext4    noatime,noauto,errors=remount-ro        0       1
UUID=cef3ea66-7920-4627-adee-5b5c0dc9337a       /mnt/Terastore2         ext4    noatime,noauto,errors=remount-ro        0       1
UUID=d7487770-1396-459d-9450-74956f6b416b       /mnt/Terastore2Backup   ext4    noatime,noauto,errors=remount-ro        0       1
UUID=21f61cc4-f535-46e5-b5cd-a50584d9d1ad       /mnt/Backup             ext4    noatime,noauto,errors=remount-ro        0       1

To get the UUID for your volume/partition/file system, use blkid.

Usage

Mounting:

pm_drive -o /mnt/Terastore

or shorthand

pmmount /mnt/Terastore

Unmounting:

pm_drive -f /mnt/Terastore

or shorthand

pmumount /mnt/Terastore

License

pm_drive is licensed under the terms of the GNU General Public License (GPL) v2 and the source code is freely available.

3 thoughts on “pm_drive (safe power-switching mount/umount)

  1. Cool stuff. Works great with my Gembird and two external WD drives. Running Ubuntu 11.04. Keep it up!

  2. Hi,

    I have a SISPM under linux running and now wanted to test the script but the download link is dead. I didn’t find the tool somewhere else. So the “project” stopped?

Leave a Reply

Your email address will not be published. Required fields are marked *

*