The Clock Mini-HOWTO
Total Page:16
File Type:pdf, Size:1020Kb
The Clock Mini−HOWTO The Clock Mini−HOWTO Table of Contents The Clock Mini−HOWTO.................................................................................................................................1 Ron Bean, rbean@execpc.com...............................................................................................................1 1. Introduction..........................................................................................................................................1 2. How Linux Keeps Track of Time........................................................................................................1 3. Software...............................................................................................................................................1 4. Radio Clocks........................................................................................................................................1 1. Introduction..........................................................................................................................................1 1.1 Does Anybody Really Know What Time It Is?.................................................................................1 1.2 Where to Find Stuff: "The Usual Places"..........................................................................................2 1.3 Acknowledgements............................................................................................................................3 2. How Linux Keeps Track of Time........................................................................................................3 2.1 Basic Strategies..................................................................................................................................3 2.2 Potential Conflicts..............................................................................................................................4 2.3 Should the RTC use Local Time or UTC, and What About DST?....................................................4 2.4 How Linux keeps Track of Time Zones............................................................................................6 2.5 The Bottom Line................................................................................................................................6 3. Software...............................................................................................................................................6 3.1 Clock(8) and Hwclock(8)..................................................................................................................6 3.2 Adjtimex(8)........................................................................................................................................7 3.3 Xntpd and ntpd: the Network Time Protocol.....................................................................................7 3.4 Chrony...............................................................................................................................................8 3.5 Clockspeed.........................................................................................................................................8 4. Radio Clocks........................................................................................................................................9 4.1 CHU and the "Gadget Box"...............................................................................................................9 4.2 WWV and the "Most Accurate Clock"..............................................................................................9 4.3 GPS and the "Totally Accurate Clock"............................................................................................10 4.4 Low−frequency Time Signals: DCF77, MSF(Rugby), WWVB.....................................................10 i The Clock Mini−HOWTO Ron Bean, [email protected] v2.1, November 2000 How to set and keep your computer's clock on time. 1. Introduction • 1.1 Does Anybody Really Know What Time It Is? • 1.2 Where to Find Stuff: "The Usual Places" • 1.3 Acknowledgements 2. How Linux Keeps Track of Time • 2.1 Basic Strategies • 2.2 Potential Conflicts • 2.3 Should the RTC use Local Time or UTC, and What About DST? • 2.4 How Linux keeps Track of Time Zones • 2.5 The Bottom Line 3. Software • 3.1 Clock(8) and Hwclock(8) • 3.2 Adjtimex(8) • 3.3 Xntpd and ntpd: the Network Time Protocol • 3.4 Chrony • 3.5 Clockspeed 4. Radio Clocks • 4.1 CHU and the "Gadget Box" • 4.2 WWV and the "Most Accurate Clock" • 4.3 GPS and the "Totally Accurate Clock" • 4.4 Low−frequency Time Signals: DCF77, MSF(Rugby), WWVB 1. Introduction 1.1 Does Anybody Really Know What Time It Is? The Real−Time−Clock (RTC) chips used on PC motherboards are notoriously inaccurate, usually gaining or losing the same amount of time each day. Linux provides a simple way to correct for this in software, which The Clock Mini−HOWTO 1 The Clock Mini−HOWTO can make the clock *very* accurate, even without an external time source. But most people don't know how to set it up, for several reasons: • It's not mentioned in most of the general documentation on how to set up linux, and it can't be set up automatically (unless you have an external time source), so the default is not to use it. • If you type "man clock" you may get the man page for clock(3), which is not what you want. Try "man 8 clock" or "man 8 hwclock" (some distributions search the man pages in numerical order if you don't give a section number, others search in the order specified in /etc/man.config). • Most people don't seem to care what time it is anyway. • Those few who do care often want to sync the system clock to an external time source, such as a network time server or radio clock. This makes the accuracy of the RTC (mostly) irrelevant. This mini−HOWTO describes the low−tech approach (which can be very accurate by itself), and provides pointers to several more sophisticated options. In most cases the documentation is well written, so I'm not going to repeat that information here. Previous versions included detailed instructions for the old clock(8) program for anyone still running an older system, but I've dropped that section because most distributions now use hwclock(8) instead, which has much better documentation. If you still want a copy of the clock(8) instructions I can email them to you, but read the section on hwclock(8) first. Note You must be logged in as "root" to run any program that affects the RTC or the system time, which includes most of the programs described here. If you normally use a graphical interface for everything, you may also need to learn some basic unix shell commands. Note If you run more than one OS on your machine, you should only let one of them set the RTC, so they don't confuse each other. The exception is the twice−a−year adjustment for Daylight Saving(s) Time (see the section on DST for details). If you run a dual−boot system that spends a lot of time running Windows, you may want to check out some of the clock software available for that OS instead. Follow the links on the NTP website at http://www.eecis.udel.edu/~ntp/software.html. Many of the radio clocks mentioned here include software for Windows. 1.2 Where to Find Stuff: "The Usual Places" In some places I've mentioned that software can be downloaded from "the usual places", which means any place you could download a complete Linux system if you didn't get it on a CD−ROM. In the old days that meant the ftp archive at sunsite.unc.edu, and various mirror sites around the world. That site has been renamed http://metalab.unc.edu/linux/ (since Sun no longer sponsors it). Some distributions also have their own websites, which may include a lot of this stuff. I assume most people get Linux on CD these days, and those CDs often include software that is not part of the default installation, so you may already have some of the programs mentioned here without knowing it. 1.2 Where to Find Stuff: "The Usual Places" 2 The Clock Mini−HOWTO The latest version of this mini−HOWTO can be found at the home of the Linux Documentation Project, which is currently http://www.linuxdoc.org/ (and is also reachable from the metalab site mentioned above). I think all the old links are now forwarded to this one. All HOWTOs are written in SGML and converted to various other formats by standardized conversion programs. Most people seem to want the HTML version, which is at http://www.linuxdoc.org/HOWTO/mini/Clock.html. Revision history can be found as comments in the SGML source. Most Linux distributions install a complete set of HOWTO's in /usr/doc/HOWTO/ and /usr/doc/HOWTO/mini. 1.3 Acknowledgements This mini−HOWTO has been greatly improved thanks to various people who have sent me email since the first version in 1996. In some cases they wrote with questions but ended up giving me as much information as I gave them. Unfortunately I haven't compiled a list of names (maybe next time). You know who you are :−). 2. How Linux Keeps Track of Time 2.1 Basic Strategies A Linux system actually has two clocks: One is the battery powered "Real Time Clock" (also known as the "RTC", "CMOS clock", or "Hardware clock") which keeps track of time when the system is turned off but is not used when the system is running. The other is the "system clock" (sometimes called the "kernel clock" or "software clock") which is a software counter based on the timer interrupt. It does not exist when the system is not running, so it has to