dockur / windows

Windows inside a Docker container.
MIT License
17.49k stars 1.5k forks source link

Wrong time in VM, keeps resetting #672

Closed eylenburg closed 2 months ago

eylenburg commented 2 months ago

Operating system

Fedora Kinoite 40

Description

I noticed that the default docker/podman VM has the wrong time, several hours in the future (!) despite being set to a US time zone while I'm in Europe. This lead to a wrong time and date in file modification dates.

So I went to the Time & Date settings in Windows, disabled "set time automatically" and manually set the correct time and date and time zone.

This fixed the time being several hours off the real time, however after each PC reboot, the time in the VM is changed to be one hour behind the real time.

I can manually change it in the VM's settings again, but after a reboot it will again show me the time one hour behind. Does any have any idea what could cause this?

It might lead to data loss if for example you're syncing your files and the modification date is used to decide which version is the newer one.

I previously filed this bug with the Winapps project (https://github.com/winapps-org/winapps/issues/173)

Docker compose

# For documentation, FAQ, additional configuration options and technical help, visit: https://github.com/dockur/windows

name: "winapps" # Docker Compose Project Name.
volumes:
  # Create Volume 'data'.
  # Located @ '/var/lib/docker/volumes/winapps_data/_data' (Docker).
  # Located @ '/var/lib/containers/storage/volumes/winapps_data/_data' or '~/.local/share/containers/storage/volumes/winapps_data/_data' (Podman).
  data:
services:
  windows:
    image: dockurr/windows # https://hub.docker.com/r/dockurr/windows
    container_name: WinApps # Created Docker VM Name.
    environment:
      # Version of Windows to configure. For valid options, visit:
      # https://github.com/dockur/windows?tab=readme-ov-file#how-do-i-select-the-windows-version
      # https://github.com/dockur/windows?tab=readme-ov-file#how-do-i-install-a-custom-image
      VERSION: "tiny11"
      RAM_SIZE: "4G" # RAM allocated to the Windows VM.
      CPU_CORES: "4" # CPU cores allocated to the Windows VM.
      DISK_SIZE: "64G" # Size of the primary hard disk.
      #DISK2_SIZE: "32G" # Uncomment to add an additional hard disk to the Windows VM. Ensure it is mounted as a volume below.
      USERNAME: "MyWindowsUser" # Uncomment to set a custom Windows username. The default is 'Docker'.
      PASSWORD: "MyWindowsPassword" # Uncomment to set a password for the Windows user. There is no default password.
      HOME: "${HOME}" # Set path to Linux user home folder.
    privileged: true # Grant the Windows VM extended privileges.
    ports:
      - 8006:8006 # Map '8006' on Linux host to '8006' on Windows VM --> For VNC Web Interface @ http://127.0.0.1:8006.
      - 3389:3389/tcp # Map '3389' on Linux host to '3389' on Windows VM --> For Remote Desktop Protocol (RDP).
      - 3389:3389/udp # Map '3389' on Linux host to '3389' on Windows VM --> For Remote Desktop Protocol (RDP).
    stop_grace_period: 120s # Wait 120 seconds before sending SIGTERM when attempting to shut down the Windows VM.
    restart: always
    volumes:
      - data:/storage # Mount volume 'data' to use as Windows 'C:' drive.
      - ${HOME}:/shared # Mount Linux user home directory @ '\\host.lan\Data'.
      #- /path/to/second/hard/disk:/storage2 # Uncomment to mount the second hard disk within the Windows VM. Ensure 'DISK2_SIZE' is specified above.
      #- ./oem:/oem # Enables automatic post-install execution of 'oem/install.bat', applying Windows registry modifications contained within 'oem/RDPApps.reg'.
      #- /path/to/windows/install/media.iso:/custom.iso # Uncomment to use a custom Windows ISO. If specified, 'VERSION' (e.g. 'tiny11') will be ignored.
    devices:
      - /dev/kvm # Enable KVM.
      #- /dev/sdX:/disk1 # Uncomment to mount a disk directly within the Windows VM (Note: 'disk1' will be mounted as the main drive).
      #- /dev/sdY:/disk2 # Uncomment to mount a disk directly within the Windows VM (Note: 'disk2' and higher will be mounted as secondary drives).

Docker log

$ podman logs WinApps
BdsDxe: loading Boot0004 "Windows Boot Manager" from HD(1,GPT,3DFC09A2-FCE3-4607-AC02-7E1AFF123BB7,0x800,0x40000)/\EFI\Microsoft\Boot\bootmgfw.efi
BdsDxe: starting Boot0004 "Windows Boot Manager" from HD(1,GPT,3DFC09A2-FCE3-4607-AC02-7E1AFF123BB7,0x800,0x40000)/\EFI\Microsoft\Boot\bootmgfw.efi
❯ Windows started succesfully, visit http://localhost:8006/ to view the screen...

Screenshots (optional)

image

xsy420 commented 2 months ago

It is not an issue anymore since v3.07. System time is based on LANGUAGE and REGION environment value by default. If it is still different, you can specify the timezone in the unattend xml file like

<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
      <ComputerName>*</ComputerName>
      <TimeZone>UTC</TimeZone>
</component>

It's the same level with tag ComputerName

eylenburg commented 2 months ago

The time zone is set correctly but the time is still off by an hour. And that's not a problem in itself because I can just manually set the time in the Windows settings. But after a reboot it is changed again to be one hour wrong. I wonder why?

edit: So right now it's 10:47 in the UK. The Windows VM is set to the UK timezone (see screenshot above) but shows 9:47. I can manually change the time in Windows or change the timezone to Europe (+1 hour) to get to 10:47 in Windows. But after a reboot of my PC the Windows VM is set to 9:47 and UK time zone again, so it undoes my time zone change and it also has the wrong time for the time zone it's supposed to be in.

I start my VM with the command podman-compose --file ~/.config/winapps/compose.yaml start, not sure if that's wrong but in any case I'd assume the Windows VM remembers the settings I change inside the VM?

xsy420 commented 2 months ago

add this command into your install.bat

reg add HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation /v RealTimeIsUniversal /t REG_DWORD /d 1
xsy420 commented 2 months ago

or just run it if you don't want to reinstall

eylenburg commented 2 months ago

Amazing, that fixed it! Thank you!