Power-down USB-HDD automatically when unmounting

Forum Forums General Tips and Tricks Power-down USB-HDD automatically when unmounting

  • This topic has 7 replies, 2 voices, and was last updated Dec 29-8:46 am by Anonymous.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3942
    Anonymous

      Power-down USB-HDD automatically when unmounting with YAD

      How can this be done?

      #3944
      Anonymous

        According to this: http://unix.stackexchange.com/questions/112117/shutdown-my-backup-hard-disk-on-linux-when-i-dont-use-it
        the superior solution would be to create a rule ( /etc/udev/rules.d )

        #3997
        Anonymous

          OK, I have done some research and testing, and end-up with this rule:

          ACTION==”change”, KERNEL==”sd[b-z]1″, RUN+=”/sbin/hdparm -Y /dev/%k”

          It stops drive’s spindle and park it’s heads after partition was unmounted (exactly what i want),
          BUT, this rule will be executed EACH TIME some app reads or changes partition info!
          So modifying a /usr/local/bin/unplugdrive.sh unmounting script will be more preferable to me.
          Any help will be greatly appreciated! 🙂

          #4010
          Anonymous

            EACH TIME […] !

            I agree ~~ I personally wouldn’t want that (worries about mechanical strain of repeated power-cycling)

            Must it be yad, specifically? Would python+gtk (or gtkdialog) be equally acceptable?
            For that matter, if it’s a known (unchanging) target, the task could even be accomplished via a bash script + .desktop launcher
            along the lines of
            sudo umount /dev/sdb && sudo hdparm -S 1 /dev/sdb
            (with play or beep audible confirmation… or feh /path/to/smileyface-image visual confirmation)
            ^—- optionally adding a rule (via sudo visudo) to auto-elevate privledges for /usr/local/bin/unplugdrive.sh

            #4015
            Anonymous

              Must it be yad, specifically? Would python+gtk (or gtkdialog) be equally acceptable?

              No, just think modify existing program is smplier solution.

              <optionally adding a rule (via sudo visudo) to auto-elevate privledges for /usr/local/bin/unplugdrive.sh>

              I do it for hdparm, and modified YAD script to exec “sudo hdparm -Y” for each device marked for eject.

              #4019
              Anonymous

                Added to /usr/local/bin/unplugdrive.sh this
                mountpointdev=$(df --output=source,target |grep ${mountpointlist}|awk -F " " '{print $1}')
                before that string
                pumount "${mountpointlist}"
                and this

                echo DEVICE is $mountpointdev
                sudo hdparm -Y $mountpointdev

                after

                To allow exec hdparm without prompting a password add this:
                %users ALL=(root) NOPASSWD: /sbin/hdparm
                to
                EDITOR=/usr/bin/nano sudoedit /etc/sudoers.d/antixers

                #4036
                Anonymous

                  good solution!

                  Overnight, I wondered whether a script should employ the lsof command to ensure the device isn’t still busy.
                  Checking now, I see that pumount has an option for this: pumount –lazy

                  {blush} I missed the point:
                  script already exists & you just wanted to modify /usr/local/bin/unplugdrive.sh

                  #4449
                  Anonymous

                    Found some errors in my prevous message, but can’t edit so,post again:
                    Added to /usr/local/bin/unplugdrive.sh this:
                    mountpointdev=$(df --output=source,target |grep ${mountpointlist}|awk -F " " '{print $1}')
                    before that string
                    pumount "${mountpointlist
                    and this

                    echo DEVICE is $mountpointdev
                    sudo hdparm -Y $mountpointdev

                    after.
                    To allow exec hdparm without prompting a password add this:
                    %users ALL=(root) NOPASSWD: /sbin/hdparm -Y /dev/sd?*
                    to
                    EDITOR=/usr/bin/nano sudoedit /etc/sudoers.d/antixers

                    P.S. damn BBcodes…

                  Viewing 8 posts - 1 through 8 (of 8 total)
                  • You must be logged in to reply to this topic.