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