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