Menu Based - Time changing Script

Tuesday, July 7, 2009 |

I was working with few testers who need to change the system time occasionally on a linux box. Most of the time, they had problem while issuing the date command. Below one is a menu based shell script to update time on a linux box (xen guest in this case)

#!/bin/bash

Author : basil@
Purpose : Menu based date/time change of Linux boxes with ntpdate
Date : 04-20-2009

# Below kernel parameter is to allow xen guest take independent decision about its clock.

echo 1 > /proc/sys/xen/independent_wallclock

while :
do
clear
echo "-------------------------------------"
echo " Main Menu "
echo "-------------------------------------"
echo "[1] Show Todays date/time"
echo "[2] Change System time"
echo "[3] Show calendar"
echo "[4] Change System time to Current time"
echo "[5] Exit/Stop"
echo "======================="
echo -n "Enter your menu choice [1-5]: "
read yourch

case $yourch in
1) echo "Today is `date` , press Enter/Return key. . ." ; read ;;
2) echo "Enter new date and time [Format: MMDDHHMMYYYY]: ";read newtime ; date $newtime;echo "Today is `date`, , press Enter/Return key. . ." ; read ;;
3) /usr/bin/cal; echo "Press a key. . ." ; read ;;
4) echo "Updating to Current time..."; `/usr/sbin/ntpdate -s clock.redhat.com`;echo "Today is `date`, , press Enter/Return key. . ." ; read ;;
5) exit 0 ;;
*) echo "Opps!!! Please select choice 1,2,3 or 4";
echo "Press Enter/Return key. . ." ; read ;;

esac
done

Time Sync issues - VMware Guest Hosts

Monday, July 6, 2009 |




I was damn tired of time sync issues related to guest hosts running on top of VMware ESX 3.5 host. Even though I have installed ntp client on all the servers, but still the guest OS's are running out of Sync.





NTP Recommendations

Note: In all cases use NTP instead of VMware Tools periodic time synchronization. Also, you may need to open the firewall (UPD 123) to allow NTP traffic.
The following is a sample /etc/ntp.conf :
tinker panic 0
restrict 127.0.0.1
restrict default kod nomodify notrap
server 0.vmware.pool.ntp.org
server 1.vmware.pool.ntp.org
server 2.vmware.pool.ntp.org
driftfile /var/lib/ntp/drift
The following is a sample /etc/ntp/step-tickers :
0.vmware.pool.ntp.org
1.vmware.pool.ntp.org
The configuration directive tinker panic 0 instructs NTP not to give up if it sees a large jump in time. This is important for coping with large time drifts and also resuming virtual machines from their suspended state.
Note: The directive tinker panic 0 must be at the top of the ntp.conf file.
It is also important not to use the local clock as a time source, often referred to as the Undisciplined Local Clock. NTP has a tendency to fall back to this in preference to the remote servers when there is a large amount of time drift.
An example of such a configuration is:
server 127.127.1.0
fudge 127.127.1.0 stratum 10
Comment out both lines.
After making changes to NTP configuration, the NTP daemon must be restarted. Refer to your operating system vendor’s documentation.

VMware Tools time synchronization configuration

When using NTP in the guest, disable VMware Tools periodic time synchronization.
To disable VMware Tools periodic time sync you use one of the following options:
  1. Set tools.syncTime = "0" in the configuration file (.vmx file) of the virtual machine.

    OR

  2. Deselect Time synchronization between the virtual machine and the host operating system in the VMware Tools toolbox GUI of the guest operating system.

    OR

  3. Run the vmware-guestd --cmd "vmx.set_option synctime 1 0" command in the guest operating system.
These options do not disable one-time synchronizations done by VMware Tools for events such as tools startup, taking a snapshot, resuming from a snapshot, resuming from suspend, or VMotion. These events synchronize time in the guest operating system with time in the host operating system, so it is important to make sure that the host operating system's time is correct.
To do this for VMware ACE, VMware Fusion, VMware GSX Server, VMware Player, VMware Server, and VMware Workstation run time synchronization software such as NTP or w32time in the host. For VMware ESX run NTP in the service console. For VMware ESXi, run NTP in the VMkernel.

Virtual Hardware clock configuration

When configuring the Linux guest operating system, if you are given a choice between keeping the “hardware” clock (that is, the virtual CMOS time of day clock) in UTC or local time, choose UTC. This avoids any confusion when your local time changes between standard and daylight saving time (in England, "summer time").


64bit Kernels

Linux Flavor
Version
Kernel Parameters
Notes
RHEL

RHEL 5.3 notsc divider=10
RHEL 5.2
notsc divider=10
RHEL 5.1 with RHSA-2007:0993-13
notsc divider=10
RHEL 5.1 without RHSA-2007:0993-13
notsc


32bit Kernels

Linux Flavor Version Kernel Parameters Notes
RHEL



RHEL 5.3 divider=10 clocksource=acpi_pm

RHEL 5.2 divider=10 clocksource=acpi_pm

RHEL 5.1 divider=10 clocksource=acpi_pm

RHEL 5.0 clocksource=acpi_pm

Editing Kernel Configuration

Kernel command line parameters are specified in the /etc/lilo.conf or /boot/grub/grub.conf file, depending on your choice of boot loader.

For LILO, put the kernel command line parameters at the end of the "append" line. For example, if the append line looks like:

append="resume=/dev/hda6 splash=silent"

and you want to add "clock=pmtmr divider=10" the updated text is:

append="resume=/dev/hda6 splash=silent clock=pmtmr divider=10"

Remember to run /sbin/lilo after editing lilo.conf , so that your edits take effect.

For GRUB, put the kernel command line parameters at the end of the "kernel" line. For example if the kernel line looks like:

kernel /vmlinuz-2.6.18 ro root=/dev/hda2

and you want to add "clock=pmtmr divider=10" the updated text is:

kernel /vmlinuz-2.6.18 ro root=/dev/hda2 clock=pmtmr divider=10


Below given is the best practice, for time related issues on VMware guests.

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006427