setclock.xml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <sect1 id="ch07-setclock">
  2. <title>Creating the setclock script</title>
  3. <?dbhtml filename="setclock.html" dir="chapter07"?>
  4. <para>The following script is only for real use when the hardware clock (also
  5. known as BIOS or CMOS clock) isn't set to GMT time. The recommended
  6. setup is setting the hardware clock to GMT and having the time converted
  7. to localtime using the /etc/localtime symbolic link. But if an
  8. OS is run that doesn't understand a clock set to GMT (most notable are
  9. Microsoft OS'es) you may want to set the clock to localtime so that
  10. the time is properly displayed on those OS'es. This script will then
  11. set the kernel time to the hardware clock without converting the time using
  12. the /etc/localtime symlink.</para>
  13. <para>Create the <filename>/etc/init.d/setclock</filename> script by running
  14. the following command:</para>
  15. <para><screen><userinput>cat &gt; /etc/init.d/setclock &lt;&lt; "EOF"</userinput>
  16. #!/bin/sh
  17. # Begin /etc/init.d/setclock
  18. #
  19. # Include the functions declared in the /etc/init.d/functions file
  20. # and include the variables from the /etc/sysconfig/clock file
  21. #
  22. source /etc/init.d/functions
  23. source /etc/sysconfig/clock
  24. #
  25. # Right now we want to set the kernel clock according to the hardware
  26. # clock, so we use the -hctosys parameter.
  27. #
  28. CLOCKPARAMS="--hctosys"
  29. #
  30. # If the UTC variable is set in the /etc/sysconfig/clock file, add the
  31. # -u parameter as well which tells hwclock that the hardware clock is
  32. # set to UTC time instead of local time.
  33. #
  34. case "$UTC" in
  35. yes|true|1)
  36. CLOCKPARAMS="$CLOCKPARAMS --utc"
  37. ;;
  38. no|false|0)
  39. CLOCKPARAMS="$CLOCKPARAMS --localtime"
  40. ;;
  41. esac
  42. echo -n "Setting clock..."
  43. /sbin/hwclock $CLOCKPARAMS
  44. evaluate_retval
  45. # End /etc/init.d/setclock
  46. <userinput>EOF</userinput></screen></para>
  47. <sect2>
  48. <title>Creating the /etc/sysconfig/clock file</title>
  49. <para>If you want to use this script on your system even if the
  50. hardware clock is set to GMT, then the UTC variable below has to be
  51. changed to the value of <emphasis>1</emphasis>.</para>
  52. <para>Create a new file <filename>/etc/sysconfig/clock</filename> by running
  53. the following:</para>
  54. <para><screen><userinput>cat &gt; /etc/sysconfig/clock &lt;&lt; "EOF"</userinput>
  55. # Begin /etc/sysconfig/clock
  56. UTC=0
  57. # End /etc/sysconfig/clock
  58. <userinput>EOF</userinput></screen></para>
  59. <para>Now, you may want to take a look at a very good hint explaining how we
  60. deal with time on LFS at <ulink
  61. url="&hints-root;time.txt">&hints-root;time.txt</ulink>.
  62. It explains issues such as timezones, UTC, and the TZ
  63. environment variable.</para>
  64. </sect2>
  65. </sect1>