[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

enable hdparm at boot



After struggling with the shell for some time I have come up with the 
following modifications for /etc/hdparm.conf and /etc/init.d/hdparm.sh
that were suggested by Tommi Komulainen <Tommi.Komulainen@iki.fi>.
(Tommi Komulainen suggestions can be seen as bug report #87451.)

The following:
1) Does not uses /proc, which might not be available.
2) Can have comments in the configuration file.
3) A default config file is possible by commenting out every line. Thus
   the Debian maintainer can ship a default script which will do noting
   without the explicit intervention of the sysadmin.
4) The config file have 'undo' lines so that when entering single user
   mode from a production runlevel the configurations for the HDs will be
   undone.
5) When using
       update-rc.d default 05
   the script will not be run in single user mode.
6) CDROMs can be configured as well.
7) If desired the script can be further simplified by removing the
   verification of the HD model and/or removing the identify option.
   This changes might make it more sh, as opposed to bash, complaint,
   although I am not sure whether it is not sh compliant as it is.


[20:39:28 /tmp]$ cat /etc/hdparm.conf
#
# /etc/hdparm.conf
#
# Configuration file for /etc/init.d/hdparm.sh
# format: when:drive:model:params
# where
#   when Is either start or stop. Lines beginning with anything
#        else will be ignored. start will be used when entering
#        a runlevel and stop when leaving it. This way, all 
#        configurations will be undone after changing to single
#        user mode.
#   drive Is hda, hdb and so on.
#   model Should be the same as obtained using 
#             /etc/init.d/hdparm identify $drive
#         or * if you do not mind about verifying the drive.
#   params Are the required params. 
#

# Don't mind that hda model will not be verified.
#start:hda:*:-qu1
# But I want its configuration to be the same as before when
# changing to single user mode.
#stop:hda:*:-qu0

start:hda:WDC AC21200H:-qc1qk1qm8qu1
start:hdb:WDC AC33200L:-qc1qk1qm8qu1
start:hdc:TOSHIBA CD-ROM XM-6302B:-qc1qu1qk1qK1

stop:hda:WDC AC21200H:-qc0qk0qm0qu0
stop:hdb:WDC AC33200L:-qc0qk0qm0qu0
stop:hdc:TOSHIBA CD-ROM XM-6302B:-qc0qu0qk0qK0
[20:39:34 /tmp]$

[20:39:40 /tmp]$ cat /etc/init.d/hdparm.sh
#!/bin/sh -e
#
# /etc/init.d/hdparm.sh
# hdparm        Configure {E,}IDE drives with hdparm.
#

IFS=',=:
'
PATH=/sbin:/bin

[ -d /proc/ide ] || exit 0

case "$1" in
    start)
        [ -x /sbin/hdparm -a -e /etc/hdparm.conf ] || exit 0

        echo -n "Configuring drives:"
        cat /etc/hdparm.conf |
            while read line_mode drive model parms; do
                [ "$line_mode" != "start" ] && continue
	        hdparm -i /dev/$drive | grep Model | 
	        while read field Model rest; do :; done
                [ "$model" = "*" -o "$model" = "$Model" ] &&
                    hdparm $parms /dev/$drive
                echo -n " $drive"
            done
        echo "."
        ;;

    identify)
        if [ -z "$2" ]; then 
	    echo -n "Usage: /etc/init.d/hdparm drives "
	    echo "(hda hdb and such)."
	    exit 1
	fi
	shift 1
        for drive in "$@"; do
	    hdparm -i /dev/$drive | grep Model | 
	        while read field model rest; do
		    echo "$drive":"$model"
		    shift
		done
        done
        ;;

    stop)
        [ -x /sbin/hdparm -a -e /etc/hdparm.conf ] || exit 0

        echo -n "Disconfiguring drives:"
        cat /etc/hdparm.conf |
            while read line_mode drive model parms; do
                [ "$line_mode" != "stop" ] && continue
	        hdparm -i /dev/$drive | grep Model | 
	        while read field Model rest; do :; done
                [ "$model" = "*" -o "$model" = "$Model" ] &&
                    hdparm $parms /dev/$drive
                echo -n " $drive"
            done
        echo "."
        ;;
	
    *)
        echo "Usage: /etc/init.d/hdparm {start|stop|identify devices}" >&2
        exit 1
        ;;
esac

exit 0
[20:39:47 /tmp]$

-- 
	
	Shaul Karl <shaulka@bezeqint.net>



Reply to: