Skip to content

WSL2 distro terminatation via wsl.exe command skips systemd shutdown sequence #13435

@JyJyJcr

Description

@JyJyJcr

Windows Version

Microsoft Windows [Version 10.0.26100.4946]

WSL Version

2.5.10.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

6.6.87.2-microsoft-standard-wsl2

Distro Version

Debian 13 / Ubuntu 24.04

Other Software

No response

Repro Steps

Prerequisite
  • systemd is enabled via /etc/wsl.conf.
Passive procedure
  1. Start the distro: wsl -d <distro>
  2. Terminate the distro and log the timestamp: wsl -t <distro>;date
  3. restart the distro and inspect the shutdown logs using the recorded timestamp.
Active procedure
  1. Start the distro and enter the shell: wsl -d <distro>
  2. Create the following systemd unit file at /etc/systemd/system/shuttest.service:
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/bin/date
StandardOutput=append:/path/to/log/file # change here

[Install]
WantedBy=multi-user.target
  1. Make systemd recognize, enable, and start the service: sudo systemctl daemon-reload; sudo systemctl enable --now shuttest
  2. Terminate the distro and log the timestamp: wsl -t <distro>;date
  3. Restart the distro and check the log file: cat /path/to/log/file

Expected Behavior

According to the source code of WSL init:

WSL/src/linux/init/init.cpp

Lines 2510 to 2522 in feb9ad9

//
// If the distro init process was booted, use the shutdown command to terminate the instance.
//
if (Config.BootInit && !Config.BootStartWriteSocket)
{
UtilExecCommandLine("systemctl reboot", nullptr);
}
reboot(RB_POWER_OFF);
FATAL_ERROR("reboot(RB_POWER_OFF) failed {}", errno);
return;

when WSL terminates, it is expected to call systemctl reboot, which should trigger the proper systemd shutdown sequence.

Therefore, when terminating a distro using wsl.exe:

> wsl -t Debian;date
この操作を正しく終了しました。

2025年8月29日 0:01:31

Passive procedure

journald logs should confirm the systemd shutdown sequence is executed:

Aug 29 00:01:32 jyjyjcr-wsl2 systemd[1]: Reached target shutdown.target - System Shutdown.
Aug 29 00:01:32 jyjyjcr-wsl2 systemd[1]: Reached target final.target - Late Shutdown Services.
Aug 29 00:01:32 jyjyjcr-wsl2 systemd[1]: systemd-poweroff.service: Deactivated successfully.
Aug 29 00:01:32 jyjyjcr-wsl2 systemd[1]: Finished systemd-poweroff.service - System Power Off.
Aug 29 00:01:32 jyjyjcr-wsl2 systemd[1]: Reached target poweroff.target - System Power Off.
Aug 29 00:01:32 jyjyjcr-wsl2 systemd[1]: Shutting down.
Aug 29 00:01:32 jyjyjcr-wsl2 systemd-journald[39]: Journal stopped
Active procedure

The custom service should log a stop timestamp, which matches the timestamp of distro termination:

Fri Aug 29 12:01:31 AM JST 2025
Note

These logs are actually generated when sudo systemctl poweroff is executed manually.

Actual Behavior

When terminating a distro using wsl.exe:

> wsl -t Debian;date
この操作を正しく終了しました。

2025年8月28日 23:53:00

Passive procedure

No shutdown sequence is logged. journald shows an abrupt stop:

Aug 28 23:52:52 jyjyjcr-wsl2  sudo[212]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=1000)
Aug 28 23:52:52 jyjyjcr-wsl2  sudo[212]: pam_unix(sudo:session): session closed for user root
Aug 28 23:53:00 jyjyjcr-wsl2  Exception:
Aug 28 23:53:00 jyjyjcr-wsl2  unknown: Operation canceled @p9io.cpp:258 (AcceptAsync)
Aug 28 23:53:00 jyjyjcr-wsl2  unknown:
Aug 28 23:53:09 jyjyjcr-wsl2  kernel: Linux version 6.6.87.2-microsoft-standard-WSL2 (root@439a258ad544) ...
Active procedure

The service stop timestamp is missing, suggesting that ExecStop was never called.

Possible cause

The shutdown trigger systemctl reboot is asynchronous (See manpage). WSL init process will reach reboot(RB_POWER_OFF) before systemd shutdown sequence finished.

Diagnostic Logs

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions