7

In FreeBSD, I'd like to set the timezone to UTC in an unattended way. If I run tzsetup, and select "yes" and "a" in the dialogs, for choosing UTC, I see that there are no /etc/localtime files present.

So if I want to set up UTC on a server in an unattended way, can I just rm /etc/localtime instead of running tzsetup?

enter image description here

enter image description here

enter image description here

6

Removing /etc/localtime will default the system to UTC because there's no "local" time zone (this is what happens when you run tzsetup, as you surmised).
For an automated install you simply remove the tzsetup bit from the bsdinstall time script - that script then does nothing and leaves you with an installation that expects a UTC system clock and operates in UTC.

Note that if you do this you must ensure your system's hardware/BIOS clock is set to UTC - most are these days, but if yours isn't "Strange Things" can potentially happen.
If you previously configured the system with a non-UTC hardware clock for some bizarre reason you also need to fix that and then remove /etc/wall_cmos_clock (an empty file that serves as a flag to tell the system that the hardware clock is NOT set to UTC).

3
  • Thanks. So generally I can just rm -f /etc/localtime /etc/wall_cmos_clock and do a ntpdate update? What about guests in virtualized environments, where the emulated hardware clock can be anything? Would the above rm + ntpdate update fix virtualized guests too? – hyperknot Sep 8 '15 at 23:57
  • I'm not sure about the virtualized guests (bhyve or such?) - I would reboot after doing this just to be 100% sure you catch everything though. (Same logic as fixing timezones for DST changes: you could restart every daemon on the box & hope you don't miss anything, or you could just reboot, let ntpdate re-sync the clock on boot, and then know everything is using the correct time zone.) – voretaq7 Sep 9 '15 at 0:50
  • 1
    Thanks. I'm talking about KVM virtualised providers, like DigitalOcean, etc. So if I do both rm and reboot and ntpdate I'll know it's ok. – hyperknot Sep 9 '15 at 1:01
4

Try this (or similar):

cp /usr/share/zoneinfo/UTC /etc/localtime

(found)

You may be able to do it as a symlink, too:

ln -s /usr/share/zoneinfo/UTC /etc/localtime

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.