要使用debconf,在调用dpkg-reconfigure之前,还需要删除/etc/localtime
和/etc/timezone
。也要注意可能不是良性的额外空间(如您的问题!)。
因此,有效的“ debconf方式”(在Debian Stretch中)将是:
echo "tzdata tzdata/Areas select Europe" | debconf-set-selections
echo "tzdata tzdata/Zones/Europe select Madrid" | debconf-set-selections
rm -f /etc/localtime /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
原因是tzdata配置脚本试图变得聪明,并且如果以前曾对其进行过配置,或者用户手动干预了时区,则其行为会有所不同。
额外
要自己调试类似的问题,您首先需要执行以下操作:
export DEBCONF_DEBUG=developer
这将提供以下信息:
# dpkg-reconfigure -f noninteractive tzdata
debconf (developer): starting /var/lib/dpkg/info/tzdata.config reconfigure 2018e-0+deb9u1
debconf (developer): <-- VERSION 2.0
debconf (developer): --> 0 2.0
debconf (developer): <-- CAPB backup
debconf (developer): --> 0 multiselect escape
debconf (developer): <-- SET tzdata/Areas Etc
debconf (developer): --> 0 value set
debconf (developer): <-- SET tzdata/Zones/Etc UTC
debconf (developer): --> 0 value set
debconf (developer): <-- INPUT high tzdata/Areas
debconf (developer): --> 30 question skipped
debconf (developer): <-- GO
debconf (developer): --> 0 ok
debconf (developer): <-- GET tzdata/Areas
debconf (developer): --> 0 Etc
debconf (developer): <-- INPUT high tzdata/Zones/Etc
debconf (developer): --> 30 question skipped
debconf (developer): <-- GO
debconf (developer): --> 0 ok
debconf (developer): starting /var/lib/dpkg/info/tzdata.postinst configure 2018e-0+deb9u1
debconf (developer): <-- VERSION 2.0
debconf (developer): --> 0 2.0
debconf (developer): <-- GET tzdata/Areas
debconf (developer): --> 0 Etc
debconf (developer): <-- GET tzdata/Zones/Etc
debconf (developer): --> 0 UTC
debconf (developer): <-- STOP
它会告诉你,这有力地就设置询问它们的用户(从而覆盖您设置的值前值debconf-set-selections
)。
然后,您将shebang /var/lib/dpkg/info/tzdata.config
从更改#!/bin/sh
为#!/bin/sh -x
,并按照程序流程进行操作,在该处可以看到:
+ [ -L /etc/localtime ]
+ readlink /etc/localtime
+ TIMEZONE=/usr/share/zoneinfo/Etc/UTC
看着 /var/lib/dpkg/info/tzdata.config
你会发现:
# If /etc/localtime is a link, update /etc/timezone
if [ -L /etc/localtime ] ; then
TIMEZONE="$(readlink /etc/localtime)"
这解释了为什么@fiction答案有效。同样在脚本中查找更多,您会发现,如果删除“ / etc / localtime”,则@andrekeller答案在较新的Debian版本中也适用。
希望当下一个Debian版本使脚本更智能并且现有答案也无效时,此调试帮助将对您有所帮助。可以在debconf-devel(7)中找到有关调试debconf的更多信息。