setclock.xml 2.7 KB

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