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