On Wed, 24 Apr 2024 12:52:35 -0400 Laurence Oberman <loberman@xxxxxxxxxx> wrote: > On Wed, 2024-04-24 at 15:47 +0800, Winston Wen wrote: > > Hi, > > > > I noticed that my hard drive had an unsafe shutdown during system > > restart. I have done some related research and found that a stop > > command will be sent to the hard drive during system shutdown, but > > not during system restart. > > > > Is there a way to avoid the unsafe shutdown? Or is it the > > responsibility of the firmware to send the stop command to the hard > > drive before shutdown? > > > > And why doesn't the kernel send the stop command in system restart? > > I am indeed curious about it, and I would greatly appreciate it if > > anyone > > could help me clarify it. :) > > > > Thanks! > > > Which Distro are you using, where you are seeing this. > And what is the kernel version. > > Regards > Laurence > > Hi Laurence, Thank you for your reply! I found it on Deepin 20, with a 4.19 kernel and a sata disk from a Chinese manufacturer. After undergoing a disk stress test (fio), I found that the write performance of the disk was poor for a period of time after rebooting. The disk manufacturer did some troubleshooting and tracing, and told me that the disk did not receive the stop command during the reboot process, so it will take some time to rebuild the internal data structure after being powered on again. They showed me a list of commands they traced, and during the shutdown process, they would receive a STANDBY IMMEDIATE command after FLUSH CACHE EXT, but not during the restart process. Then I did some tests to confirm. I enabled dev.scsi.logging_level in the debian12 virtual machine (with 6.6 kernel) and collected logs on system reboot and shutdown. During the shutdown, the "Stopping disk" log can be seen, but it is not present during the reboot. I also hope to do some comparative testing on other hard drives, but I did not find the unsafe shutdown related field in the smart information of the sata disk (maybe I just missed it), so I give up. I am not an expert in scsi, so I took a temporary look at the relevant code and found sd_shutdown based on the "Stopping disk" log, and I also browsed some related commits and discussions. I feel that this may be a firmware implementation issue, but I'm not so sure, so I come to the community to ask for some advice. Just now, I tested another machine (also Deepin system, but American Megatrends firmware), the Seagate's sata disk does not increase power_cycle_count during the reboot. I think maybe this is the right behavior of the firmware. Welcome any suggestions and corrections, and thanks for all replies! -- Thanks, Winston