1

The documentation to mount ext4 drive into Windows using WSL is clearly explain here (https://learn.microsoft.com/en-us/windows/wsl/wsl2-mount-disk)

However, anytime I close my WSL2 session, I lose access to the drive from within windows... as expected.

Is there a workaround to keep WSL running in the background so that my mounted drive(s) continue to be accessible from within Windows?

3
  • Have you created the appropriate fstab file? How you do what you want would be no different than any other Linux environment
    – Ramhound
    Commented Aug 24, 2023 at 18:46
  • 1
    I think you are not understanding the question. WSL instance will terminate when it s window is closed, thus unmounting any drives that were mounted during the session. I want to keep the drives mounted even after closing WSL to be able to use them in Windows. Commented Aug 24, 2023 at 19:21
  • You should edit your question to make it clear you looking to configure a persistent network share within Windows, and make it clear, the network location is pointing to the WSL instance. As it was written my original thought was you were trying to have a persistent network share within WSL. It's my believe that you are attempting to use WSL in such a way it wasn't designed to support. You should probably just use a VM that is automatically launched (and shutdown) when the the host system powers on and off.
    – Ramhound
    Commented Aug 24, 2023 at 20:13

1 Answer 1

1

I found a way to keep a mounted drive available in Windows even after closing the WSL2 window. After having the drive properly mounted in WSL and accessible via Windows explorer, the trick was to keep the WSL2 Ubuntu instance running in the background.

That can be done by creating a CMD script (i.e. wsl_bg.cmd) in in the Windows startup folder: (crl+r -> shell:startup)

wsl_bg.cmd:

wsl bash -c "nohup bash -c 'while true; do sleep 1h; done &' &>/dev/null "

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .