Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Genie 1.43 Does Not Shutdown Cleanly #185

Closed
00110110010000010011001101000110 opened this issue Aug 3, 2021 · 7 comments
Closed

Genie 1.43 Does Not Shutdown Cleanly #185

00110110010000010011001101000110 opened this issue Aug 3, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@00110110010000010011001101000110

Windows version (build number):
Windows 10 21H1 (Build 19043.1151) x86-64

Linux distribution:
Ubuntu 20.04 LTS

Genie version:
1.43

Describe the bug
Running Windows native binaries (e.g. ipconfig.exe) works in WSL and inside Genie. However, I've noticed that after running genie --shutdown the Windows binaries no longer work in WSL. Genie must be started again for any of them to work. This issue does not occur in Genie 1.42.

To Reproduce
Steps to reproduce the behavior:

  1. Start fresh WSL session (do wsl --shutdown first if needed)
  2. Run /mnt/c/Windows/system32/ipconfig.exe and confirm the output is displayed correctly
  3. Start genie (I use exec /usr/bin/genie -s in an alias)
  4. Inside genie, run /mnt/c/Windows/system32/ipconfig.exe and confirm the output is displayed correctly
  5. In a new WSL shell shutdown genie (I ran genie --shutdown)
  6. In the WSL shell, run /mnt/c/Windows/system32/ipconfig.exe, which produces the error: "bash: /mnt/c/Windows/system32/ipconfig.exe: cannot execute binary file: Exec format error"
  7. Start genie again (I use exec /usr/bin/genie -s in an alias) and see error: "genie: failed to unmount binfmt_misc filesystem; attempting to continue"
  8. Inside genie, run /mnt/c/Windows/system32/ipconfig.exe and confirm the output is displayed correctly again

Expected behavior
I expected Genie 1.43 to behave the same way as Genie 1.42 where a genie --shutdown would still allow Windows binary execution in WSL.

@zfogg
Copy link

zfogg commented Aug 5, 2021

+1

@cerebrate
Copy link
Member

On the one hand: this specific error is because genie unmounts the /proc/sys/fs/binfmt_misc filesystem before starting systemd, since systemd expects to mount this filesystem itself and it often breaks if this fs is already mounted. See #142 . Remounting this filesystem should fix the problem, and doing this is something I could well add to the shutdown handler.

On the other hand: you're expecting genie to be idempotent, and like the BUGS section says, it isn't, and indeed it can't be. Linux pid/mount namespaces aren't perfect containers, systemd units and other actions inside the bottle can and will change things that affect the outside of the bottle, and in some cases (kernel modules, for example) can and will change things that affect other running distros . And systemd and its units inside the bottle believe , when genie -u calls systemctl poweroff, that it's shutting down the whole machine. There are an arbitrarily large number of possibilities I can't support here.

All of which is to say that despite the above potential fix for this issue, in the bigger picture, there are no guarantees whatsoever that the outside-genie session will be preserved as is or even be usable once genie exits. That what you're doing - continuing to use a distro session after genie -u - works at all is pure luck, and I strongly suggest not doing it.

@00110110010000010011001101000110
Copy link
Author

That's fair enough.

The reason I am doing this at all is to dynamically grab the Windows DNS entry for WSL on opening a new terminal and overwrite /etc/systemd/resolved.conf (if the IP differs) for when Genie is running OR overwrite /etc/resolv.conf (if the IP differs) when Genie is not running or has stopped running.

If there's a better way of doing this, let me know. From your explanation, though, it sounds like the only reliable thing to do is to initially set /etc/systemd/resolved.conf and /etc/systemd/resolv.conf when opening a new terminal before starting Genie and then only attempting this again after a wsl --shutdown.

@cerebrate
Copy link
Member

Hrm. That's an interesting question.

For the /etc/systemd/resolved.conf side of it, what I might be tempted to do is create a script that grabs the Windows DNS info and does the needful, and then run it from a systemd unit, using the Before= property to make sure that it completes before systemd-resolved.service starts up.

I'm less sure of a good way to handle /etc/resolv.conf . In theory, systemd-resolved wants to own /etc/resolv.conf and will do whatever it wants with it (although note the somewhat messy discussion going on in the bottom of #130 right now...), so - assuming you set it properly at the start of a session when the terminal opens or using .wslconfig - you could probably cobble together a couple of systemd units to make a copy at, oh, /etc/resolv-presystemd.conf before systemd-resolved starts up and then copy it back over /etc/resolv.conf after systemd has shut down systemd-resolved.

(But that's - systemd-resolved and its ownership of /etc/resolv.conf is - another variation on idempotency not guaranteed, so... 😁 )

Or, I suppose, a wrapper script around genie -s could do the same job if you're careful never to invoke it in ways that would bypass the wrapper.

@cerebrate
Copy link
Member

Fix (and more visible relevant warning notes) implemented in 1.44.

(Please note that the dev-1.44 branch will not build externally until I push the next ArkaneSystems.WSL library update, today or tomorrow.)

@00110110010000010011001101000110
Copy link
Author

I still see this issue in 1.44 when I shutdown genie. On starting genie again, it still says: "genie: failed to unmount binfmt_misc filesystem; attempting to continue"

@cerebrate
Copy link
Member

1.44 attempts to remount the binfmt_misc filesystem on shutdown (if you use the -v switch to genie -u when shutting down, it should report success on this, as well as failure).

That said, it attempts to remount the filesystem. There is no guarantee that it succeeds, for a whole host of possible reasons that add up to why continuing to use a session after the bottle exits isn't a supported scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants