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