{"id":458,"date":"2011-09-15T16:09:01","date_gmt":"2011-09-15T14:09:01","guid":{"rendered":"http:\/\/katastrophos.net\/andre\/blog\/?page_id=458"},"modified":"2014-08-25T22:54:09","modified_gmt":"2014-08-25T20:54:09","slug":"pm_drive-safe-power-switching-mountumount","status":"publish","type":"page","link":"https:\/\/katastrophos.net\/andre\/blog\/software\/pm_drive-safe-power-switching-mountumount\/","title":{"rendered":"pm_drive (safe power-switching mount\/umount)"},"content":{"rendered":"<h2>What is it and what does it do?<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/katastrophos.net\/andre\/blog\/wp-content\/uploads\/2011\/06\/sispm-55x150.jpg\" alt=\"\" title=\"GEMBIRD SilverShield\" width=\"55\" height=\"150\" class=\"alignright size-thumbnail wp-image-479\" srcset=\"https:\/\/katastrophos.net\/andre\/blog\/wp-content\/uploads\/2011\/06\/sispm-55x150.jpg 55w, https:\/\/katastrophos.net\/andre\/blog\/wp-content\/uploads\/2011\/06\/sispm-111x300.jpg 111w\" sizes=\"(max-width: 55px) 100vw, 55px\" \/>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&#8243; 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.<br \/>\n<strong>This is where pm_drive comes in:<\/strong><\/p>\n<p>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.<br \/>\npm_drive currently supports the Gembird SilverShield (m)SiS-PM series of USB-switchable power outlets via <a href=\"http:\/\/sispmctl.sourceforge.net\" target=\"_blank\">sispmctl<\/a>.<br \/>\nSupport for <a href=\"http:\/\/fhem.de\" target=\"_blank\">FHEM<\/a>-controllable 868 MHz power outlets is planned.<\/p>\n<h2>Use cases \/ Stunts<\/h2>\n<p>1. When I am at home I usually have at least one (thin-)client running which accesses shares on my home server. Luckily both <strong>Samba<\/strong> and <strong>Netatalk<\/strong> can be configured to execute a command once a share is accessed (<strong>root preexec<\/strong>). We can use this method to <strong>pmmount<\/strong> the mount-point the share is pointing to. Regularly trying to <strong>pmumount<\/strong> the mount-point via <strong>cron<\/strong> should succeed once all connections to the shares are closed.<\/p>\n<p>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 <strong>pmmounted<\/strong> and replicated\/synced to every night via <strong>rsync<\/strong> and <strong>cron<\/strong>. After the process has finished they are <strong>pmumounted<\/strong> to save power.<\/p>\n<h2>Download<\/h2>\n<p><a class=\"downloadlink\" href=\"http:\/\/katastrophos.net\/downloads\/pm_drive.1.3.tar.bz2\"><strong>Install-Your-Own TM:<\/strong> BZipped source tarball<\/a><\/p>\n<p>Just move <strong>pm_drive<\/strong>, <strong>pmmount<\/strong> and <strong>pmumount<\/strong> to <strong>\/usr\/local\/bin<\/strong> or <strong>\/usr\/bin<\/strong>.<\/p>\n<p>Make sure to install <a href=\"http:\/\/sispmctl.sourceforge.net\" target=\"_blank\">sispmctl<\/a> beforehand. This should be as simple as doing: <strong>apt-get install sispmctl<\/strong><\/p>\n<h2>Configuration<\/h2>\n<p>pm_drive uses a simple config file in <strong>\/etc\/pm_drive.conf<\/strong> to map outlet numbers to specific mount-points. These mount-point shall be defined in your <strong>\/etc\/fstab<\/strong> beforehand, preferably with a device-node-agnostic <strong>UUID<\/strong>.<\/p>\n<p>The syntax of <strong>pm_drive.conf<\/strong> is simple:<\/p>\n<p><strong>[outlet number]:[mount-point1];[mount-point2];&#8230;<\/strong><\/p>\n<p><strong>Example \/etc\/pm_drive.conf :<\/strong><\/p>\n<pre name=\"code\" class=\"bash:nocontrols:nogutter\">\r\n1:\/mnt\/Terastore;\/mnt\/Terastore2\r\n2:\/mnt\/TerastoreBackup;\/mnt\/Terastore2Backup\r\n4:\/mnt\/Backup\r\n<\/pre>\n<p><strong>Excerpt \/etc\/fstab :<\/strong><\/p>\n<pre name=\"code\" class=\"bash:nocontrols:nogutter\">\r\nUUID=c643a083-0ffa-4302-b8a1-24fa563b32da       \/mnt\/Terastore          ext4    noatime,noauto,errors=remount-ro        0       1\r\nUUID=60ae208a-f725-4f76-a7e9-000f70404439       \/mnt\/TerastoreBackup    ext4    noatime,noauto,errors=remount-ro        0       1\r\nUUID=cef3ea66-7920-4627-adee-5b5c0dc9337a       \/mnt\/Terastore2         ext4    noatime,noauto,errors=remount-ro        0       1\r\nUUID=d7487770-1396-459d-9450-74956f6b416b       \/mnt\/Terastore2Backup   ext4    noatime,noauto,errors=remount-ro        0       1\r\nUUID=21f61cc4-f535-46e5-b5cd-a50584d9d1ad       \/mnt\/Backup             ext4    noatime,noauto,errors=remount-ro        0       1\r\n<\/pre>\n<p>To get the UUID for your volume\/partition\/file system, use <strong>blkid<\/strong>.<\/p>\n<h2>Usage<\/h2>\n<p><strong>Mounting:<\/strong><\/p>\n<pre name=\"code\" class=\"bash:nocontrols:nogutter\">\r\npm_drive -o \/mnt\/Terastore\r\n<\/pre>\n<p><strong>or shorthand<\/strong><\/p>\n<pre name=\"code\" class=\"bash:nocontrols:nogutter\">\r\npmmount \/mnt\/Terastore\r\n<\/pre>\n<p><strong>Unmounting:<\/strong><\/p>\n<pre name=\"code\" class=\"bash:nocontrols:nogutter\">\r\npm_drive -f \/mnt\/Terastore\r\n<\/pre>\n<p><strong>or shorthand<\/strong><\/p>\n<pre name=\"code\" class=\"bash:nocontrols:nogutter\">\r\npmumount \/mnt\/Terastore\r\n<\/pre>\n<h2>License<\/h2>\n<p>pm_drive is licensed under the terms of the GNU General Public License (GPL) v2 and the source code is freely available.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":42,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-458","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/pages\/458"}],"collection":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/comments?post=458"}],"version-history":[{"count":55,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/pages\/458\/revisions"}],"predecessor-version":[{"id":707,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/pages\/458\/revisions\/707"}],"up":[{"embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/pages\/42"}],"wp:attachment":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/media?parent=458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}