Ubuntu WSL Auto Start
Install WSL
WSL should be installed prior to proceeding
Ubuntu 24.04 should be the default Distro
wsl --set-default Ubuntu-24.04
WSL Keep Running
By default Windows will stop WSL after all Terminal windows are closed. This is likely to save resources but it can be frustrating when something like Docker is running, as stopping the WSL instance will shut down all the Docker containers.
The workaround is to simply run this command:
wsl --exec dbus-launch true
The command is used to start a session of dbus-launch in WSL without actually launching any graphical application. This background session will keep the WSL instance active without much of a drawback.
This command is how WSL will be automatically started and kept running.
Task Scheduler
It is really simple to schedule this command to run with Task Scheduler. In the Windows search bar type "Task Scheduler" and open up the app. Click "Create Task..." on the right side.
General
Under the "General" tab:
- Enter "Ubuntu WSL Start" as the "Name"
- Check "Run with highest privileges"
Under the "Triggers" tab select "New..."
- Select "At log on" from the "Begin the task" dropdown
- Ensure it "enabled"
- Click "OK" to save
Under the "Actions" tab select "New..."
- For "Program/script" enter
wsl.exe
- Then for "Add arguments" enter
--exec dbus-launch true
- Click "OK" to save
Under the "Conditions" tab, uncheck everything.
Under the "Settings" tab make sure the following are checked:
- Allow task to be run on demand
- Run task as soon as possible after a scheduled start is missed
- Stop the task if it runs longer than 3 days
- If the running task does not end when requested, force it to stop
Finally, click "OK" to save the task. Now reboot and then open up a Terminal and check to see if Ubuntu is running:
wsl -l -v