Ubuntu WSL Auto Start
This guide will provide instructions on how to have WSL auto start at log in
Windows 11 - Auto Start Ubuntu WSL
Install WSL
WSL should be installed with Ubuntu 24.04 set as the default distro prior to proceeding.
wsl --set-default Ubuntu-24.04WSL 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 trueThe 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 is "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