Bug 270808 - External hard disks should be spun down when 'safely removed'
Summary: External hard disks should be spun down when 'safely removed'
Status: RESOLVED FIXED
Alias: None
Product: frameworks-solid
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.44.0
Platform: Fedora RPMs Linux
: NOR major
Target Milestone: ---
Assignee: Lukáš Tinkl
URL:
Keywords: usability
: 292759 324981 338912 371161 393632 399792 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-04-13 03:34 UTC by Syam
Modified: 2019-10-26 01:52 UTC (History)
41 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
proposed patch to spid down the drive (2.61 KB, patch)
2013-02-24 20:57 UTC, Lukáš Tinkl
Details
~/.local/share/solid/actions/usb-drive-eject.desktop (319 bytes, application/x-desktop)
2018-01-12 09:57 UTC, Michael Heidelbach
Details
~/bin/usb-drive-eject (1.22 KB, application/x-shellscript)
2018-01-12 10:01 UTC, Michael Heidelbach
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Syam 2011-04-13 03:34:42 UTC
Version:           4.6 (using KDE 4.6.1) 
OS:                Linux

I've been using an external (USB) had disk with multiple partitions and always used 'safely remove' from KDE device notifier (or Dolphin) to unmount all partitions and then disconnect the USB connection.
Recently, I've noticed that the disk has developed errors, possibly due to removal before spin down.

On Windows, after I do a 'safely remove', the lamp on the HDD goes a little dim and the manual says that it's then safe to disconnect the drive.
On Linux, using the Palimpsest Disk Utility (http://library.gnome.org/users/palimpsest/ ), I can do a 'power down' and the same dimming of the lamp is observed.

It'd be great (and safe) if this would automatically be done when unmounting from KDE. Otherwise, it's a risk to disconnect the drive even after 'safely removing' it.

Reproducible: Always
Comment 1 Christoph Feck 2012-01-31 00:31:40 UTC
*** Bug 292759 has been marked as a duplicate of this bug. ***
Comment 2 Syam 2012-06-02 10:35:10 UTC
The new version of Palimpsest (or 'Gnome Disk Utility' or just 'Disks' in F17) doesn't have the 'Safe removal' option anymore. Now there's no (easy) way to power down the HDD on KDE or GNOME. :-(
Comment 3 Myriam Schweingruber 2012-09-07 11:22:41 UTC
Confirmed by duplicate.
Comment 4 guanx 2012-11-15 23:30:38 UTC
This is always a problem. Some people want only a umount, some want eject and spin down. My guess is 
1) umount is sufficient, and is the most proper way to deal with USB flash storage devices;
2) For CDROMs or other devices that can actually eject, eject is what most users want;
3) For external hard disks, an additional "hdparm -Y" is also welcome.
Comment 5 guanx 2012-11-15 23:34:59 UTC
BTW, If you know you want to spin down your block device, just add an "hdparm -Y" to "/usr/lib/kde4/libexec/kdeeject" for the moment (before there can be a sophisticated solution).
Comment 6 guanx 2012-11-16 00:25:04 UTC
My mistake. The proper place to spin down a hard drive seems to be in KDiskFree instead of the command line utility kdeeject.
Comment 7 Alex Fiestas 2013-02-24 20:53:01 UTC
Luka, any thoughts on this?
Comment 8 Lukáš Tinkl 2013-02-24 20:57:54 UTC
Created attachment 77554 [details]
proposed patch to spid down the drive

Can you try the attached patch?
Comment 9 Alex Fiestas 2013-02-24 23:20:44 UTC
For the patch to work you have to use udisk2.
Comment 10 Alex Fiestas 2013-07-28 20:45:07 UTC
Closing the thread for lack of activity.

@Lukáš Tinkl Should we push this to master ? or just drop the patch?
Comment 11 Lukáš Tinkl 2013-07-29 09:09:08 UTC
Without proper feedback, nope
Comment 12 Jean-Christophe Baptiste 2014-06-10 13:46:24 UTC
This is now the behavior in all major OS and DE: Windows, Mac OS, Gnome...
KDE should also do it. This is far safer for disk drive to be shut before being unplugged.
Comment 13 Christoph Feck 2014-06-25 18:13:26 UTC
*** Bug 324981 has been marked as a duplicate of this bug. ***
Comment 14 Alivema4ever 2014-08-30 20:35:00 UTC
Voted +20 for this.
This is a basic feature that (hopefully) extends the lifespan of external harddisks.
Comment 15 Christoph Feck 2014-09-09 10:41:24 UTC
*** Bug 338912 has been marked as a duplicate of this bug. ***
Comment 16 Christoph Feck 2014-09-28 13:31:55 UTC
Lukáš, what feedback do you need? Is this patch risky to apply?
Comment 17 Alivema4ever 2014-09-28 14:23:56 UTC
Since most of us don't build kde by ourselves, it's better to just merge the patch with the testing / beta KDE branch. So that, when the package manager syncs the testing branch, it will be automatically applied and built and ready for testing. Let the beta tester do the test.
The rest is simple. Patch maker should listen to the feedback and bug reports on the testing branch.
If no serious issue reported during the testing period, the patch is ready to go stable branch.
Comment 18 Jean-Christophe Baptiste 2014-10-25 03:20:45 UTC
So when can we get this patch applied please ?
Meanwhile, we are using that stuff daily...
Comment 19 Alivema4ever 2014-10-25 18:26:41 UTC
No need to force developers to implement a feature that they don't consider to be important. Because it's your removable hdds which are at risks, not their fixed hdds.

I always power off my removable drive by issuing the following command after unmounting all mounted partitions on the particular drive.

```
udisksctl power-off /dev/sdb
```

Udisksctl comes from udisks2 package, which is installed by default on most distributions.

That solves this problem without needs to apply this half-hearted patch.
Comment 20 Jean-Christophe Baptiste 2014-10-25 19:14:27 UTC
Unfortunately, I cannot force anyone. The purpose is that they should just follow the common sense, and optionally listen to their users.
KDE is propably the last modern environment not implementing this (at least, it works well on Gnome, Windows and Mac OS).

Honnestly, I don't care there is a command line (I knew about this one). When you use KDE for working, you just don't want to throw a command every time you use external disks (in my case, often). Such dumb functionalities should be managed by the desktop environment.

Again, that's common sense. Nothing else.
Comment 21 a.frankova.contact 2014-12-07 20:44:47 UTC
Hi,
I have the exact same problem (an external usb drive not spinning down after ejecting). I just found this bugreport and I would love to help to get this worked out. Is there any way I can help? I'm just a common Kubuntu user so I don't have any advanced experience, but I definitely can do testing and give feedback.
Comment 22 Christoph Feck 2014-12-12 21:18:07 UTC
The patch that needs testing is attached here.
Comment 23 a.frankova.contact 2014-12-12 21:45:17 UTC
(In reply to Christoph Feck from comment #22)
> The patch that needs testing is attached here.

Okay, after some googling, I've realized I'm treading much deeper water than I expected. (Yay, go newbies.) I'll still try and help, but in case anyone with more experience than me is reading this, feel free to pick this up, it'll probably be faster. :P
Otherwise I'll, uh, get back if/when I get it to work.
Comment 24 M G Berberich 2015-01-05 16:07:36 UTC
I vote for reopening this bug.
I can”t understand why it has status CLOSED/WONTFIX, this should be fixed.
Comment 25 Syam 2015-01-06 10:13:35 UTC
There seems to be enough demand and 'activity' for this report. Reopening.
Comment 26 Rafael 2015-08-27 16:30:57 UTC
Hello guys, the following command has solved this problem (as root):
# hdparm -B 127 /dev/sdb
I've noted that previous value was 128 (never spin down)
Comment 27 luminoso 2015-10-22 11:18:03 UTC
Comment 26 does not work for me. Although "udisksctl power-off -b /dev/sdX" does work.

How can I, in a Fedora 22 system can test the proposed patch?

I am using plasma-workspace 5.4.2, framework 5.15.0 and applications 15.08.2. I suggest bumping this bug(or feature request) for plasma5 series.
Comment 28 Myriam Schweingruber 2015-10-22 11:48:51 UTC
The attached patch is of no use in frameworks I presume, judging from the date this was done in Qt4, so could somebody take care of this?
Comment 29 noric 2016-01-22 14:45:52 UTC
I'm willing to test this patch on KDE 4.14 (Kubuntu 14.04).
Could a dev please give me a hint about where to start with compiling KDE4?
Comment 30 noric 2016-01-22 20:40:31 UTC
Ok, I've searched a lot and I think I need to compile "Solid" with kdesrc-build. If not possibile to just compile Solid (not sure about it), then I'm going to compile the whole "kdelibs".
Please let me know if I'm in the right direction.
Comment 31 Davide Olianas 2016-03-14 14:58:33 UTC
I modified the patch to work with the current git master branch. Should I attach it?
I'm trying it on manjaro linux, plasma-desktop 5.5.5-1.1, kio 5.19.0-1, dolphin 15.12.2-1.

Still, it doesn't work. I have an external usb drive with three partitions, when I choose "safely remove" on the last mounted partition, the hard disk is still spinning. udisks --detach works for me too.
Comment 32 Soukyuu 2016-04-02 16:43:04 UTC
I do hope this will get fixed eventually, my external HDD makes unhealthy screeching noises when I unplug it without letting it spin down. I can't imagine it being healthy in the long run - especially since it seems to trigger the "unexpected power loss" counter on S.M.A.R.T. statistics. 

The same HDD gracefully (and silently) spins down in windows.
Comment 33 Soukyuu 2016-04-02 16:49:27 UTC
Oh and all "udisksctl power-off /dev/sdx" does in my case is spin the HDD down.... then up again.
OT: why can't I seem to find the vote link for this bug?
Comment 34 David Polák 2016-07-09 12:56:14 UTC
I am affected by this bug, HDD spins down and then right back up again and shows up in Device Notifier.
Comment 35 Alivema4ever 2016-09-07 10:08:01 UTC
I think the udisks subsystem of KDE should distinguish between unmounting the partitions of a drive and safely removing the drive.

Unmounting the mounted filesystem should be clearly assigned as unmount action. This is the dependency of safely remove.

Safely removing the drive should ensure that all partitions are unmounted prior to powering off the drive.

The proper graphical application to power off external disk is gnome-disk[1]. This application can be used as reference on how to implement power-off feature for safely removing external hard disks. Unfortunately, there is no equivalent app on KDE.

[1] https://git.gnome.org/browse/gnome-disk-utility/

@Soukyuu: I mistyped the command.
The proper udisksctl command to power off the drive is
``udisksctl power-off -b /dev/sdb``
``udisksctl power-off --block-device /dev/sdb``
Comment 36 guanx 2016-09-07 10:51:59 UTC
(In reply to Alivema4ever from comment #35)
> I think the udisks subsystem of KDE should distinguish between unmounting
> the partitions of a drive and safely removing the drive.
> //snip

Absolutely.

Normally there are three actions to unload a mounted drive: unmount, power off, and eject. This does not take into account anything to do with the device mapper, or there can be more actions.
To me it is acceptable to do all three by default, but it's obviously inconvenient if the other choices are not available in the context menu (right-click pop-up menu).
Comment 37 David Polák 2016-09-12 20:52:57 UTC
There is currently no way to remove external disks safely in KDE.

`udisksctl power-off --block-device /dev/sdb` spins down the disk for about a second, before KDE spins it back up.

Workarounds:
1) Turn off your computer, remove disk, turn on your computer.
2) Kill X server, udiskctl spin down, start X server

Those workarounds should be satisfactory enough for everybody. /rant
Comment 38 dubvulture 2016-10-01 11:39:17 UTC
5 years and this is still not fixed?!
We're talking about users' hard disks undermining here, not just some random crash or arguable behiaviour.
Comment 39 Christoph Feck 2016-10-19 01:55:29 UTC
*** Bug 371161 has been marked as a duplicate of this bug. ***
Comment 40 Lukas Ba. 2017-01-18 14:01:48 UTC
(In reply to David Polák from comment #37)
> There is currently no way to remove external disks safely in KDE.
> 
> `udisksctl power-off --block-device /dev/sdb` spins down the disk for about
> a second, before KDE spins it back up.
> 
Consider my vote added.

> Workarounds:
> 1) Turn off your computer, remove disk, turn on your computer.
> 2) Kill X server, udiskctl spin down, start X server
> 
> Those workarounds should be satisfactory enough for everybody. /rant

Is this workaround successful for you?
Step
1   Eject in dolphin
2   # hdparm -y /dev/sdb
3   Press HDD enclosure power button/Remove USB cable to external HDD


Some more background to this.

Turns out that most cheap external USB/SATA/firewire enclosures don’t properly issue a stop command to the drive when you flick the power switch. Instead, the power switch simply cuts power to the drive, which forces the drive to do an emergency head retract. If you think that sounds bad, you’re right. Emergency retracts aren’t going to brick your drive immediately, but if they occur regularly they’re putting a lot of unnecessary wear and tear on the drive. In fact, some drives monitor how often this happens with S.M.A.R.T. attribute 192.
Comment 41 LordDan 2017-07-04 19:20:54 UTC
Well, it's just shameful that KDE still can't power off an USB removable hard disk.
Others DEs do it: Gnome, XFCE, Windows, MacOS... Perhaps LXDE.
I still rely on Gnome Disk Utility (Disks) for safe removal of an external HD...
Comment 42 Michael Heidelbach 2018-01-12 09:57:23 UTC
Created attachment 109812 [details]
~/.local/share/solid/actions/usb-drive-eject.desktop
Comment 43 Michael Heidelbach 2018-01-12 10:01:35 UTC
Created attachment 109813 [details]
~/bin/usb-drive-eject

Maybe this helps. (plus attachment of previous post)
Works for me for > 2 years
I never had the problem of respinning though
Comment 44 Nate Graham 2018-01-12 14:03:25 UTC
Me neither. My external backup hard drive always spins down after being ejected.

Are people still experiencing this using KDE Frameworks 5.41+?
Comment 45 Jean-Christophe Baptiste 2018-01-12 15:24:06 UTC
Yes. OpenSUSE 42.3, Nautilus (Gnome) spins down the disk, Dolphin in KDE session does not.

But sadly I doubt it will be fixed some day.
Comment 46 Davide Olianas 2018-01-12 19:46:31 UTC
(In reply to Nate Graham from comment #44)
> Me neither. My external backup hard drive always spins down after being
> ejected.
> 
> Are people still experiencing this using KDE Frameworks 5.41+?

Do you know a distro with the version of KDE Frameworks you mentioned so that I can report if it works on my PC?


I'm currently on Kubuntu 16.04, KDE Frameworks 5.18.0. udisksctl works for me, but the "safe remove" from Dolphin doesn't spin down the disk.
Comment 47 Vincas Dargis 2018-01-13 07:35:32 UTC
I'm on Debian Testing, with KDE Plasma 5.10.4 and KDE Frameworks 5.37.0, and external drive is still not stopped when "safely" removing it.
Comment 48 Vincas Dargis 2018-01-13 07:36:07 UTC
Maybe I should check on KDE Neon live cd, that should have latest KDE, yes?
Comment 49 Davide Olianas 2018-01-13 18:24:33 UTC
The problem is still present with KDE Neon (KDE Frameworks 5.41).

The script usb-drive-eject works when launched from the CLI. The .desktop launcher does not work, I receive the following error message: "The desktop entry of type Service is unknown".
Comment 50 Michael Heidelbach 2018-01-13 19:56:57 UTC
@Davide
Click Device manager icon in toolbar
Click 'actions for ...' for a mounted partition.

You should see something like 'Eject' or 'Auswerfen'
Click that and you disk should power down.
Comment 51 Davide Olianas 2018-01-14 09:31:18 UTC
(In reply to Michael Heidelbach from comment #50)
> @Davide
> Click Device manager icon in toolbar
> Click 'actions for ...' for a mounted partition.
> 
> You should see something like 'Eject' or 'Auswerfen'
> Click that and you disk should power down.

Thanks! Previously I forgot to move the .desktop file in the correct folder. I now see the action for the external disk.
Comment 52 Christoph Feck 2018-01-16 23:59:42 UTC
I use 'hdparm -y' to spin down the external SATA disk. This command needs root privileges, so I am wondering whether (or how) Solid could do it without root access.
Comment 53 Michael Heidelbach 2018-01-17 13:00:58 UTC
(In reply to Christoph Feck from comment #52)
> I use 'hdparm -y' to spin down the external SATA disk. This command needs
> root privileges, so I am wondering whether (or how) Solid could do it
> without root access.

$ udisksctl power-off -b ...
can do for unpriviledged users.

$ dbus --system org.freedesktop.UDisks2 /org/freedesktop/UDisks2/drives/TOSHIBA_MQ01UBD100_44K3TR2HT
void org.freedesktop.UDisks2.Drive.PowerOff(QVariantMap options)

also looks promising.
Couldn't use it with qdbus due to (QVariantMap options)
Comment 54 Filip Fila 2018-02-04 16:52:08 UTC
Yeah, external HDDs still don't spin down with the safe remove option for me. 

Seconded on the uncomfortable noise coming from the HDD if you just pull it out - it can't be good for the drive. Power off has been the default option in all Windows' except 7 I think, and Thunar, Nautilus etc. and their respective DEs do power off HDDs if you press Eject.

A big vote from me for fixing this.
Comment 55 Øystein Steffensen-Alværvik 2018-02-18 10:17:53 UTC
As a user who prefers not to fiddle with terminal commands to do something simple as powering off an ext. HDD, I second this.

Either
a) provide option in Device Notifications to power off HDDs that support it
or
b) make unmount from Device Notifications automatically power off HDDs that support it
Comment 56 Glut 2018-04-16 12:47:34 UTC
I can confirm this on Kubuntu 18.04, KDE frameworks v. 5.44.0.

Cutting the connection manually after "safely removing" a drive makes an awful noise and leaves me wondering each time how many days I've shaved off of the drive's life time.

Seriously though, this seems like such an important issue that I really do need to ask why this has yet to be addressed after 5 years? I would absolutely understand if this were an incredibly complex and novel problem that nobody in the Linux world has been able to fix yet, but it seems like all distros outside of KDE have found a solution for it. So what gives?

If there is any additional information you need us to provide to help with tracking this down, please let us now. I'm sure that everyone subscribed to this bug report is annoyed enough by this issue to invest as much time as they can to help with fixing it.
Comment 57 Øystein Steffensen-Alværvik 2018-04-16 16:10:33 UTC
Can Framework's specific method of ejecting a harddrive be invoked from the command line, for debugging purposes?
Comment 58 Nate Graham 2018-04-18 21:42:06 UTC
We don't need more information; what we need is for someone who has familiarity with the code involved to fix it. In FOSS, the general limitation is manpower.
Comment 59 Glut 2018-04-19 15:18:09 UTC
@Michael Heidelbach:

Thanks a lot for the custom eject action! I've just set it up and it seems like it's working perfectly so far.

@Nate:

I understand. I'm sorry if my last comment came off as antagonistic. I appreciate all the time and effort you and all the other KDE contributors put into these projects. It's just that issues with the core system like these can be very frustrating sometimes – especially if they've been open for so long and you feel like there's nothing you can do to help move things along.

I really do hope that somebody picks this up eventually.
Comment 60 Nate Graham 2018-04-19 16:49:11 UTC
I do too! :)
Comment 61 Christoph Feck 2018-04-29 12:46:20 UTC
*** Bug 393632 has been marked as a duplicate of this bug. ***
Comment 62 David 2018-06-17 21:08:42 UTC
(In reply to Nate Graham from comment #58)
> We don't need more information; what we need is for someone who has
> familiarity with the code involved to fix it. In FOSS, the general
> limitation is manpower.

Can't we implement the script someone provided here as the solution for the bug? This should get fixed immediately and this could work somehow?
Comment 63 Filip Fila 2018-06-17 22:33:58 UTC
I did not have success with the .desktop file that was attached in this thread, but I did with this other one found on Reddit so I'm copy pasting it:

"I think I've found a workaround (at least for me). Create a file called poweroff.desktop at ~/.local/share/solid/actions/ with the following content:

[Desktop Action open]
Exec=solid-hardware unmount %i &&  udisksctl power-off -b %d
Icon=kt-stop
Name=Power off device

[Desktop Entry]
Actions=open;
Type=Service
X-KDE-Action-Custom=true
X-KDE-Solid-Predicate=[ IS StorageVolume AND StorageVolume.ignored == false ]

Then log out and in again. The file creates a new entry for the device notifier in the control panel to power off the device. The command first unmounts the drive and then powers it off. In contrast to OP's experience my external HDD stays off and doesn't restart again." - by a user who's now deleted his post or even account
Comment 64 Krešimir Čohar 2018-06-17 23:05:18 UTC
(In reply to Filip from comment #63)
> I did not have success with the .desktop file that was attached in this
> thread, but I did with this other one found on Reddit so I'm copy pasting it:
> 
> "I think I've found a workaround (at least for me). Create a file called
> poweroff.desktop at ~/.local/share/solid/actions/ with the following content:
> 
> [Desktop Action open]
> Exec=solid-hardware unmount %i &&  udisksctl power-off -b %d
> Icon=kt-stop
> Name=Power off device
> 
> [Desktop Entry]
> Actions=open;
> Type=Service
> X-KDE-Action-Custom=true
> X-KDE-Solid-Predicate=[ IS StorageVolume AND StorageVolume.ignored == false ]
> 
> Then log out and in again. The file creates a new entry for the device
> notifier in the control panel to power off the device. The command first
> unmounts the drive and then powers it off. In contrast to OP's experience my
> external HDD stays off and doesn't restart again." - by a user who's now
> deleted his post or even account

i had to modify this a little bit to make it work with the latest edition of plasma:


[Desktop Action open]
Exec=udisksctl unmount -b %d;  udisksctl power-off -b %d
Icon=kt-stop
Name=Power off device
 
[Desktop Entry]
Actions=open;
Type=Service
X-KDE-Action-Custom=true
X-KDE-Solid-Predicate=[ IS StorageVolume AND StorageVolume.ignored == false 

(changed solid-hardware unmount to udisksctl unmount)
Comment 65 hap 2018-07-08 18:14:32 UTC
Adding to this request. Every other distro I have used powers off the spinning HDDs when "ejecting" or "safely removing". This is a fundamental behavior and can cause damage to drives when people are on KDE but muscle memory from other distros takes over. Please either build in the power off to "safely remove drive" as other distros do, or add another option that does include powering down like "eject and poweroff" etc. Users shouldnt need to take multiple steps in disk utilities or the terminal to do this simple task.
Comment 66 Stefan Brüns 2018-10-08 19:42:36 UTC
Git commit 867f53608d3a5145e3380e8c1686f40be8f06c31 by Stefan Brüns.
Committed on 08/10/2018 at 19:42.
Pushed by bruns into branch 'master'.

[UDisks2] Power down drive on remove if supported

Summary:
It is preferable to to do a controlled shutdown prior to disconnecting
and eventually cutting of power to the drive.
Closes T9730

Test Plan:
Connect external drive, select "Savely Remove" from context menu
1. if drive has only on partition, fs is unmounted and drive spins down
2. if drive has multiple partitions:
 a) first (not last) partition can be unmounted and remounted
 b) "Remove"ing last partition spins down drive

Reviewers: #frameworks, ngraham, broulik

Reviewed By: ngraham, broulik

Subscribers: broulik, kde-frameworks-devel, ngraham

Tags: #frameworks

Maniphest Tasks: T9730

Differential Revision: https://phabricator.kde.org/D15932

M  +10   -1    src/solid/devices/backends/udisks2/udisksstorageaccess.cpp

https://commits.kde.org/solid/867f53608d3a5145e3380e8c1686f40be8f06c31
Comment 67 Nate Graham 2018-10-14 15:32:24 UTC
*** Bug 399792 has been marked as a duplicate of this bug. ***
Comment 68 Vincas Dargis 2019-01-27 17:16:08 UTC
External HDD now spins down in Debian Buster! Thanks!
Comment 69 Gordon Lack 2019-10-26 01:52:53 UTC
And powering off an external drive can be a real pain, as I then need to physically unplug and re-insert as device if I want to use it again.

I may well want to unmount a device (as I don;t need it "now"), but leave it plugged in as I may need it later.

So I've opened https://bugs.launchpad.net/ubuntu/+source/dolphin/+bug/1827778 to re-add the option to *just* unmount a device.