setclock.xml 2.7 KB

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