[6370fa6] | 1 | <sect1 id="ch07-setclock">
|
---|
| 2 | <title>Creating the setclock script</title>
|
---|
| 3 |
|
---|
| 4 | <para>
|
---|
[53b5ccf] | 5 | The following script is only for real use when the hardware clock (also
|
---|
[6370fa6] | 6 | known as BIOS or CMOS clock) isn't set to GMT time. The recommended
|
---|
[53b5ccf] | 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
|
---|
[6370fa6] | 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>
|
---|
[9a0cfdf] | 17 | If you want to use this script on your system even if the
|
---|
[53b5ccf] | 18 | hardware clock is set to GMT, then the UTC variable below has to be changed
|
---|
| 19 | to the
|
---|
[6370fa6] | 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)
|
---|
[def1992] | 51 | CLOCKPARAMS="$CLOCKPARAMS --utc"
|
---|
| 52 | ;;
|
---|
| 53 | no|false|0)
|
---|
| 54 | CLOCKPARAMS="$CLOCKPARAMS --localtime"
|
---|
[6370fa6] | 55 | ;;
|
---|
| 56 | esac
|
---|
| 57 |
|
---|
| 58 | echo -n "Setting clock..."
|
---|
| 59 | /sbin/hwclock $CLOCKPARAMS
|
---|
| 60 | evaluate_retval
|
---|
| 61 |
|
---|
| 62 | # End /etc/init.d/setclock
|
---|
| 63 | <userinput>EOF</userinput>
|
---|
| 64 | </literallayout>
|
---|
| 65 |
|
---|
| 66 | <sect2>
|
---|
| 67 | <title>Creating the /etc/sysconfig/clock file</title>
|
---|
| 68 |
|
---|
| 69 | <para>
|
---|
| 70 | Create a new file <filename>/etc/sysconfig/clock</filename> by running
|
---|
| 71 | the following:
|
---|
| 72 | </para>
|
---|
| 73 |
|
---|
| 74 | <literallayout>
|
---|
| 75 | <userinput>cat > /etc/sysconfig/clock << "EOF"</userinput>
|
---|
| 76 | # Begin /etc/sysconfig/clock
|
---|
| 77 |
|
---|
| 78 | UTC=1
|
---|
| 79 |
|
---|
| 80 | # End /etc/sysconfig/clock
|
---|
| 81 | <userinput>EOF</userinput>
|
---|
| 82 | </literallayout>
|
---|
| 83 |
|
---|
| 84 | <para>
|
---|
[53b5ccf] | 85 | If the hardware clock (also known as BIOS or CMOS clock) is not set to
|
---|
| 86 | GMT time, then the UTC variable in the /etc/sysconfig/clock file needs to be
|
---|
| 87 | set to
|
---|
[6370fa6] | 88 | the value <emphasis>0</emphasis> (zero).
|
---|
| 89 | </para>
|
---|
| 90 |
|
---|
[9a0cfdf] | 91 | <para>
|
---|
| 92 | Now, you may want to take a look at a very good hint explaining <ulink
|
---|
| 93 | url="http://archive.linuxfromscratch.org/lfs-hints/Time.txt">how we deal with
|
---|
| 94 | time on LFS</ulink>. It explains issues such as timezones, UTC, and the TZ
|
---|
| 95 | environment variable.
|
---|
| 96 | </para>
|
---|
| 97 |
|
---|
[6370fa6] | 98 | </sect2>
|
---|
| 99 |
|
---|
| 100 | </sect1>
|
---|
| 101 |
|
---|