Précédent Remonter Suivant

11  Performances disque dur

J'ai rajouté ce script /etc/init.d/hdparm :
#!/bin/sh

set -e

#In certian cases you may wish to run this script twice.  Once at S07
#and once later in the boot process. If you do this call /etc/init.d/hdparm
#again from rcS.d with a name such as S27hdparm.second.
#
#See /usr/share/doc/hdparm/README.Debian for more details.

case "$0" in
  *hdparm)
    FIRST=yes
    ;;
  *)
    FIRST=no
    ;;
esac

MYNAME="$0"

report()
{
  echo "${MYNAME}: $*"
}

report_error()
{
  echo "${MYNAME}: Error: $*" >&2
}

report_error_and_exit()
{
  report_error "$*.  Exiting."
  exit 1
}

case $1 in
  start|restart|reload|force-reload)
    ;;
  stop) 
    exit 0
    ;;
  *)
    echo "Usage: $MYNAME {stop|start|restart|reload|force-reload}" >&2
    exit 3
    ;;
esac

if [ "$FORCE_RUN" != 'yes' ]; then
  if grep -w -q "nohdparm" /proc/cmdline ; then
    report "*** Skipping setup of disc parameters. ***"
    exit 0
  fi
  
  raidstat=OK
  if [ -e /proc/mdstat ]; then
    if grep -iq resync /proc/mdstat; then
      raidstat=RESYNC
    fi
  elif [ -e /proc/rd/status ]; then
    raidstat=`cat /proc/rd/status`
  fi
  
  if ! [ "$raidstat" = 'OK' ]; then
    report_error "*** RAID status not OK.  Exiting. ***"
    exit 0
  fi
fi

echo -n "Setting parameters of disc:"

DISC=
DEFAULT=
OPTIONS=
DEF_QUIET=
OPT_QUIET=

#  set_option() adds $1 to the $OPTIONS list if in a disk stanza
#             and adds $1 to the $DEFAULT list if not in a disk stanza
#
#  the block beginning:
#        if test x${i%${i#??}} != x${1%${1#??}}; then
#  checks to see if $1 is already in the list and
#    if so removes the first instance

set_option() 
{
  if test -n "$DISC"; then
    NEW_OPT=
    for i in $OPTIONS; do
      if test x${i%${i#??}} != x${1%${1#??}}; then
        NEW_OPT="$NEW_OPT $i"
      else
        NEW_OPT=${NEW_OPT%-q}
      fi
    done
    OPTIONS="$NEW_OPT $OPT_QUIET $1"
  else
    NEW_DEF=
    for i in $DEFAULT; do
      if test x${i%${i#??}} != x${1%${1#??}}; then
        NEW_DEF="$NEW_DEF $i"
      else
        NEW_DEF=${NEW_DEF%-q}
      fi
    done
    DEFAULT="$NEW_DEF $DEF_QUIET $1"
  fi
}

eval_value() 
{
  case $1 in
    off|0) 
      set_option "$2"0
       ;;
    on|1) 
      set_option "$2"1
      ;;
    *) 
      return 1
      ;;
  esac
}

ITEMS_ECHOED=no

# Get blocks as far as the drive's write cache.
/bin/sync

# Set options for a group of disks in /etc/default/hdparm
[ -e /etc/default/hdparm ] && . /etc/default/hdparm

if [ -n "$harddisks" -a -n "$hdparm_opts" ]; then
  for drive in $harddisks; do 
    /sbin/hdparm -q -f $drive
    hdparm -q $hdparm_opts -q $drive
    if [ "$ITEMS_ECHOED" = yes ] ; then
      echo -n ", $drive"
    else
      echo -n " $drive"
      ITEMS_ECHOED=yes
    fi
  done
fi

egrep -v '^[[:space:]]*(#|$)' /etc/hdparm.conf | 
{
  while read KEY SEP VALUE; do
    if [ "$NEXT_LINE" != 'go' ]; then
      case $SEP in
        '{')
          case $KEY in
            command_line)
              NEXT_LINE=go
              unset DISC
              unset OPTIONS
              unset OPT_QUIET
              ;;
            *)
              DISC=$KEY
              OPTIONS=$DEFAULT
              OPT_QUIET=$DEF_QUIET
              WAS_RUN=0
              ;;
          esac
          ;;
        =)
          case $KEY in
            read_ahead_sect) 
              set_option -a$VALUE
              ;;
            lookahead) 
              eval_value $VALUE -A
              ;;
            bus) 
              eval_value $VALUE -b
              ;;
            apm) 
              set_option -B$VALUE
              ;;
            io32_support) 
              set_option -c$VALUE
              ;;
            dma) 
              eval_value $VALUE -d
              ;;
            defect_mana) 
              eval_value $VALUE -D
              ;;
            cd_speed) 
              set_option -E$VALUE
              ;;
            mult_sect_io) 
              set_option -m$VALUE
              ;;
            prefetch_sect) 
              set_option -P$VALUE
              ;;
            read_only) 
              eval_value $VALUE -r
              ;;
            spindown_time) 
              set_option -S$VALUE
              ;;
            interrupt_unmask) 
              eval_value $VALUE -u
              ;;
            write_cache) 
              eval_value $VALUE -W
              ;;
            transfer_mode) 
              set_option -X$VALUE
              ;;
            acoustic_management)
              set_option -M$VALUE
              ;;
            keep_settings_over_reset)
              eval_value $VALUE -k
             ;;
            keep_features_over_reset)
              eval_value $VALUE -K
             ;;
            chipset_pio_mode)
              set_option -p$VALUE
             ;;
            ROOTFS)
              ROOTFS=$VALUE
             ;; 
            *)
              report_error_and_exit "unknown option $KEY"
              ;;
          esac
          ;;
        "")
          case $KEY in
            '}')
              if [ -z "$DISC" ]; then
                if [ "$WAS_RUN" != '1' ]; then
                  report_error_and_exit "No disk enabled. Exiting"
                fi
              fi
              if [ -n "$OPTIONS" ]; then
                if [ -b "$DISC" ]; then
                  if [ -n "$ROOTFS" ]; then
                    if [ "$FIRST" = 'yes' -a "$DISC" != "$ROOTFS" ]; then
                      continue
                    fi
                    if [ "$FIRST" = 'no' -a "$DISC" = "$ROOTFS" ]; then
                      continue
                    fi
                  fi
                  # Flush the drive's internal write cache to the disk.
                  /sbin/hdparm -q -f $DISC
    
                  /sbin/hdparm $OPTIONS $DISC
                  if [ "$ITEMS_ECHOED" = yes ] ; then
                    echo -n ", $DISC"
                  else
                    echo -n " $DISC"
                    ITEMS_ECHOED=yes
                  fi
                fi
              fi       
              ;;
            quiet)
              if [ -n "$DISC" ]; then
                OPT_QUIET=-q
              else
                DEF_QUIET=-q
              fi
              ;;
            standby) 
              set_option -y
              ;;
            sleep) 
              set_option -Y
              ;;
            disable_seagate) 
              set_option -Z
              ;;
            *)
              report_error_and_exit "unknown option $KEY"
              ;;
          esac
          ;;
       *)
         report_error_and_exit "unknown separator $SEP"
         ;;
      esac
    else
      $KEY $SEP $VALUE
      NEXT_LINE=no-go
      WAS_RUN=1
    fi
  done
    
  if [ "$ITEMS_ECHOED" = yes ] ; then
    echo "."
  else
    echo " (none)."
  fi
}
Puis faire ``chmod 755 /etc/init.d/hdparm ; update-rc.d start hdparm 60 S .''.


Précédent Remonter Suivant