DæmonNews: News and views for the BSD community

Daemon News Ezine BSD News BSD Mall BSD Support Forum BSD Advocacy BSD Updates

Updating your NetBSD Real-Time Clock Offset without Recompiling

Bill Studenmund <wrstuden@netbsd.org>

As y'all know, the clocks changed last weekend. *BSD automatically takes care of this, so machines that have been up all the time (or run just Unix) are fine.

Machines (i386) that dual-boot, though, have a problem. Windows keeps the RTC in local time, so the clock jumped 60 minutes (3600 seconds). For time-specific protocols, like Kerberos, that can be a killer.

FreeBSD has a facility called adjkerntz which can automatically keep your system's clock in sync, but the NetBSD clock offset must be changed manually.

There is a fix though. If you are dual-booting like this, chances are you've set the kernel option RTC_OFFSET, like "options RTC_OFFSET=480" to set the kernel to keep the RTC 8 hours behind UTC. So you now need to have that be 420 for DST (and in the fall, it'll need to be 480 again).

Obviously you can just change the line and recompile. But there's another thing you can do: you can change that 480 in your compiled kernel, without having to recompile!

The number from the RTC_OFFSET option gets stored in the rtc_offset variable in the compiled kernel. So all we need to do is change it with gdb, and we're done!

You need to be root to do this, since you're writing the kernel image.

  1. Start gdb on the kernel file, with the "--write" option.

    	# gdb --write netbsd
    	GNU gdb 5.0nb1
    	Copyright 2000 Free Software Foundation, Inc.
    	GDB is free software, covered by the GNU General Public License, and you are
    	welcome to change it and/or distribute copies of it under certain conditions.
    	Type "show copying" to see the conditions.
    	There is absolutely no warranty for GDB.  Type "show warranty" for details.
    	This GDB was configured as "i386--netbsdelf"...(no debugging symbols
    	found)...
    	(gdb)
    
  2. Look at what rtc_offset is now

    	(gdb) print rtc_offset
    	$1 = 480
    
  3. Use the fact that gdb's print command will print the result of an assignment expression to change rtc_offset

    	(gdb) print rtc_offset=420
    	$2 = 420
    
  4. Quit gdb, and you're done!

Note this works even if the kernel is stripped:

	> file /netbsd
	/netbsd: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped

Enjoy!

Google
Web daemonnews.org

More Articles
  • Interview with Jan Schaumann
  • Interview with Theo de Raadt
  • Book Review: Virtualization with VMware ESX Server
  • Editorial: Not Quite Dead Yet
  • The Design of OpenBGPd
  • Interview with der Mouse
  • Letter to Steve Jobs
  • Interview with Manuel Bouyer on Xen
  • Apple and Open Source
  • BSDCan 2006
  • BSD Certification Survey Results
  • Lab in a Box
  • Ike Notes on BSDCan 2005
  • BSDCan 2005 Photos
  • FreeBSD Developer Summit Pictures

  • Advertisements




    Author maintains all copyrights on this article.
    Images and layout Copyright © 1998-2006 Dæmon News. All Rights Reserved.