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