Skip to content

Fix: add systemd unit to make /mnt/wsl recursive slave before umount#41086

Open
chemwolf6922 wants to merge 5 commits into
masterfrom
user/chemwolf6922/avoid-systemd-from-globally-unmounting-shared-mounts
Open

Fix: add systemd unit to make /mnt/wsl recursive slave before umount#41086
chemwolf6922 wants to merge 5 commits into
masterfrom
user/chemwolf6922/avoid-systemd-from-globally-unmounting-shared-mounts

Conversation

@chemwolf6922

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Systemd globally unmounts shared mounts under /mnt/wsl during graceful shutdown.

This PR adds a systemd unit to set /mnt/wsl as recursive slave during shutdown before unmounting to avoid the unmount from propagating to other namespaces.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Add regression test:
UnitTests::UnitTests::SharedMountSurvivesDistroTermination

@chemwolf6922
chemwolf6922 requested a review from a team as a code owner July 16, 2026 04:46
Copilot AI review requested due to automatic review settings July 16, 2026 04:46
@chemwolf6922 chemwolf6922 changed the title Add systemd unit to make /mnt/wsl recursive slave before umount Fix: add systemd unit to make /mnt/wsl recursive slave before umount Jul 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a WSL2 systemd shutdown regression where unmounts under /mnt/wsl in one systemd-enabled distro can propagate across shared mount peer groups and break other running distros (notably Docker Desktop’s WSL integration). It does so by generating/enabling a systemd unit that switches /mnt/wsl to rslave propagation during shutdown, preventing unmount propagation to other namespaces.

Changes:

  • Generate and enable a wsl-mnt-guard.service unit to run mount --make-rslave /mnt/wsl on shutdown (ExecStop) before unmount propagation can escape the terminating distro.
  • Add a Windows UnitTests regression test that creates a shared mount under /mnt/wsl, terminates a peer systemd distro, and verifies the mount remains available.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/linux/init/init.cpp Generates and enables a new systemd unit (wsl-mnt-guard) to prevent shutdown unmount propagation from escaping the distro.
test/windows/UnitTests.cpp Adds a regression test to ensure a /mnt/wsl shared mount survives termination of a peer systemd-enabled distro.

Comment thread test/windows/UnitTests.cpp Outdated
Copilot AI review requested due to automatic review settings July 16, 2026 05:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/linux/init/init.cpp
Copilot AI review requested due to automatic review settings July 16, 2026 06:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 16, 2026 06:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 16, 2026 07:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Graceful shutdown of any systemd distro unmounts shared /mnt/wsl mounts in ALL distros (breaks Docker Desktop WSL integration VM-wide)

2 participants