init.d scripts

Get and discuss Scripts from other users
Post Reply
User avatar
aar3Angahqueiquibohc
Administrator
Posts: 20
Joined: Wed 9. Jul 2008, 20:38

init.d scripts

Post by aar3Angahqueiquibohc » Tue 23. Dec 2008, 22:35

Here comes a init.d script wich workes for me

/etc/init.d/undervolt (under gentoo don't know where other distros store their init.d scripts)

Code: Select all

#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

CUSTOM_VTABLE=" "
DEFAULT_VTABLE=" "
VTABLE_PATH=" "

depend()
{
  need localmount
  need logger
}


do_error()
{
  # Display an error
  # $1: Error message

  eerror $1
  eerror "see http://gentoo-wiki.com/HOWTO_Undervolt_a_Pentium_M_CPU for further information"
  eend 1
}

sysfs_check()
{
  # Check that the sysfs interface exists

  if [ -e ${VTABLE_PATH_0_3_X} ]; then
    VTABLE_PATH="${VTABLE_PATH_0_3_X}"
    CUSTOM_VTABLE="${CUSTOM_VTABLE_0_3_X}"
    DEFAULT_VTABLE="${DEFAULT_VTABLE_0_3_X}"
    return 0
  else
    if [ -e ${VTABLE_PATH_0_2_X} ]; then
      VTABLE_PATH="${VTABLE_PATH_0_2_X}"
      CUSTOM_VTABLE="${CUSTOM_VTABLE_0_2_X}"
      DEFAULT_VTABLE="${DEFAULT_VTABLE_0_2_X}"
      return 0
    else
      logger "Undervolt: SysFs table not found. Can't modify CPU voltages."
      eerror "SysFs voltage_table not found. Can't modify CPU voltage table."
      eerror "It seems that the undervolting patch has not been applied to the kernel"
      do_error "or that the file /etc/conf.d/undervolt is not correctly configured."
      return 1
    fi
  fi
}

einfo_tables()
{
  # display current table and a custom table
  # $1 : custom table to display

  # Display the voltage table currently used by the CPU
  einfo "Current table:     "`cat ${VTABLE_PATH} `

  # Display the custom voltage table
  einfo "Configured table:  ${1}"
}

set_custom_table()
{
  # Set a custom table through the sysfs interface
  # $1 : custom table to set

  # Display current table and custom table that will be set
  einfo_tables "${1}"

  # Write the custom voltage to the SysFS interface and display the
  # new voltage table that is now used by the CPU if there is no error
  echo "${1}" > ${VTABLE_PATH} && \
  einfo "Applied table:     "`cat ${VTABLE_PATH}`

  return $?
}

start()
{
  ebegin "Changing CPU voltages table"

  if [ "$IS_CONFIGURED" = "yes" ]; then
    sysfs_check || return 1

    set_custom_table "${CUSTOM_VTABLE}"
    eend $?
  else
    do_error "Custom voltage table is not configured. Check the file /etc/conf.d/undervolt"
  fi
}

# I think it is not necessary to switch to the default voltage table on shutdown
# But this init script provides that feature in case you don't agree.
stop()
{
  if [ "$SWITCH_BACK" = "yes" ]; then
    if [ "$IS_CONFIGURED" = "yes" ]; then
      ebegin "Switching back to default CPU voltage table"

      sysfs_check || return 1

      set_custom_table "${DEFAULT_VTABLE}"
      eend $?
    else
      do_error "Default voltage table is not configured. Check the file /etc/conf.d/undervolt"
    fi
  else
    ebegin "Not switching back to default CPU voltage table (disabled in configuration)"
    eend 0
  fi
}


/etc/conf.d/undervolt (or where your distro stores here autoincluded config file for the undervolt init.d script)

Code: Select all

# Path to the voltage table sysfs interface file
# The init script will detect which one of the 2 below file exists and use the correspond table
VTABLE_PATH_0_2_X="/sys/devices/system/cpu/cpu0/cpufreq/op_points_table"
VTABLE_PATH_0_3_X="/sys/devices/system/cpu/cpu0/cpufreq/phc_controls"

# Switch back to DEFAULT_VTABLE if undervoltage is stopped? [yes/no]
SWITCH_BACK="no"

# Default voltages that will be restored at shutdown if SWITCH_BACK=yes
# Linux PHC 0.2.x uses a table of Frequency:Voltage pairs
# Linux PHC 0.3.x uses a table of FID:VID pairs
#DEFAULT_VTABLE_0_2_X="798000:988,1064000:1116,1330000:1244,1596000:1356"
#DEFAULT_VTABLE_0_3_X="12:16 10:10 8:4 6:0"

# Custom voltages that will be applied at boot time
#CUSTOM_VTABLE_0_2_X="600000:700,800000:764,1000000:860,12000000:956"
#CUSTOM_VTABLE_0_3_X="12:16 10:10 8:4 6:0"

# Set the following to "yes" when the all the settings are configured
# This is a safety to disable setting the voltages with the default
# values of this file that are probably wrong for your CPU
IS_CONFIGURED="no"


hopefully there are no errors in it if something wont work please open a thread in the help forum

mfg the Gnom
Life is sometimes just like a bad computer game, bad story but very nice graphics.

if you have questions meet me (DonGnom) (almost daily) in #linux-phc on irc.freenode.net.

oOarthurOo
Posts: 14
Joined: Mon 17. Nov 2008, 10:18

Re: init.d scripts

Post by oOarthurOo » Thu 24. Jun 2010, 04:11

Here is a link to my Debian (Squeeze) phc guide. An init.d script is included, as is required modifications to insserv.conf and a sleep.d script for pm-utils.

Corrections, improvements, etc., most welcome.

Post Reply