The original assumption that shutdown(8) utilities in most distributions issue STANDBYNOW explicitly is incorrect. The upstream shutdown(8) doesn't do anything about libata devices; thus, many distributions which use the upstream version don't issue STANDBYNOW to libata devices.
Accordingly, libata is updated to track spin down status of each
drive to skip STANDBYNOW and warn about it automatically. This means
that libata.spindown_compat
is no longer necessary. If
shutdown(8) doesn't issue spin down, kernel will silently do the
right thing. If shutdown(8) issue spin down, kernel will skip spin
down and warn about it. This means that many distributions which
don't spin down disks from shutdown(8) don't need to update anything
and will behave correctly on newer kernels. Please read #3-1
for more info.
When a disk is powered off, it needs to flush its write cache and then unload its heads so that they don't crash onto the recording surfaces. Most disks have mechanical mechanism to unload its heads even when power is abruptly cut. This is usually called emergency unload and causes popping sound on some disks and may have negative effect on the lifetime of the disk, so the operating system must tell the disks to unload the heads prior to shutting the system down.
In ATA, this is achieved by issuing FLUSH CACHE followed by STANDBYNOW and the IDE drivers (drivers/ide/*) have always issued the sequence prior to powering off. libata uses SCSI sd driver as its high level disk driver and the sd driver, unfortunately, issues only the cache flush command during shutdown. This is mainly because SCSI disks can be accessed by multiple initiators (hosts) and spinning down disks because one initiator goes down can disturb others. Because of this implementation detail, libata drivers up to kernel version 2.6.21 don't issue the STANDBYNOW command before powering off.
During 2.6.22 development cycle, sd and libata are updated such that they can issue FLUSCH CACHE - STANDBYNOW sequence prior to power off, suspend-to-ram and suspend-to-disk. Unfortunately, some shutdown(8) implementations are not compatible with this change.
To overcome the shortcoming of libata, shutdown(8) on some distributions issue STANDBYNOW explicitly, which isn’t a complete solution as it can’t cover sleep-to-disk case. This workaround complicates the situation.
shutdown(8) issues FLUSH CACHE (skipped on some distros)
shutdown(8) issues STANDBYNOW, disk spins down
kernel shutdown initiates
sd/libata issues FLUSH CACHE
sd/libata issues STANDBYNOW (added)
The problem is that some disks spin back up on either #4 or #5 to just spin down again. We tried to fix this by tracking disk spin down status and skipping kernel-side shutdown sequence (#4 and #5) if the disk is already spun down. Unfortunately, some shutdown(8) implementations issue STANDBYNOW without preceding FLUSH CACHE. Although many if not most disks flush their cache before entering STANDBY mode, the behavior is not required by the ATA standard and thus skipping FLUSH CACHE may lead to data loss, so there isn’t any way to fix this without updating such userland shutdown(8) implementations. Considering the danger of possible damage to disks, we decided to urge distros to update such shutdown(8) implementations.
Please update shutdown(8) to do the followings.
For each libata hard disk
Check whether /sys/class/scsi_disk/h:c:i:l/manage_start_stop
exists. If it doesn't, synchronize cache and spin the disk down as
before. If it does, do nothing and continue to the next disk. The
file is also accessible as
/sys/block/sdX/device/scsi_disk:*/manage_start_stop
.
If shutdown(8) does the above, nothing will change on older
kernels (some drives will spin up for kernel issued FLUSH CACHE and
have to do emergency unload as before but they aren't too many) and
everything should work properly on kernels with manage_start_stop
.
If you have updated your shutdown(8) utility, please contact [email protected] with information about the name of the distro, which versions are updated and how to apply them (package name, URL, etc).
Newer kernels with manage_start_stop
will always spin
down disks correctly without any update. On older kernels without
manage_start_stop
, libata disks will always do emergency
unload. It would be a good idea to either issue kernel update or
modify shutdown(8) to issue FLUSH CACHE and STANDBYNOW for older
kernels as described in the above section. Note that kernel update
would require adding manage_start_stop
support to the sd
driver and revamping libata suspend/resume support to use it, so it's
probably not suitable for distributions with emphasis on stability.
If you have updated your shutdown(8) utility, please contact [email protected] with information about the name of the distro, which versions are updated and how to apply them (package name, URL, etc).
If you don't see any warning message during shutdown, newer kernels will always properly spin down your disks. However, your distro may have issued shutdown(8) or kernel update to fix spin down on older kernels. Please check the list at the end of this page and apply update if it available.
If you see the spin down warning message, please check the list at the end of this page and apply update if available. If your distro doesn't have the update, please contact the distro with reference to this page.
shutdown(8) update won't introduce any regression on kernels <= 2.6.21 and your disks will be always spun down properly on newer kernels. Sorry about the inconvenience but we expect the transition to be relatively quick. Please contact [email protected] if you have any question.
none, yet.