20

I have a USB-powered external HDD connected to my DELL laptop. Some times, after clicking on "Safely remove" item in pop-up menu of its icon in side bar, the drive is un-mounted and is removed from /dev/ folder (sdb and sdb1 both are removed) and lsusb do not show the device, but the HDD remains spinning and I could sense the vibration by putting my finger on it. But some times a few second after clicking on "Safely remove", it stops spinning and has no vibration. Is there any way (may be a CLI command) to turn it off?

7 Answers 7

29

Try this:

udisksctl unmount -b /dev/sdXY
udisksctl power-off -b /dev/sdX

on Linux Mint or Ubuntu

4
  • 1
    Error powering off drive: The drive in use: Device /dev/sdd1 is mounted (udisks-error-quark, 14)
    – Elder Geek
    Oct 1, 2017 at 23:54
  • 4
    As you probably know you just have to unmount it first @ElderGeek... I edited to correct, particularly since there isn't another answer here using udisksctl as far as I can see. If you disagree with this, please feel free to roll back etc
    – Zanna
    Oct 2, 2017 at 8:42
  • 1
    this is the correct answer. I've long time wondered what it was! turns out, disks are managed by udisks, which is controlled by udisksctl.
    – Marcus
    Mar 23, 2018 at 20:28
  • 3
    Well. It works fine, but how do I switch it on again? (A drive connected via USB disconnects when powered off. The only way to reconnect seems to plug out the USB cable and replug it?)
    – IanH
    Aug 16, 2020 at 20:56
17

Running hdparm -y /dev/sdb as root will cause the disk to stop spinning. If anything access the disk, it will spin up again.

The man page suggest this is only useful for IDE drives. However I have tested that it does work with a USB drive attached to a Dell running 14.04. The man page says the command will usually cause the drive to spin down, which suggests some drives exist which will not spin down when this command is issued.

4
  • May this command cause any problem for my drive or my data (See answer from user283885)? Feb 18, 2015 at 1:32
  • @PHPLearner That is warning against disconnecting the drive before everything has been written. That warning applies regardless of whether the drive is spinning or not. However it is always a good idea to ensure everything has been written before the disk is spun down. You could type sync ; hdparm -y /dev/sdb
    – kasperd
    Feb 18, 2015 at 8:31
  • 2
    I conclude that if I run sync ; hdparm -y there is nothing to be concerned about the drive or the data on the drive. I could disconnect the drive at any time I like? Feb 18, 2015 at 11:43
  • 2
    @PHPLearner You should still ensure the drive is unmounted first.
    – kasperd
    Feb 18, 2015 at 12:01
4

Try the Disks utility - that should be on your menu somewhere (in my case under Accessories). You can also launch it from a terminal by running

gnome-disks

... then select the disk and you will see a power button at top-right of the window, with tooltip "Power off the drive".

3

If your desktop does something fishy, you cal always fallback on the terminal.

sudo umount /dev/sdXY
# (this will umount, it will complain on opened files, if so lsof and see which ones.)
sudo sync  
# ( this flushes all buffers to disk. It will ensure that no data is lingering in ram.)
sudo eject /dev/sdX
# ( this works on dvd/cds and some, not all usb devices, it detaches the device from the port. Some devices "get smart" and try to reset and readd themselves to the disk, however all caches are clean and safe to unplug).

On the other hand, once a device is unidentified as a block device on USB, then you can use sdparm or hdparm on that device to park the heads if so desired, however using such tools will not flash buffers. And if you forget that the device is sleeping and yank the power, then you can corrupt your data.

5
  • About data corruption, if I use hdparm -fFy does this assure that no data corruption will occur? Feb 18, 2015 at 1:33
  • 1
    Doing umount, sync and eject does not power-down the drive and does not remove drive Icon from task bar. It seems that these commands differ from "Safely remove". But hdparm -y stop drive spinning only before "Safely remove", but I need to turn it off (stop spinning) after "Safely remove". I think it is better to ask the right question in a new question. Feb 18, 2015 at 5:19
  • As Learner said, the mentioned combo assure you that no data is lingering and the drive can be unplugged. Hard drives will use the remaining rotational spin of the platter as a dynamo to generate enough power to park the head, so you are safe with just yanking the cord, as long as you don't wiggle the drive. Linux is a very libertarian operating system and will not stop you to power off your drive before flushing the in memory data to disk, thus you can shoot yourself in the foot. However if still don't feel comfortable with pulling the cord, you can power off with hdparm after flushing.
    – user283885
    Feb 18, 2015 at 14:35
  • In the case where eject removes the hard drive from /dev you can power off the usb port to which the hard drive is connected, as described here stackoverflow.com/questions/4702216/… which is really the same as yanking the cord. Again the trick is to let the drive spin down with no shocks, for about 30 seconds. You can gently put your palm on top of it and feel if it's still buzzing. If not, then it's safe to move.
    – user283885
    Feb 18, 2015 at 14:39
  • @Fabby Some of the answers was learning me good new things, but none of them show a way to turn off "Safely removed" HDD. All commands works only before "Safely remove", thus I did not accepted any! Feb 20, 2015 at 16:42
0

Unplug the USB cable should do it. If not, then plug it back in and safely remove it again until it stays off.

2
  • Even if it'd sound strange, "manually" in question means "automatically".
    – EnzoR
    Apr 21, 2016 at 10:30
  • This is actually the only answer that is guaranteed to work with ALL "safely removed" USB block devices. Issuing a standby command via hdparm won't always spin down every drive, nor will any of the other approaches that don't include this step.
    – Elder Geek
    Oct 2, 2017 at 0:08
0

This is how I do that on Linux Mint 17.3

  1. List your drives with partitions and make sure you select proper drive

    lsblk
    
  2. Unmount all mounted partitions of the disk, for example with this command pattern

    sudo umount /dev/sdXY
    

    where X is your drive letter and Y a partition number you want to unmount.

  3. Stop hdd

    udisks --detach /dev/sdX
    
  4. Unplug USB cable

-1

I have three equally valid solutions from which you can take your pick.

My personal solution is to buy a use hub featuring a power switch for each port. I find it amazingly handy. If I recall, it cost only about $6 on amazon. I'll see if I can find you the item for sale before I post this, but it is enough to tell you such an affordable device exists. Found it!

In this other discussion it was determined that there is a terminal command which can be used to literally disable power from select usb ports. The question came up because the user who asked the question was using a battery operated tablet and his inconsiderate cow-orkers were plugging their cell phones in to charge, thus running down his battery. Check out the bloke who discovered the solution! ;-)

Finally, depending perhaps on the brand and features of said drive, there should be a "spin down" command you can send to the drive before unmounting it. I've never manually used such a command but back in the days of DOS, before energy saving features were common place, that was how you had to do it, so it stands to reason there's a way to do it today, and figuring it out may be as easy as writing to the drive manufacturer, looking at their website, or googling the correct question, ie "spin-down command for hard drives". I do not stand by the following solution. I did a casual search and found this. Your mileage may vary. Do let me know if it works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.