Skip to main content

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:

  1. Enter "Ubuntu WSL Start" as the "Name"
  2. Check "Run with highest privileges"

Under the "Triggers" tab select "New..."

  1. Select "At log on" from the "Begin the task" dropdown
  2. Ensure it "enabled"
  3. Click "OK" to save

Under the "Actions" tab select "New..."

  1. For "Program/script" enter wsl.exe
  2. Then for "Add arguments" enter --exec dbus-launch true
  3. Click "OK" to save

Under the "Conditions" tab, uncheck everything.

Under the "Settings" tab make sure the following are checked:

  1. Allow task to be run on demand
  2. Run task as soon as possible after a scheduled start is missed
  3. Stop the task if it runs longer than 3 days
  4. 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