Time zone settings in a KVM virtualized environment

Source: Internet
Author: User

Guest OS time retention

KVM Technology is full virtualization, the guest OS does not need to make changes to run directly, but in the timing of the problem, the guest OS timing is a way to count the clock interrupt, and then the conversion, but the host generated clock interrupt can not reach all the guest OS in time, Because interrupts in the guest OS are not real hardware interrupts, it is an interrupt injected by host

Many Web applications, sessions authentication in the Web, and so on, will call the system time, the guest OS if the time is wrong, it will cause a program error, to this end, KVM to guest VMs provide a semi-virtualized clock (kvm-clock), In RHEL5.5 and above, Kvm-clock is used as the default clock source, and you can use the following command in guest to see if Kvm-clock is used

Cat /sys/devices/system/clocksource/clocksource0/current_clocksource
Kvm-clock

In the Kvm-clock mode, the guest OS does not have direct access to the host clock, and the host writes the system time to a memory page that the guest can read, so that the guest can read this memory page to set its own hardware time, but host does not update the memory page in real time. Instead, it is updated when a VM event (VM shutdown, reboot, etc.) occurs, so this does not keep the guest time accurate

Before proceeding, we must first understand the concepts of system time and hardware time.

UTC time and local time

UTC time: Also known as world standard Time, World unification time, UTC is calibrated by atomic clock, the rest of the world is based on this as the base time with its own time zone to set its local time

local time: local time is generally different from UTC because it is in a different time zone, and the conversion method is

local time = UTC + Time zone or UTC = local time-time zone

Time zone East is positive, West is negative, in China, time zone for East Eight district, that is, +8 District, local time all use Beijing time, on Linux display is CST, so cst=utc+ (+ 8 hours) or utc=cst-(+ 8 hours)

(Chinese standard Time, when China standards, attention to the central United States Standard Time is also abbreviated as CST)

System time and hardware time

Hardware time: The motherboard on the BIOS time, by the motherboard battery power to maintain the operation, the system to read this time when the boot, and according to it to set the system time (Note: System startup time According to the hardware time set the process may exist time zone conversion, according to/etc/localtime)

System time: This is the time that we see when we execute the date command, and all the time calls under the Linux system (except the commands that directly access hardware time) are used.

/etc/localtime This file is used to set the time zone of the system, copy the corresponding time zone file in/usr/share/zoneinfo/to/etc and rename it to LocalTime to modify the time zone setting (also can be modified using the Tzselect command). And this modification is immediately valid for the date command. This file is used for both date and hwclock, which translates between UTC and local time based on the time zone setting of the file.

Setting the virtual machine hardware clock in Libvirt

KVM virtual machines are typically managed using Libvirt, and in their configured XML file, there are information about the virtual machine hardware clock settings

  <offset= ' localtime '>  </clock> 

The offset property of clock has "UTC", "LocalTime", "timezone", "variable" four selectable options

If the guest OS is a Linux system, "UTC" Should be used, and the guest OS will synchronize the UTC time to host at startup and then calculate the system time based on the time zone set in/etc/localtime

If the guest OS is a Windows system, then "LocalTime" should be selected, and the guest OS will synchronize the system time to host at startup

Time zone settings in a KVM virtualized environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.