Hi, I’m using a 1 TB SATA HDD powered by the board. After I shut off the OS, the drive is still spinning. I would like to have a solution, maybe a script, which powers off the drive after shutdown. Any solutions please?
That is rather curious. Upon shutting down the Linux SATA driver should send the unit stop command which should spin down the HDD. It could be that the HDD ignores the command or does not support it.
BTW, I’m on Debian 8 Jessie. This is the output from hdparm root@bpi:~# hdparm -I /dev/sda
/dev/sda:
ATA device, with non-removable media
Model Number: HGST HTS721010A9E630
Serial Number: JR1000D31HAJ4E
Firmware Revision: JB0OA3U0
Transport: Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0; Revision: ATA8-AST T13 Project D1697 Revision 0b
Standards:
Used: unknown (minor revision code 0x0028)
Supported: 8 7 6 5
Likely used: 8
Configuration:
Logical max current
cylinders 16383 16383
heads 16 16
sectors/track 63 63
–
CHS current addressable sectors: 16514064
LBA user addressable sectors: 268435455
LBA48 user addressable sectors: 1953525168
Logical Sector size: 512 bytes
Physical Sector size: 4096 bytes
Logical Sector-0 offset: 0 bytes
device size with M = 10241024: 953869 MBytes
device size with M = 10001000: 1000204 MBytes (1000 GB)
cache/buffer size = unknown
Form Factor: 2.5 inch
Nominal Media Rotation Rate: 7200
Capabilities:
LBA, IORDY(can be disabled)
Queue depth: 32
Standby timer values: spec’d by Standard, no device specific minimum
R/W multiple sector transfer: Max = 16 Current = 16
Advanced power management level: 254
DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 *udma4 udma5 udma6
Cycle time: min=120ns recommended=120ns
PIO: pio0 pio1 pio2 pio3 pio4
Cycle time: no flow control=120ns IORDY flow control=120ns
Commands/features:
Enabled Supported:
SMART feature set
Security Mode feature set
* Power Management feature set
* Write cache
* Look-ahead
* Host Protected Area feature set
* WRITE_BUFFER command
* READ_BUFFER command
* NOP cmd
* DOWNLOAD_MICROCODE
* Advanced Power Management feature set
Power-Up In Standby feature set
* SET_FEATURES required to spinup after power up
SET_MAX security extension
* 48-bit Address feature set
* Device Configuration Overlay feature set
* Mandatory FLUSH_CACHE
* FLUSH_CACHE_EXT
* SMART error logging
* SMART self-test
* General Purpose Logging feature set
* WRITE_{DMA|MULTIPLE}_FUA_EXT
* 64-bit World wide name
* IDLE_IMMEDIATE with UNLOAD
* WRITE_UNCORRECTABLE_EXT command
* {READ,WRITE}_DMA_EXT_GPL commands
* Segmented DOWNLOAD_MICROCODE
* Gen1 signaling speed (1.5Gb/s)
* Gen2 signaling speed (3.0Gb/s)
* Gen3 signaling speed (6.0Gb/s)
* Native Command Queueing (NCQ)
* Host-initiated interface power management
* Phy event counters
* NCQ priority information
* unknown 76[15]
Non-Zero buffer offsets in DMA Setup FIS
DMA Setup Auto-Activate optimization
Device-initiated interface power management
In-order data delivery
* Software settings preservation
* SMART Command Transport (SCT) feature set
* SCT Write Same (AC2)
* SCT Error Recovery Control (AC3)
* SCT Features Control (AC4)
* SCT Data Tables (AC5)
Security:
Master password revision code = 65534
supported
not enabled
not locked
not frozen
not expired: security count
supported: enhanced erase
164min for SECURITY ERASE UNIT. 166min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 5000cca8c8d51090
NAA : 5
IEEE OUI : 000cca
Unique ID : 8c8d51090
Checksum: correct
My HDD is a 2,5" SATA3 1TB Hitachi Travelstar 7200rpm 32MB HGST HTS721010A9E630. Does it support that unit stop command? What is that command that Linux sends?
If this drive is not your root filesystem, you can unmount (all) the filesystem(s) on it and issue the command: hdparm -y /dev/sda and check if the drive spins down. If you get an ioctl error, try instead: sdparm -C stop /dev/sda if that does not work try: sdparm -C stop --readonly /dev/sda
All of the commands listed above can spin down your drive. If none of them does, it is likely the drive will not spin down unless power is removed.
doesn’t handle USB drives. BPi M3 has no real SATA. Only a horribly slow and buggy USB bridge: http://linux-sunxi.org/Banana_Pi_M3#SATA
The high-level SATA driver does. The USB mass-storage driver does the low-level interfacing only in this case.
Anyway, it helps to understand problems if you call them correctly. In this case it’s an USB disk not spinning down on shutdown
Behaviour might depend on disk and USB bridge used. Since the USB bridge is powered through a specific GPIO pin (PD25
) the simplest way to really shut a disk down would be to set this to 0
after umount (maybe using sunxi-pio
?).
If the GPIOs have properly implemented drivers, you should be able to do this using the /sys/ interface. I don’t recall off the top of my head how to do that, (and my BPi is at the office ATM so can’t check now) but it would involve echoing something to some files under /sys/class/gpio. See the file Documentation/gpio/sysfs.txt in the Linux kernel sources for more detailed information on how to do this.
I tried the hdparm -y /dev/sda and it does what I want, the drive stopped spinning. So I tought I’d create an init script for that and link it in /etc/rc0.d/ directory. But it did not work. After shutdown the drive is still spinning.
(Probably obvious but) Have you verified the script acually gets executed?