Is it possible to automount drive using wsl --mount after restart?

3.9k views Asked by At

I am able to mount my ext4 partition in wsl-2 using the following command in powershell:

wsl --mount \\.\PHYSICALDRIVE4 --partition 1

However when I either restart my computer or run wsl --restart the partition is unmounted and I have to run the above command again. Is there a way of automounting the partition?

Thanks.

2

There are 2 answers

3
Jscore On BEST ANSWER

After asking around on the wsl github, this option is currently not supported however there is a work around solution which is below for anyone who needs this functionality.

REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "Mount PhysicalDrive4" /t REG_SZ /F /D "C:\Windows\System32\wsl.exe --mount \\.\PHYSICALDRIVE4 --partition 1"

Also I forgot to say this functionality is only available for Windows Insiders preview build 20211 and above.

The solution proposed by @dopewind below doesn't work in this case as ext4 mounting in wsl-2 has to happen in powershell (with admin rights) and not in the installed linux distro.

0
nexuswho On

Just add the command to the end of .bashrc file in your home directory in WSL ( or the .zshrc file if you use zsh )