diff options
author | WANG Chao <chaowang@redhat.com> | 2013-06-06 17:56:11 +0800 |
---|---|---|
committer | Harald Hoyer <harald@redhat.com> | 2013-06-06 12:10:50 +0200 |
commit | 77364fd6bb01ea184db73b1a5ad05da984752293 (patch) | |
tree | 3dc368934b6c4264b3efddaf7dad27e01db4c782 | |
parent | 41b0e41a09ecde849a75db695db26b6ad78a1e58 (diff) | |
download | dracut-77364fd6bb01ea184db73b1a5ad05da984752293.tar.gz dracut-77364fd6bb01ea184db73b1a5ad05da984752293.tar.bz2 dracut-77364fd6bb01ea184db73b1a5ad05da984752293.zip |
base: setup correct system time and time zone in initrd
Currently in initrd, hardware clock is always considered to use UTC time
format and system time zone is also UTC. Thus system time isn't correct
if hw clock is localtime or we're using other time zone in real root.
To fix this, install /etc/adjtime and /etc/localtime to initrd. If not
using systemd, install /usr/sbin/hwclock for dracut init to setup system
time.
[harald: combined the two hostonly if's]
Signed-off-by: WANG Chao <chaowang@redhat.com>
Signed-off-by: Harald Hoyer <harald@redhat.com>
-rwxr-xr-x | modules.d/99base/init.sh | 9 | ||||
-rwxr-xr-x | modules.d/99base/module-setup.sh | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/modules.d/99base/init.sh b/modules.d/99base/init.sh index 880a2c05..c72129b9 100755 --- a/modules.d/99base/init.sh +++ b/modules.d/99base/init.sh @@ -55,6 +55,15 @@ if ! ismounted /dev; then exit 1 fi +# setup system time +if [ -f /etc/adjtime ]; then + if strstr "$(cat /etc/adjtime)" LOCAL; then + hwclock --hctosys --localtime + else + hwclock --hctosys --utc + fi +fi + # prepare the /dev directory [ ! -h /dev/fd ] && ln -s /proc/self/fd /dev/fd >/dev/null 2>&1 [ ! -h /dev/stdin ] && ln -s /proc/self/fd/0 /dev/stdin >/dev/null 2>&1 diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh index 4955b7ba..f3caf289 100755 --- a/modules.d/99base/module-setup.sh +++ b/modules.d/99base/module-setup.sh @@ -28,6 +28,17 @@ install() { egrep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo 'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd" egrep '^nobody:' /etc/passwd >> "$initdir/etc/passwd" + # install /etc/adjtime and time zone data + if [[ $hostonly ]]; then + dracut_install -o /etc/adjtime \ + /etc/localtime + + # Our init.sh script needs hwclock to set system time + if ! dracut_module_included "systemd"; then + dracut_install -o hwclock + fi + fi + # install our scripts and hooks inst_script "$moddir/init.sh" "/init" inst_script "$moddir/initqueue.sh" "/sbin/initqueue" |