Defragging Linux Drive

One of the stable FOSS program for defragging Linux formatted drive is defragfs.

Download and extract the zip file and copy the “defragfs” perl script file to /usr/local/bin.

The command to use:

cd /usr/local/bin
sudo perl ./defragfs /path/you/want/defrag

An example is the following defragmentation of a activated drive on my PC.

Posted in Uncategorized | Leave a comment

Hdparm, Load_Cycle_Count and Samsung HM641JI and Seagate ST320LT022

Previously i have written about controlling the increment of load cycle count of my Samsung harddrive running Fedora and LMDE. In this post, i must admit i have included many redundant steps to tune the harddrive setting  to control Load_Cycle_Count.

In this series, i am writing further about controlling the load cycle count of my external Seagate harddrive to ensure that the harddrive do not suffer an early death.

In this first section, i am running OpenSUSE Leap 42.1 on my external Seagate harddrive. As this new hybrid consumer-enterprise distribution (i.e OpenSUSE Leap) works like Fedora (another RPM-based dristribution), I created a systemd service named hdsilence.service to run at boot up. This service allows me to spin down my idling internal harddrive and keep my external harddrive spinning. To refresh our memory, we execute the command  
ls /dev/disk/by-id/*  
to retrieve the model and serial of all harddrives attached to our workstation.

Below is the contents 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 254 -S 251 /dev/disk/by-id/ata-Seagate_Model_Serial
# Enable automatic spin down after 30 seconds for the second, infrequently used disk
ExecStart=/sbin/hdparm -B 127 -S 12 /dev/disk/by-id/ata-Samsung_Model_Serial

[Install]
WantedBy=suspend.target basic.target

To get a sense of the syntax of systemd service, you may refer to archlinux Archwiki (https://wiki.archlinux.org/index.php/Systemd) which provides a comprehensive introduction to systemd. I am sure this article is interesting for beginners and experienced linux users 🙂

In the second section, i am running Ubuntu and Sparkylinux on my external Seagate harddrive.

I edited hdparm.conf in the directory /etc/hdparm.conf as advised in the previous post.

The edited hdparm.conf includes the following details:

# Root file systems.  Please see README.Debian for details
ROOTFS = /dev/disk/by-id/ata-Samsung_Model_Serial


/dev/disk/by-id/ata-Samsung_Model_Serial {
     apm = 254
     spindown_time = 251
#    dma = on
}


Notice that the dma option is commented (with #). You may experiment with uncommenting it ( by removing #) with caution as it work on some workstations but not on mine.

In addition, i created a new rule called 50-hdparm.rules in /etc/udev/rules.d.

50-hdparm.rules include one statement for putting my idling Samsung harddrive to sleep that is similar to hdsilence.service and keeping my working external Seagate harddrive chugging along. 

50-hdparm.rules shall include the following statements:

ACTION==”add”, SUBSYSTEM==”block”, KERNEL==”sdb”, RUN+=”/usr/sbin/hdparm -B 254 –prefer-ata12 -S 251 /dev/disk/by-id/ata-Seagate_Model_Serial”

ACTION==”add|change”, KERNEL==”sda”, ATTR{queue/rotational}==”1″, RUN+=”/usr/sbin/hdparm -B 127 -S 12 /dev/disk/by-id/ata-Samsung_Model_Serial”


To ensure that the load cycle count is managed successfully, please check the temperature of the harddrive by running the command
sudo smartctl -A /dev/disk/by-id/ata-Samsung_Model_Serial | grep -E “Load_Cycle|ID| Power_On|Temp”

The command is used to check Load_Cycle-Count, Power_On_Hours and Temperature_Celsius.

Please be advised that i am not responsible for any system failure in your workstation should you follow my procedures above as different workstations has their own unique settings. You are advised to exercise due diligence before attempting the steps above.

Please feel free to share your experience in tuning your harddrive to avoid harddrive crash.

Posted in Uncategorized | Leave a comment

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=251

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:

#! /bin/bash
#Utility that checks whether the APM level is at 254 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 != “254” ]] ; then
           hdparm -B 254 /dev/sda
     fi

sleep ${SLEEP}s
done

#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=”254 254″
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 254 /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 = 254
     spindown_time = 251
     dma = on  #i have commented the option dma as there is a warning during  

                      #my 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: 254
       *    Advanced Power Management ature 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 254 -S 251 /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”

 

Posted in Uncategorized | Leave a comment

Installing SUSE Imagewriter on Linux Mint Debian Edition

The original title for this post is “Installing SUSE Imagewriter on Ubuntu LTS”.

However due to data loss of the blog, i decide to rewrite this article using Linux Mint Debian Edition ( a similar distribution to Ubuntu).

First we have to download the source from Github (https://github.com/openSUSE/imagewriter)

Click Download ZIP and save to your preferred directory such as /home/username/Downloads












Extract imagewriter-master.zip in /home/username/Downloads and in terminal run the command:

cd /home/username/Downloads

Install the latest version of qt4-qmake and libqt4-dev by running:

sudo apt-get update && sudo apt-get install qt4-qmake libqt4-dev

Near the bottom of the Github page are the instructions for Linux Installation

  

Follow the instructions in README.md by running the command:

qmake DEFINES=USEHAL imagewriter.pro 

Then run the command:


qmake DEFINES=USEUDISKS imagewriter.pro


Next run the command:

qmake DEFINES=USEUDISKS2 imagewriter.pro
 
The following warning message can be safely ignored for the qmake commands:
/home/username/Downloads/imagewriter-master/imagewriter.pro:87: Unescaped backslashes are deprecated. 

Run the command:
 

make 

to recompile SUSE Imagewriter 

Finally, run the command:
 
sudo make install 

to install SUSE Imagewriter.

While running the command make, there may be missing packages. Troubleshoot the error messages by installing the missing packages using apt-get or your preferred package manager.

To give permission to run SUSE Imagewriter as Superuser,run the following command:

sudo xhost +SI:localuser:root

Congratulations! Start SUSE Imagewriter to burn .iso images to USB devices by running the command:

 sudo DISPLAY=:0 imagewriter

SUSE Imagewriter in operation

 
 

 

 



Posted in Uncategorized | Leave a comment