setclock.xml 2.7 KB

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