Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing scripts to automate setting up new slicehost installations. In a perfect world, after I started the script, it would just run, with no attention from me. I have succeeded, with one exception.

How do I set the timezone, in a permanent (survive reboot) and sane (adjust for standard and daylight savings time, so no just forcing the date) ... manner that doesn't require input from me?

Currently, I'm using

 dpkg-reconfigure tzdata

This doesn't seem to have any way to force parameters into it. It demands user input.

EDIT: I'm editing here, rather than commenting, since comments don't seem to allow code blocks.

Here's the actual code I ended up with, based on Rudedog's comment below. I also noticed that this doesn't update /etc/timezone. I'm not certain who uses that, but in case anybody does, I'm setting that too.

echo $TIMEZONE > /etc/timezone                     
cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime   # This sets the time
share|improve this question
up vote 11 down vote accepted

You should be able to do this with

cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

Substitute the appropriate timezone in the above command.

share|improve this answer
you should be symlinking that not copying over – Zypher Dec 16 '09 at 22:49
He's using Debian. dpkg-reconfigure tzdata makes a copy, not a symlink. I believe the rationale is because /usr/share might not be mounted at boot time. – Rudedog Dec 17 '09 at 3:37
According to the technical section of the tzconfig manpage for Debian: >The work done by tzconfig is actually pretty simple. It just updates the link /etc/localtime to point to the correct timezone installed in /usr/share/zoneinfo/. – brent Dec 17 '09 at 15:19
tzconfig is deprecated on lenny in favor of dpkg-reconfigure tzdata and won't actually do anything. You can verify that it copies instead of symlinks by running dpkg-reconfigure tzdata and look at the result. – Rudedog Dec 17 '09 at 17:23

Update /etc/localtime symlink to point to correct timezone in /usr/share/zoneinfo/

share|improve this answer
Note that if you use a symlink and your /usr is mounted on a separate partition, anything that starts before /usr gets mounted will not have the correct timezone. Most distros today, including Debian, copy rather than symlink. – Rudedog Dec 17 '09 at 3:45

On Ubuntu 12.04 the following did the trick for me:

echo "Europe/Berlin" > /etc/timezone
dpkg-reconfigure tzdata
share|improve this answer

Try this:

echo "Europe/London" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
share|improve this answer
Although the code is appreciated, it should always have an accompanying explanation. This doesn't have to be long but it is expected. – peterh Apr 28 '15 at 8:20

tzdata uses debconf to answer that question, so you need to prepopulate it. There's several ways to do this, the easiest is to preseed the answer during installation. Beyond that you can set up a default database for debconf to use, see the debconf(7) manpage for how do that.

share|improve this answer

Ran into this myself. Here's a complete config for how to do this right (it's an aggregate of comments in here and this question):

#Set time zone and time
echo "tzdata tzdata/Areas select Europe" | debconf-set-selections
echo "tzdata tzdata/Zones/Europe select London" | debconf-set-selections
echo $TIMEZONE > /etc/timezone
cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
share|improve this answer

Also make sure that ntpd is installed and running.

yum install ntpd
service ntpd start
share|improve this answer

protected by Sven Apr 28 '15 at 9:47

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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