0

I'm running some servers on my Ubuntu instance on WSL through windows 11. For those servers to run, I need to mount a hard drive, which i do with the command

wsl --mount //./PHYSICALDRIVE0

The above command needs to be run from the PowerShell as Administrator
After that i need to launch my default instance

Is there a way to automate this process so it happens silently when i boot windows?

1 Answers1

1

Using the windows task scheduler, create a new task, and tell it to:

  • run at startup in the scheduling settings
  • run as administrator (with highest privileges)
  • run even if user is not logged in,

set it to launch a program: powershell.exe with arguments -C wsl --mount //./PHYSICALDRIVE0

Cpt.Whale
  • 4,501
  • 2
  • 13
  • 25
  • i'm going to try it out soon and will accept your answer as correct when confirmed. Thanks – André Alçada Padez Mar 01 '23 at 22:49
  • one more question: that task will only mount the drive, it won't start my machine after the mount. Is there a way to do these two operations sequentially on the same task? or am i missing something? thank you – André Alçada Padez Mar 01 '23 at 22:53
  • 1
    @AndréAlçadaPadez running a wsl command should start up wsl? Otherwise, powershell will take multiple commands separated by semicolon, like `-C foo x;bar y` etc. Starting from task scheduler args means no multiline (and special characters can be weird), so usually just call a script if you need anything complicated. – Cpt.Whale Mar 02 '23 at 16:32
  • It is difficult to have task scheduler run wsl commands at boot, although pretty straightforward to have it run those commands when a user first logs in. See the issues discussed in [this superuser question](https://superuser.com/questions/1754734/how-to-run-wsl-on-windows-11-boot-as-service/1765794#1765794). I will be very interested if you are successful! – Geeky51 Mar 03 '23 at 23:19