How to run Linux commands on WSL startup in Windows 10

Опубликовано: 07 Октябрь 2024
на канале: Tech Forum
2,997
10

#wsl

Refer    • How to Enable Ubuntu Terminal in Wind...   to enable WSL2 with ubuntu distribution in windows 10.

Windows Subsystem for Linux is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows Server 2019. In May 2019, WSL 2 was announced, introducing important changes such as a real Linux kernel, through a subset of Hyper-V features.

As part of the latest Windows 10 Developer Insider build Microsoft enabled the option to run the Linux commands on WSL startup.

For now, the latest Developer insider build(Windows 10 Build 21286.) should be installed to test this capability

ms-settings:windowsinsider
https://aka.ms/WIPWindowsUpdate

This can be achieved by editing the /etc/wsl.conf file in your distribution and adding an option titled "command" under a section titled "boot".

sudo vi /etc/wsl.conf

The wsl.conf is located in each Linux distribution in /etc/wsl.conf. If the file is not there, you can create it yourself. This file can contain
some of the configurations that can be applied every time you launch the subsystem now additionaly linux commands to be executed on startup



This command will run whenever your specific WSL distribution starts up. The new feature can be used to run environment configuration scripts and other Linux commands required to be executed on WSL distribution startup.

Power Shell commands
wsl --list --verbose (view list of wsl distributions)
wsl --shutdown (shutdown all distributions)