Is there any way to turn off a USB HDD manually?
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
udisksctl unmount -b /dev/sdXY udisksctl power-off -b /dev/sdX
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
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.
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?)
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.
@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
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?
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
. then select the disk and you will see a power button at top-right of the window, with tooltip «Power off the drive».
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.
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.
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.
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.
@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!
Unplug the USB cable should do it. If not, then plug it back in and safely remove it again until it stays off.
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.
This is how I do that on Linux Mint 17.3
- List your drives with partitions and make sure you select proper drive
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.
How to turn off hard drive in Ubuntu?
I am running Kubuntu from External Hard Drive. My Internal Hard Drive has Windows on it. I don’t want to use it while on Ubuntu and want to turn it off to produce less heat as well consume lower battery. I think spinning down hard drive isn’t an option for me. Because, it wear out the hard drive and I don’t plan to spend on HDD’s 🙂
@GuilhemSoulas My question is not about spinning down hard drive. Mine is how to turn off hard drive.
3 Answers 3
where /dev/sdX is the device you’d like to turn off. You can also run sudo blkid to determine the device’s ‘fingerprint’ (UUID), which would allow you to more reliably control which device is being turned off.
sudo hdparm -Y /dev/disk/by-uuid/DEVICE-IDENT-HERE
man hdparm
-Y Force an IDE drive to immediately enter the lowest power consumption sleep mode, causing it to shut down completely. A hard or soft reset is required before the drive can be accessed again (the Linux IDE driver will automatically handle issuing a reset if/when needed). The current power mode status can be checked using the -C option.
This command did turn off the hard disk drive, but running sudo hdparm -C /dev/sdX to query the status will turn on the drive again then goes to stand by (a soft reset, I guess). Does the job for power saving, but not for simulating installation without the hard disk drive.
You likely have the udisks2 package installed; you can use
udisksctl power-off -b /dev/sdX
where /dev/sdX is the device you’d like to turn off.
From udisksctl man page (version 2.7.6):
power-off Arranges for the drive to be safely removed and powered off. On the OS side this includes ensuring that no process is using the drive, then requesting that in-flight buffers and caches are committed to stable storage. The exact steps for powering off the drive depends on the drive itself and the interconnect used. For drives connected through USB, the effect is that the USB device will be deconfigured followed by disabling the upstream hub port it is connected to. Note that as some physical devices contain multiple drives (for example 4-in-1 flash card reader USB devices) powering off one drive may affect other drives. As such there are not a lot of guarantees associated with performing this action. Usually the effect is that the drive disappears as if it was unplugged.
Автоотключение hdd с помощью hdparm
Хотелось бы, чтобы несистемный диск (WD5000AAKX) на десктопном компьютере отключался после отсутствия обращений к нему через 5 минут.
Раньше это делал с помощью gnome-power-manager, потом через mate-power-manager, потом xfce4-power-manager. В общем, выбирал легкий путь. В настоящее время в меню управления питанием в Cinnamon такая настройка отсутствует (хотя в этом же дистрибутиве, установленнм на thinkpad такая настройка есть).
Что я делал:
не помогло
ЧЯДНТ?
1. Как автоматически останавливать диск через 5 минут после последнего обращения?
2. Просто интересно, почему в настройках cinnamon на десктопе отсутствуют настройки остановки hdd, а в том же дистрибе на thinkpad x220 они есть? Что такого было установлено на thinkpad, чего нет на desktop?
Что я делал: >hdparm -B 128 -S 60 /dev/sdb
не помогло. >hdparm -B 128 /dev/sda
Ты хоть в курсе, как диск называется?
Да, это опечатка. В терминале делал /dev/sdb
добавлю еще:
в ответ на первую из команд выдается вот что:
/dev/sdb: setting Advanced Power Management level to 0x80 (128) HDIO_DRIVE_CMD failed: Input/output error setting standby to 60 (5 minutes) APM_level = not supported
Что я делал: >hdparm -B 128 -S 60 /dev/sdb
не помогло. >hdparm -B 128 /dev/sda
Тут где-то на форуме были темы как посмотреть что дергает диск. У себя за этим занятием ловил то-ли udev (хотя врядли) то-ли udisks. Вобщем что-то обращается диску и просто не успевает пройти 5 минут после последнего обращения. Вот и не засыпает. И, да лучше поставить минут 20, а то будут глюки, когда каждую 5 минуту засыпает, а каждую шестую просыпается. и кирдык маторчику..
мне важнее понять: пока что понятные менеджеры питания видел в gnome и xfce. А как же все остальные, у кого всякие там awesome, lxde и прочее? Как там надежно управлять дисками?
У меня ничего не дергает диск. Это диск с данными, он нужен далеко не каждый раз. Вот в данный момент, когда пишу это, gnome-power-manager(я вернулся на mate) выключил его с характерным звуком выключения hdd. ТАкой же звук у меня был и в винде, когда происходило включение или остановка hdd по необходимости.
Поставить и настроить smartd с оповещением на E-mail? Мне, честно говоря, непонятно, зачем останавливать НЖМД, обычно этим страдают любители SSD, у которых ресурс для перезаписи существенно ограничен по сравнению с НЖМД. Жёсткому диску лучше работать круглосуточно, чем выключать его каждые пять минут. Ресурс количества старт-стопов тоже имеет свой порог в SMART, так на заметку.
Как автоматически останавливать диск через 5 минут после последнего обращения?
Мне, честно говоря, непонятно, зачем останавливать НЖМД
Жёсткому диску лучше работать круглосуточно
2 причины вопроса: первая — этот диск нужен вообще не каждые сутки. Бывает нужен, а бывает и нет. То, что я хочу — заложено в любой power-manager, например, в gnome-power-manager. второе — понять на будущее, если хотите — то просто ради эксперимента.
Как там надежно управлять дисками?
Всякие laptop-mode-tools которые юзают hdparm
Что я делал: >hdparm -B 128 -S 60 /dev/sdb
не помогло. >hdparm -B 128 /dev/sda
Давай я тебе вслух почитаю man hdparm
-B Get/set Advanced Power Management feature, if the drive supports it. A low value means aggressive power management and a high value means better performance. Possible settings range from values 1 through 127 (which permit spin-down), and values 128 through 254 (which do not permit spin-down). The highest degree of power management is attained with a setting of 1, and the highest I/O performance with a setting of 254. A value of 255 tells hdparm to disable Advanced Power Management altogether on the drive (not all drives support disabling it, but most do).
Строго говоря как будит вести себя диск при определенных значения hdparm -B зависит от производителя диска. Гдето в сети точно лежит pdf’ка на твой диск, где это описано.