From c319a9f1833ac22d96c1aa38ac8097fc59dab045 Mon Sep 17 00:00:00 2001 From: Julian Yap Date: Wed, 31 Jul 2024 12:16:16 -0700 Subject: [PATCH] Hibernation works fine. Add "Resume from Hibernate has the wrong time" --- content/pages/2024-04-04-1712257725.md | 44 +++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/content/pages/2024-04-04-1712257725.md b/content/pages/2024-04-04-1712257725.md index e5bb82b..6483f5f 100644 --- a/content/pages/2024-04-04-1712257725.md +++ b/content/pages/2024-04-04-1712257725.md @@ -6,7 +6,7 @@ draft: false I have installed Arch Linux on a Microsoft Surface Book 3 to use as my "focus" machine. This page outlines some things I've had to install and tweak. -Most everything [works out of the box](https://github.com/linux-surface/linux-surface/wiki/Supported-Devices-and-Features#surface-books-and-surface-laptop-studio) except the cameras, which I've disabled in the BIOS. Suspend only supports [ACPI state 0 Suspend-To-Idle](https://www.kernel.org/doc/Documentation/power/states.txt) and eats up 20%+ of the battery life overnight. [Resume from Hibernate has keyboard issues](#resume-from-hibernate-has-keyboard-issues). +Most everything [works out of the box](https://github.com/linux-surface/linux-surface/wiki/Supported-Devices-and-Features#surface-books-and-surface-laptop-studio) except the cameras, which I've disabled in the BIOS. Suspend only supports [ACPI state 0 Suspend-To-Idle](https://www.kernel.org/doc/Documentation/power/states.txt) and eats up 20%+ of the battery life overnight, but as of kernel 6.9.9-arch1-1-surface I have not had issues with Hibernation. This is *not* a recommended laptop for running Linux. @@ -115,8 +115,44 @@ Appears to be an issue with the dock and using a USBC to Display Port cable. Unplugging the power cable (which connects to the dock) seems to help get the external screen displaying again. Annoying workaround. -### Resume from Hibernate has keyboard issues +### Resume from Hibernate has the wrong time -Tracking the issue: https://github.com/linux-surface/linux-surface/issues/1412 +Resume from Hibernate suffers from clock drift so has the wrong time. -The system Hibernates fine. Resume from Hibernate seems to work except some keys on the keyboard (both USB keyboard and built-in keyboard) didn't work on the one test I did. Was able to SSH into the laptop and reboot it from there. +To resolve this, I set up a systemd service that runs a time synchronization command when the system wakes up. Here's a step-by-step approach to implement this. + +First, make sure you have the systemd-timesyncd service enabled and running. This is the default time synchronization daemon for Arch Linux. If it's not already enabled, you can enable it with: +``` +sudo systemctl enable --now systemd-timesyncd.service +``` + +Create a new systemd service file: +``` +sudo vi /etc/systemd/system/fix-time-on-resume.service +``` + +Add the following content to the file: +``` +[Unit] +Description=Fix system time on resume from hibernate +After=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/systemctl restart systemd-timesyncd.service + +[Install] +WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target +``` + +Reload the systemd daemon to recognize the new service: +``` +sudo systemctl daemon-reload +``` + +Enable the new service: +``` +sudo systemctl enable fix-time-on-resume.service +``` + +This service automatically restarts the systemd-timesyncd service when your system resumes from hibernation, which corrects the time.