I have a NAS server made by me with a Raspberry Pi and some HDDs attached to the USB port. All this is powered from a smart UPS made also by me. When I want to shutdown, I press a button on the UPS and this tells Raspberry Pi it is time to shutdown. After it unmount all HDDs and do the other shutdown procedures, it signal to the UPS to cut off the power. But... now I wonder if it's ok to cut the power of a HDD just like that ? I mean, if it lose power when the heads are over the disks, this will not damage the surface ? Should I use some kind of command to spin off the drive motors and park the heads ? What can I do to safely poweroff a HDD ?
1 Answers
Power off of an unmounted HDD can be risky for HDD's which don't support "autopark". But no (P)ATA or SATA HDD should exist which missing this feature. That's more a problem of old devices like MF, MFM and possible RLL HDD's.
That's no problem which is related by the controller type, but the controller type, easy describe the generation of hard disk.
HDD's normally have a auto park function, since about 1993. So the had should be protect against head crashes.
For hard disk, which didn't support like this, some people used a tool called "park". Possible that's available today as a DOS and Linux tool for historical hard disk.
One additional way to protect you against head crashes, use an SSD against a HD or SSHD.
A small hint. COW file systems and systems which use special hashes for the data and metadata, like ZFS, BTRFS and bcachefs, can protect your data against some sorts of data corruption which can happen by damaged sectors or by hard power off.

- 204
- 1
- 5
- 23
-
2Is not what I asked... I want solutions regarding HDD, not SSD. Ok, I understand that HDD can park its heads, but I don't know if I cut the power of a (unmounted) HDD I damage the disk somehow... – Marus Gradinaru Feb 10 '23 at 11:04
-
Power off of a unmounted hdd, can be risky for hdd
s which dont support "autopark". But no (P)ATA or SATA HDD should exist which missing this feature. Thats more a problem of old devices like MF, MFM and possible RLL HDD
s. – Alfred.37 Feb 10 '23 at 11:09 -
@MarusGradinaru: This answer does cover rotational HDDs, correctly stating that this is a non-problem on any disk you might be using with an RPi. After
umount
+sync
to be fully sure any dirty data has been sent to the drive, it's fully safe to just cut power; that's what desktops do. (IDK ifsync
waits for the drive's internal write cache/buffer to drain; that might take a fraction of a second, so if power-supply capacitors don't hold the voltage up for long after you cut power, you might consider a 1 second sleep aftersync
before signalling the UPS, just to be extra safe.) – Peter Cordes Feb 10 '23 at 20:13 -
@MarusGradinaru: In any case, it's always mechanically and electrically safe for the drive hardware and firmware to cut power at any time; the only question is whether your data has made it all the way to disk. Drive firmware has to be written with that assumption, even for SMR (shingled) drives that have to copy in the background to pack data further. – Peter Cordes Feb 10 '23 at 20:15
-
@PeterCordes Ok, then... But that "click" it makes when the power is suddenly cut off, it's kind of scarry :) On the Raspberry I use the firmware feature that gives a logic level on a GPIO pin after it finishes all the things that must be done to ensure a safe shutdown. I don't give the shutdown command, it does. So I cannot use
sync
or other commans. But I think it unmounts the disks before it signal the shutdown, because it wakes the HDDs from stand-by when the sequence is initiated (maybe to check if all data is written). – Marus Gradinaru Feb 10 '23 at 21:42 -
@MarusGradinaru: That click sound might be the heads moving to the park position. As for software, if this happens after the OS is fully shut down, then it would have already done any necessary
sync
ing as part of the shutdown scripts. You can of course look in them to see if anything likesync
happens afterumount
if you're curious, but I wouldn't worry if you're using a standard feature, not slotting in your own power-cut command into the shutdown scripts. – Peter Cordes Feb 10 '23 at 21:55 -
If the disk filesystems are not marked dirty at boot time, then the previous shutdown was done cleanly. – Jeremy Boden Feb 15 '23 at 22:43
sync; blockdev --flushbufs /dev/device; hdparm -Y /dev/device
as the last task. – Artem S. Tashkinov Feb 10 '23 at 14:36