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.
-
AuthorPosts
-
December 17, 2017 at 11:43 pm #3942
Anonymous
Power-down USB-HDD automatically when unmounting with YAD
How can this be done?
December 18, 2017 at 12:24 am #3944Anonymous
::According to this: https://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 )December 18, 2017 at 11:22 pm #3997Anonymous
::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! 🙂December 19, 2017 at 2:10 am #4010Anonymous
::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.shDecember 19, 2017 at 2:52 am #4015Anonymous
::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.
December 19, 2017 at 3:09 am #4019Anonymous
::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 thisecho DEVICE is $mountpointdev sudo hdparm -Y $mountpointdevafter
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/antixersDecember 19, 2017 at 11:32 am #4036Anonymous
::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.shDecember 29, 2017 at 8:46 am #4449Anonymous
::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 thisecho DEVICE is $mountpointdev sudo hdparm -Y $mountpointdevafter.
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/antixersP.S. damn BBcodes…
-
AuthorPosts
- You must be logged in to reply to this topic.