Tuesday, June 05, 2012

Script to help with timing issues on virtual guests

There's an issue when running a virtual machine that the time gets incorrectly updated. The problem is that when you suspend the computer, the virtual machine will suspend and return with the incorrect time, instead of updating from the Internet. I have seen this issue more so on Linux than on Windows, but for Linux it's easily fixed by a simple script. Here's the basic steps to get it working.


  1. Open up Vi or your favorite editor on your virtual machine
  2. Type in the following details
    1. #!/bin/bash
      service ntpd stop
      sleep 5
      ntpdate pool.ntp.org
      sleep 5
      service ntpd start
  3. Save you file
  4. Change the permissions to all the file to be executable
    1. Run the following command
    2. #chmod 755 filename
  5. Test the command
    1. Run the following command
    2. #date
    3. You should see an incorrect time
    4. Run the script, note the "./" before the script name
    5. #./yourtimescriptname
    6. Run the following command
    7. #date
    8. You should see the correct time
  6. Now your virtual machine is updated
  7. You can add this script to a cron job or login script to automate the process
So far I just run this manually since I rarely reboot the virtual machine or login or out. You can make a symbolic link or an alias to make things easier to manage. 


No comments: