1 | <sect1 id="ch07-setclock">
|
---|
2 | <title>Creating the setclock script</title>
|
---|
3 |
|
---|
4 | <para>
|
---|
5 | The following script is only for real use when the hardware clock (also
|
---|
6 | known as BIOS or CMOS clock) isn't set to GMT time. The recommended
|
---|
7 | setup is setting the hardware clock to GMT and having the time converted
|
---|
8 | to localtime using the /etc/localtime symbolic link. But if an
|
---|
9 | OS is run that doesn't understand a clock set to GMT (most notable are
|
---|
10 | Microsoft OS'es) a user might want to set the clock to localtime so that
|
---|
11 | the time is properly displayed on those OS'es. This script will reset
|
---|
12 | the kernel time to the hardware clock without converting the time using
|
---|
13 | the /etc/localtime symlink.
|
---|
14 | </para>
|
---|
15 |
|
---|
16 | <para>
|
---|
17 | If a user wants to use this script on the system even if the
|
---|
18 | hardware clock is set to GMT, then the UTC variable below has to be changed
|
---|
19 | to the
|
---|
20 | value of <emphasis>1</emphasis>.
|
---|
21 | </para>
|
---|
22 |
|
---|
23 | <literallayout>
|
---|
24 | <userinput>cat > setclock << "EOF"</userinput>
|
---|
25 | #!/bin/sh
|
---|
26 | # Begin /etc/init.d/setclock
|
---|
27 |
|
---|
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 |
|
---|
33 | source /etc/init.d/functions
|
---|
34 | source /etc/sysconfig/clock
|
---|
35 |
|
---|
36 | #
|
---|
37 | # Right now we want to set the kernel clock according to the hardware
|
---|
38 | # clock, so we use the -hctosys parameter.
|
---|
39 | #
|
---|
40 |
|
---|
41 | CLOCKPARAMS="--hctosys"
|
---|
42 |
|
---|
43 | #
|
---|
44 | # If the UTC variable is set in the /etc/sysconfig/clock file, add the
|
---|
45 | # -u parameter as well which tells hwclock that the hardware clock is
|
---|
46 | # set to UTC time instead of local time.
|
---|
47 | #
|
---|
48 |
|
---|
49 | case "$UTC" in
|
---|
50 | yes|true|1)
|
---|
51 | CLOCKPARAMS="$CLOCKPARAMS -u"
|
---|
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>
|
---|
61 | </literallayout>
|
---|
62 |
|
---|
63 | <sect2>
|
---|
64 | <title>Creating the /etc/sysconfig/clock file</title>
|
---|
65 |
|
---|
66 | <para>
|
---|
67 | Create a new file <filename>/etc/sysconfig/clock</filename> by running
|
---|
68 | the following:
|
---|
69 | </para>
|
---|
70 |
|
---|
71 | <literallayout>
|
---|
72 | <userinput>cat > /etc/sysconfig/clock << "EOF"</userinput>
|
---|
73 | # Begin /etc/sysconfig/clock
|
---|
74 |
|
---|
75 | UTC=1
|
---|
76 |
|
---|
77 | # End /etc/sysconfig/clock
|
---|
78 | <userinput>EOF</userinput>
|
---|
79 | </literallayout>
|
---|
80 |
|
---|
81 | <para>
|
---|
82 | If the hardware clock (also known as BIOS or CMOS clock) is not set to
|
---|
83 | GMT time, then the UTC variable in the /etc/sysconfig/clock file needs to be
|
---|
84 | set to
|
---|
85 | the value <emphasis>0</emphasis> (zero).
|
---|
86 | </para>
|
---|
87 |
|
---|
88 | </sect2>
|
---|
89 |
|
---|
90 | </sect1>
|
---|
91 |
|
---|