Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
adjust timezone to the host at creation time #47
New containers' timezone is fixed to Etc/UTC, however it's always should be copied from the host:
--- lxc-ubuntu.ORIG 2013-09-21 19:19:25.535539699 +0200 +++ lxc-ubuntu 2013-09-21 20:10:12.316143642 +0200 @@ -105,6 +105,10 @@ rm -f $rootfs/usr/sbin/policy-rc.d fi + # adjust timezone to the host + cp -f /etc/timezone $rootfs/etc/timezone + chroot $rootfs dpkg-reconfigure -f noninteractive tzdata + return 0 }
--- lxc-fedora.ORIG 2013-09-21 19:59:19.533180037 +0200 +++ lxc-fedora 2013-09-22 00:13:29.945942612 +0200 @@ -585,4 +585,8 @@ clean || exit 1 exit 0 fi + +# adjust timezone to the host +cp -f /etc/timezone /data/lxc/samba/rootfs/etc/localtime + echo "container rootfs and config created"
--- lxc-oracle.ORIG 2013-09-21 20:02:18.020336992 +0200 +++ lxc-oracle 2013-09-22 01:25:35.675211177 +0200 @@ -329,6 +329,9 @@ echo "root:root" | chroot $container_rootfs chpasswd echo -e "Added container user:\033[1moracle\033[0m password:\033[1moracle\033[0m" echo -e "Added container user:\033[1mroot\033[0m password:\033[1mroot\033[0m" + + # adjust timezone to the host + cp -f /etc/timezone $container_rootfs/etc/localtime } # create the container's lxc config file
However I realized, it's not good enough, as system time also depends on the hardware clock (UTC or not). It's configured in different places, eg.:
Ubuntu -> /etc/default/rcS
Probably other places in other distributions.
This was already done in debian, ubuntu and ubuntu-cloud. For those this was done by copying the timezone name and running the tzdata hook which will hopefully do the right thing in most cases.
For the other templates, I'd prefer their individual maintainer to come up with what they think is the right way to do this. Also note that we need to support things like running Oracle on top of Ubuntu, so we need to support multiple possible input files or at least not fail if they're missing.