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

hyperknot
  • 701
  • 2
  • 9
  • 16

2 Answers2

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).

voretaq7
  • 79,879
  • 17
  • 130
  • 214
  • 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 08 '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 09 '15 at 00: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 09 '15 at 01: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
warren
  • 18,369
  • 23
  • 84
  • 135