Skip to main content

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

Comments

Popular posts from this blog

Repairing Fedora Grub using Fedora Live USB

First, Prepare the Fedora Workstation Live CD using Fedora Media Writer. Next, run the Workstation Live CD and run the console. Then, enter the following commands if you are running the separate boot and root partition: 1) sudo mount /dev/sdaX /mnt Note: sdaX is the root partition 2) sudo mount /dev/sdaW /mnt/boot Note: sdaW is the boot partition The following files are essential for running the essential processes for repairing grub and shall be mounted: 3) sudo mount --bind /dev /mnt/dev 4) sudo mount --bind /proc /mnt/proc 5) sudo mount --bind /sys /mnt/sys 6) sudo mount --bind /var/run /mnt/var/run Now, you are ready to go into the Fedora partitions to repair the grub files. The path should be changed to root user from liveuser> to root>: 7) sudo chroot /mnt If you are running dual boot Windows and Fedora system, the following command will replace the Metro Interface: 8) grub2-install /dev/sda With a dual-boot or multi-boot systems, the follow

Installing SUSE Imagewriter on Linux Mint Debian Edition

The original title for this post is "Installing SUSE Imagewriter on Ubuntu LTS". Download Zip, save to preferred directory:~/Downloads However due to data loss of the blog, i decide to rewrite this article using Linux Mint Debian Editi on ( a similar distribution to Ubuntu ). First we have to download the source from Github (https://github.com/openSUSE/imagewriter) Download ZIP, save to preferred directory: ~/Downloads Extract imagewriter-master.zip in /home/username/Downloads and in terminal run the command: cd /home/username/Downloads/imagewriter-master Install the latest version of qt4-qmake and libqt4-dev by running: sudo apt-get update && sudo apt-get install qt4-qmake libqt4-dev Instructions for Linux Installation on github Follow the instructions in README.md by running the command: qmake DEFINES=USEHAL imagewriter.pro  Follow by the command: qmake DEFINES=USEUDISKS imagewriter.pro Next run the command: qmake DEFINE

Fixing time on sysvinit and systemd

If you have a system that boot using different GNU/Linux init systems such as sysvinit (aka System 5) and systemd (aka System 500) in addition to proprietary Windows system, you may face incorrect time display on one of the aforementioned system. The difference in time display is dependent on the time difference of your location and the UTC time. Further complication may result from concept like Daylight Saving Time (DST). If the Bios is set to localtime, you may fix it in systemd boot system using 'timedatectl' command like: sudo timedatectl set-local-rtc 1 However, if you are using sysvinit and Bios is using localtime, you can set inform the system that local time is being used using 'hwclock' command like: sudo hwclock --localtime or to synchronize the hardware clock with system time and inform the system using: sudo hwclock --systohc --localtime If Bios is using UTC time, you may revert the change with 'timedatectl' like: sudo timedatectl set-lo