setclock.xml 2.5 KB

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