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