Home page of this blog

Monday, April 7, 2008

Harddrive killer bug, workaround for Ubuntu Hardy Heron

I installed Ubuntu Hardy Heron Beta in my laptop to test. I installed smartmontools and checked if the load cycle count increases. It did not increase until I did a suspend/resume which works very well in Ubuntu. I googled to find a fix for the high frequency of load cycle count after suspend and resume. Since Ubuntu Hardy uses pm utils the ugly fix from ubuntu demon did not seem to work. http://ubuntuforums.org/showpost.php?p=3675960&postcount=26 I found two links from novel bugzilla and redhat bugzilla https://bugzilla.novell.com/show_bug.cgi?id=338230 https://bugzilla.redhat.com/show_bug.cgi?id=382061 I integrated the above two fixes in three shell script files. I copied the three script files into /etc/pm/config.d, /etc/pm/power.d, /etc/pm/sleep.d and tested suspend/resume Surprise, the fix started working in Ubuntu Hardy Heron Beta The script names are pm-disk, diskpr and disksr The following is my effort to explain what I did and where to copy the scripts to make it work Configuration Script taken from Novel Bugzilla Link: pm-disk --> same script which is found in novel bugzilla (power management config script), to be copied into /etc/pm/config.d/ create a file called pm-disk with the following contents
# Configure disk power management settings to ensure both
# long disk life and good power management.
#
# Space delimited list of disk devices this affects.
#
DEVICES_DISK_PM_NAMES="/dev/sda"
#
#
# Power management modes
#
# Powersave mode off
#  Disable APM and spin-down
#
DEVICES_DISK_PM_POWERSAVE_OFF="hdparm -q -B 255 -q -S 0"
#
# Powersave mode on
# Enable APM to conservative 200 and set spin-down for 21 minutes
#
DEVICES_DISK_PM_POWERSAVE_ON="hdparm -q -B 200 -q -S 252"
give the file executable permission, chmod +x pm-disk from the folder where the script is saved. Just copy the script to /etc/pm/config.d/ using the following command. Thanks to comments from "Hai", there is no need to give executable permission to pm-disk source
sudo cp pm-disk /etc/pm/config.d/
Action Script for Power Management taken from Novel Bugzilla Link: diskpr --> renamed script disk to diskpr meaning actionscript for disk power(power management switch from AC to Battery), to be copied into /etc/pm/power.d/ create a file called diskpr with the following contents (Correction: the 3rd line of the following script was using . /etc/pm/config.d/disk and changed to use . /etc/pm/config.d/pm-disk, Thanks to comments from "Hai" (see comments 3 to 5))
#!/bin/bash
. /usr/lib/pm-utils/functions
. /etc/pm/config.d/pm-disk


if test -z ${DEVICES_DISK_PM_NAMES}; then
        exit 1
fi

case "$1" in
        true)
                echo "**enabled pm for harddisk"
                for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
                        ${DEVICES_DISK_PM_POWERSAVE_ON} ${DISK_NAME}
                done ;;
        false)
                echo "**disabled pm for harddisk"
                for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
                        ${DEVICES_DISK_PM_POWERSAVE_OFF} ${DISK_NAME}
                done ;;
esac
give the file executable permission, chmod +x diskpr from the folder where the script is saved. Copy the script to /etc/pm/power.d/ using the following command
sudo cp diskpr /etc/pm/power.d/
sudo chmod +x /etc/pm/power.d/diskpr
Suspend/Resume handling Script adopted based on Redhat Bugzilla Link: disksr --> the script is created with a slight modification to adapt the one like suse script for handling suspend/resume and named disksr (sr stands for suspend resume), to be copied into /etc/pm/sleep.d/ create a file called disksr with the following contents (Correction: the 3rd line of the following script was using . /etc/pm/config.d/disk and changed to use . /etc/pm/config.d/pm-disk, Thanks to comments from "Hai" (see comments 3 to 5))
#!/bin/bash
. /usr/lib/pm-utils/functions
. /etc/pm/config.d/pm-disk



if test -z ${DEVICES_DISK_PM_NAMES}; then
        exit 1
fi

case "$1" in
        hibernate|suspend)
                echo "**enabled pm for harddisk"
                for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
                        ${DEVICES_DISK_PM_POWERSAVE_ON} ${DISK_NAME}
                done ;;
        thaw|resume)
                echo "**disabled pm for harddisk"
                for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
                        ${DEVICES_DISK_PM_POWERSAVE_OFF} ${DISK_NAME}
                done ;;
esac
give the file executable permission, chmod +x disksr from the folder where the script is saved. Copy the script to /etc/pm/sleep.d/ using the following command
sudo cp disksr /etc/pm/sleep.d/
sudo chmod +x /etc/pm/sleep.d/disksr
Many thanks to Redhat, Novel Bugzilla and Ubuntuforums which helped get this fix work for Ubuntu Hardy Heron Beta (I am using Ubuntu Hardy Heron now) in my laptop Hope the scripts will work for you if you use Ubuntu Hardy Heron or latest Fedora or openSUSE.
 Corrections

 1. No need to add executable rights to pm-disk config script.
    Thanks to comments from "Hai"

 2. Change the disksr and diskpr  files
   to include /etc/pm/config.d/pm-disk instead
   of /etc/pm/config.d/disk. Thanks to comments from "Hai"

 3. To have a default hdparm value of 254 or 255 set and
   standby value to 0, without calling these scripts initially,
   change the values in /etc/acpi/power.sh In the
   script /etc/acpi/power.sh which is present
   by default in Ubuntu Hardy 8.04, I changed the
   function laptop_mode_disable as follows







function laptop_mode_disable {
    for x in /sys/bus/ide/devices/*/block*; do
    drive=$(basename $(readlink $x));
    $HDPARM -S 0 /dev/$drive 2>/dev/null
    $HDPARM -B 255 /dev/$drive 2>/dev/null
    done
    for x in /sys/bus/scsi/devices/*/block*; do
    drive=$(basename $(readlink $x));
    $HDPARM -S 0 /dev/$drive 2>/dev/null
    $HDPARM -B 255 /dev/$drive 2>/dev/null
    done
    $LAPTOP_MODE stop
}
The change includes passing 255 (or 254 if 255 does not work for you) after -B and 0 after -S

P.S:I am very new to blogging eventhough I am using linux distros in my PC/Laptop for more than three years, so there will be mistakes and typo, which I hope you will not mind

9 comments:

  1. Hi,

    Very nice your post. It seems that people working with ubuntu hardy forgot about this problem. I have a questio: for your workaround to work all that is needed is to create these scripts and to save them to correct directories? I mean, shouldn't one enable pm-utils?

    Many thanks
    Thiago

    ReplyDelete
  2. Hi,

    Hardy uses pm-utils by default. It should work if you create and place scripts mentioned in my blog.

    Also Hardy you can edit various params in laptopmode.conf to avert harddrive killer bug. for how to apply this fix follow

    https://launchpad.net/ubuntu/+source/acpi-support/+bug/59695/comments/63

    for step by step tutorial

    http://vale.homelinux.net/wordpress/2007/10/24/potential-risk-for-your-nx6325s-harddrive/

    I am eagerly waiting for Hardy release and seriously hope this bugs will be fixed without manual tweaking.

    Regards,
    Sankaran

    ReplyDelete
  3. Great! It've worked for me, however you have small mistakes:
    1. You call config script /etc/pm/config.d/pm-disk, but sourcing /etc/pm/config.d/disk (note the missing "pm-") from your actual hook files. That's why your solution does not work out of the box.
    2. No need to chmod 755 config script - its only sourced.

    ReplyDelete
  4. Another comment for the record:
    On my dell XPS m1330 I've used these config values:
    # Powersave mode off
    # Disabling APM (-B 255) does not work - using -B 254
    # spin-down set to 1 hour.
    #
    DEVICES_DISK_PM_POWERSAVE_OFF="hdparm -q -B 254 -q -S 242"
    #
    # Powersave mode on
    # Enable APM to conservative 200 and set spin-down for 21 minutes
    #
    DEVICES_DISK_PM_POWERSAVE_ON="hdparm -q -B 200 -q -S 252"

    ReplyDelete
  5. Another problem: non of these script is called on system boot (whether I'm on AC or on battery). I have to replug AC power each time I boot to trigger them :)

    ReplyDelete
  6. "Hai", I changed the blog to reflect your findings and tried to correct as told by you. Thanks a lot for the pointing the bugs in the script.

    Also as a resolution for scripts not getting called by default, no need to unplug/replug power. Just change /etc/acpi/power.sh to reflect your hdparm values. This also I tried to add in the blog towards the end.

    Thanks,
    Sankaran

    ReplyDelete
  7. "Hai", I changed the blog to reflect your findings and tried to correct as told by you. Thanks a lot for pointing the bugs in the script.

    Also as a resolution for scripts not getting called by default, no need to unplug/replug power. Just change /etc/acpi/power.sh to reflect your hdparm values. This also I tried to add in the blog towards the end.

    Thanks,
    Sankaran
    P.S: spelling/grammar correction

    ReplyDelete
  8. Changing /etc/acpi/power.sh as you pointed, did not help - hdd head cranks still here upon boot.

    ReplyDelete
  9. I have purchased a Dell xps m1330 laptop (I still dont get it), and planning to install ubuntu on it. Reading about the process I was directed to this thread. I wanted to ask:
    1. Is it recommended to fix this bug as you suggest? Or: is it dangerous to the HDD leaving settings as default?
    2. Is it better to correct it via laptop-mode?
    THX, Seba

    ReplyDelete