Skip to content
February 28, 2012 / Kamil Páral

Changing system time in a virtual machine

 When working on a bug 748920 I needed to change the system time (RTC) in a KVM+libvirt virtual machine. I have found quite some obstacles I want to share.

The first possible source of your confusion might be the fact, that if you set your system time in the usual way using ‘date’ and ‘hwclock’, the change will persist VM reboot, but won’t persist VM shutdown. On shutdown the RTC is reset.

If you need to have a permanent system time change (persisting shutdown), you need to edit the libvirt configuration file for your VM. Issue this command:

$ virsh edit <domain_name>

Then edit the XML file according its documentation. Find this line:

<clock offset='utc'/>

and replace it with this line:

<clock offset='variable' adjustment='86400'/>

The adjustment parameter controls how much will the system time be shifted from current UTC time, the value is the number of seconds. In the example above I shifted the time one day into the future (86400 seconds). You can use negative values as well.

Save the file, boot your VM. The time should be shifted.

Be careful that currently Fedora boot breaks if you shift your time more than one day into the past, as says bug 748920.

Flattr this

3 Comments

Leave a Comment
  1. tosky / Feb 28 2012 13:52

    You can also explicitely use the timezone:

    <clock offset=’timezone’ timezone=’Europe/Prague’>

    • Kamil Páral / Feb 28 2012 13:57

      Yes, you can, but that can be used to moving the clock just +- 11 hours at max. And you can do the same inside the client.

  2. kashyapc / Feb 28 2012 20:24

    Thanks for this Kamil. I’ll go check my lab guests and see what they’re upto. It’s easy to forget.

Leave a Reply (Markdown syntax supported)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 26 other followers

%d bloggers like this: