]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
base: setup correct system time and time zone in initrd
authorWANG Chao <chaowang@redhat.com>
Thu, 6 Jun 2013 09:56:11 +0000 (17:56 +0800)
committerHarald Hoyer <harald@redhat.com>
Thu, 6 Jun 2013 10:10:50 +0000 (12:10 +0200)
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>
modules.d/99base/init.sh
modules.d/99base/module-setup.sh

index 880a2c0539a4dbbecec94b3e79f8698ab46d45dc..c72129b97a6c89c59f5e3d8b281c3b48411bfe2f 100755 (executable)
@@ -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
index 4955b7ba9291a50084c97e70ce637a7357a1c689..f3caf289627812edfed1700fc7a36f505c2e9708 100755 (executable)
@@ -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"