Linux From Scratch
Prev | Chapter 7. Creating system boot scripts | Next

# Creating the setclock script

The following script is only for real use when the hardware clock (also known as BIOS or CMOS clock) isn't set to GMT time. The recommended setup is setting the hardware clock to GMT and having the time converted to localtime using the /etc/localtime symbolic link. But if an OS is run that doesn't understand a clock set to GMT (most notable are Microsoft OS'es) a user might want to set the clock to localtime so that the time is properly displayed on those OS'es. This script will reset the kernel time to the hardware clock without converting the time using the /etc/localtime symlink.

If a user wants to use this script on the system even if the hardware clock is set to GMT, then the UTC variable below has to be changed to the value of 1.

`cat > setclock << "EOF"`
#!/bin/sh
# Begin /etc/init.d/setclock
#
# Include the functions declared in the /etc/init.d/functions file
# and include the variables from the /etc/sysconfig/clock file
#
source /etc/init.d/functions
source /etc/sysconfig/clock
#
# Right now we want to set the kernel clock according to the hardware
# clock, so we use the -hctosys parameter.
#
CLOCKPARAMS="--hctosys"
#
# If the UTC variable is set in the /etc/sysconfig/clock file, add the
# -u parameter as well which tells hwclock that the hardware clock is
# set to UTC time instead of local time.
#
case "$UTC" in
yes|true|1)
CLOCKPARAMS="$CLOCKPARAMS -u"
;;
esac
echo -n "Setting clock..."
/sbin/hwclock $CLOCKPARAMS
evaluate_retval
# End /etc/init.d/setclock
`EOF`

## Creating the /etc/sysconfig/clock file

Create a new file `/etc/sysconfig/clock` by running the following:

`cat > /etc/sysconfig/clock << "EOF"`
# Begin /etc/sysconfig/clock
UTC=1
# End /etc/sysconfig/clock
`EOF`

If the hardware clock (also known as BIOS or CMOS clock) is not set to GMT time, then the UTC variable in the /etc/sysconfig/clock file needs to be set to the value 0 (zero).

Prev | Home | Next
Creating the sendsignals script | Up | Creating the sysklogd script