Wednesday, 9 December 2015

Hdparm and Samsung Hard disk {ata-SAMSUNG_HM641JI}

I have written this article to consolidate what i have implemented to reduce the Load_Cycle_Count of the hard disk. As Linux is known to be affected by the Advanced Power Management issue, i try (out of parnoia as my hard disk hit Load_Cycle_Count of 72000 in a short period of 4 months) to reduce the growth rate of the Load_Cycle_Count by implementing the steps below after reading pages of forum from Fedora, Ubuntu, Arch and Debian, to a lesser extent, Gentoo.

In Fedora

I implemented the following configuration in /etc/udisks2/"mydevice".conf:

# See udisks(8) for the format of this file.

[ATA]
WriteCacheEnabled=true
StandbyTimeout=253


I recommend that the name for "mydevice" to be altered to reflect the model and serial number of your harddisk using the following command:

udisksctl status

#The following step (adding rc.local configuration) may be obsolete and is optional for modern linux system running Systemd;  

I added rc.local configuration in /etc/rc.d by issuing the command:
sudo nano /etc/rc.d/rc.local

and I added the following (please note the text in red; text in pink are kept unchanged) :
#! /bin/bash -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#Utility that checks whether the APM level is at 250 if not, reset it there. 

SLEEP="120"

while [ true ] ; do

STATE=`hdparm -I /dev/sda | grep "Advan" | sed "s/.* \([0-9][0-9][0-9]*\).*/\1/"`
ASTATE=`echo ${STATE:0:3}`

     if [[ $ASTATE != "250" ]] ; then
           hdparm -B 250 /dev/sda
     fi

sleep ${SLEEP}s
done


exit 0

NB: #! /bin/sh -e is to be changed to #! /bin/bash -e if the default shell is not bash. We can check using the command:
readlink -f $(which sh)

This step (editing TLP configuration) may be optional;
As i have installed TLP package known for its powersaving capability, i edited the following value in /etc/default/tlp:

# Non-zero value enables, zero disables laptop mode.
DISK_IDLE_SECS_ON_AC=0
DISK_IDLE_SECS_ON_BAT=300


# Dirty page values (timeouts in secs).
MAX_LOST_WORK_SECS_ON_AC=360
MAX_LOST_WORK_SECS_ON_BAT=600


# Hard disk advanced power management level: 1..254, 255 (max saving, min, off)
# Levels 1..127 may spin down the disk; 255 allowable on most drives.
# Separate values for multiple devices with spaces.
DISK_APM_LEVEL_ON_AC="250 250"
DISK_APM_LEVEL_ON_BAT="128 128"



Alternatively, you may add a systemd service as advocated on Unix & Linux Stack Exchange forum.
( http://unix.stackexchange.com/questions/80437/how-can-i-run-an-hdparm-command-after-boot-and-resume-on-fedora-19#89013 )

The Creator named it hdsilence.service by saving it in /etc/systemd/system/hdsilence.service. Below is the innards of hdsilence.service:



[Unit]
Description=Silence HD
After=suspend.target

[Service]
Type=oneshot

# Disable automatic head parking for the main disk
ExecStart=/sbin/hdparm -B 250 /dev/disk/by-id/ata-ST3250824AS_4N127FD1

# Enable automatic spin down after 30 seconds for the second, infrequently used disk
ExecStart=/sbin/hdparm -S 6 /dev/disk/by-id/ata-ST31000528AS_BVP5H5X1

[Install]
WantedBy=suspend.target basic.target





To enable hdsilence.service, the user may issue the following commands:
systemctl enable hdsilence.service
systemctl daemon-reload


In Linux Mint Debian Edition
#warning: please do not edit the hdparm.conf without understanding its working mechanism as it can bricked your system. It is advisable to read the hdparm documentation before running man hdparm.

On top of what i have implemented in Fedora, i edited the hdparm configuration in /etc/hdparm.conf by adding the following

/dev/sda {
     apm = 250
     spindown_time = 253 # check man hdparm
     dma = on  # (optional) i have commented the option dma as   

                      # there is a warning during boot-up
}


To verify that the above is running, i issue the following command: 
sudo hdparm -I /dev/sdb | grep Advan

I obtained the following result:
    Advanced power management level: 250
       *    Advanced Power Management feature set


The above configuration is working at boot up.

Finally, i added a udev rule (50-hdparm.rules) in Linux Mint Debian Edition in /etc/udev/rules.d using the following script:

ACTION=="add", SUBSYSTEM=="block", KERNEL=="sda", RUN+="/usr/sbin/hdparm -B 250 -S 253 /dev/disk/by-id/ata-SAMSUNG_HM641JI_SERIAL"


Please verify the implement in Fedora / Linux Mint Debian Edition by monitoring the Load_Cycle_Count & Power_On_Hours running the command using Smarmontools:

sudo smartctl -A /dev/sda | grep -E "Load_Cycle_Count|ID| Power_On_Hours"


Follow my blog with Bloglovin

No comments:

Post a Comment

Experimenting with Archlinux on Legacy Bios system

nano /etc/wpa_suppplicant/wpa_supplicant.conf    ctrl_interface=/run/wpa_supplicant    update_config=1 wpa_supplicant -B -i wlan0 -c /e...