After a talk with stgraber, this is a due to the fact that the Ubuntu
LXC I build are using a pre-generated image which uses UTC by default.

If you want to change the time on Xenial, in my case date command or
other technic didn't have positive impact.

The only thing that work so far is to unlink /etc/localtime and link it
to the desired zone.

example :

#ls -altr /etc/localtime 
lrwxrwxrwx 1 root root 27 Oct 12 15:59 /etc/localtime -> 
/usr/share/zoneinfo/Etc/UTC

# unlink /etc/localtime

# ls -altr /etc/localtime 
ls: cannot access '/etc/localtime': No such file or directory

# ln -s /usr/share/zoneinfo/America/Toronto /etc/localtime

# ls -altr /etc/localtime 
lrwxrwxrwx 1 root root 35 Oct 12 12:05 /etc/localtime -> 
/usr/share/zoneinfo/America/Toronto

Eric

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to lxc in Ubuntu.
https://bugs.launchpad.net/bugs/1632766

Title:
  time in lxc ubuntu template

Status in lxc package in Ubuntu:
  Invalid

Bug description:
  With regard to github bug :

  ---
  adjust timezone to the host at creation time #47
  https://github.com/lxc/lxc/issues/47
  ---

  I still can reproduce the problem on different HW running Xenial with
  the LXC ubuntu image Trusty and Xenial.

  * Bare metal (xenial)
  $ date
  Wed Oct 12 11:27:55 EDT 2016

  LXC (Trusty)
  $ sudo lxc-attach -n trusty
  root@trusty:/# date
  Wed Oct 12 15:28:10 UTC 2016

  * Bare metal #2 (xenial)
  $ date
  Wed Oct 12 11:28:57 EDT 2016

  LXC (Xenial)
  $ lxc-attach -n xenial

  $ date
  Wed Oct 12 15:29:32 UTC 2016

  Note, that using the debian template everything works fine :

  Bare metal #1 (xenial)
  $ date
  Wed Oct 12 11:30:40 EDT 2016

  $ lxc-attach -n debian8
  $ date
  Wed Oct 12 11:30:45 EDT 2016

  However debian and ubuntu got the same piece of code :

  # lxc-debian.in
  149     # set initial timezone as on host
  150     if [ -f /etc/timezone ]; then
  151         cat /etc/timezone > "$rootfs/etc/timezone"
  152         chroot "$rootfs" dpkg-reconfigure -f noninteractive tzdata
  153     elif [ -f /etc/sysconfig/clock ]; then
  154         . /etc/sysconfig/clock
  155         echo "$ZONE" > "$rootfs/etc/timezone"
  156         chroot "$rootfs" dpkg-reconfigure -f noninteractive tzdata
  157     else
  158         echo "Timezone in container is not configured. Adjust it 
manually."
  159     fi
  160
  161     echo "root:root" | chroot "$rootfs" chpasswd
  162     echo "Root password is 'root', please change !"
  163
  164     return 0
  165 }

  # lxc-ubuntu.in
  600     # Set initial timezone as on host
  601     if [ -f /etc/timezone ]; then
  602         cat /etc/timezone > $rootfs/etc/timezone
  603         chroot $rootfs dpkg-reconfigure -f noninteractive tzdata
  604     elif [ -f /etc/sysconfig/clock ]; then
  605         . /etc/sysconfig/clock
  606         echo $ZONE > $rootfs/etc/timezone
  607         chroot $rootfs dpkg-reconfigure -f noninteractive tzdata
  608     else
  609         echo "Timezone in container is not configured. Adjust it 
manually."
  610     fi

  If I run the above manually it has positive effect on Trusty (persistent 
across stop/start)
  $ cat /etc/timezone > /var/lib/lxc/trusty/rootfs/etc/timezone
  $ chroot /var/lib/lxc/trusty/rootfs dpkg-reconfigure -f noninteractive tzdata

  Current default time zone: 'America/Toronto'
  Local time is now:      Wed Oct 12 11:35:37 EDT 2016.
  Universal Time is now:  Wed Oct 12 15:35:37 UTC 2016.

  $ lxc-attach -n trusty
  $ date
  Wed Oct 12 11:36:02 EDT 2016

  But got no effect on Xenial LXC container :

  $ cat /etc/timezone > /var/lib/lxc/xenial/rootfs/etc/timezone
  $ chroot /var/lib/lxc/xenial/rootfs dpkg-reconfigure -f noninteractive tzdata

  Current default time zone: 'Etc/UTC'
  Local time is now:      Wed Oct 12 15:38:00 UTC 2016.
  Universal Time is now:  Wed Oct 12 15:38:00 UTC 2016.

  # lxc-attach -n xenial
  $ date
  Wed Oct 12 15:38:06 UTC 2016

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1632766/+subscriptions

-- 
Mailing list: https://launchpad.net/~touch-packages
Post to     : touch-packages@lists.launchpad.net
Unsubscribe : https://launchpad.net/~touch-packages
More help   : https://help.launchpad.net/ListHelp

Reply via email to