setclock.xml 2.8 KB

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