You can check which version is each installed distribution with the command,
wsl -l -v
as this superuser question states.
But is it possible to know the WSL version (1 or 2) from inside the Linux installation?
Is there any reliable mechanism to check the version?
What I found?
Environment and "interop"
The only difference in environment variables, is that WSL 2 has one named WSL_INTEROP
that version 1 has not.
That variable points to a path special file.
Kernel version
This reddit post reply points to use the following command,
uname -r | tr '[:upper:]' '[:lower:]'
WSL 1 output:
4.4.0-19041-microsoft
WSL 2 output:
5.4.72-microsoft-standard-wsl2
Could this be an option except the replies given,
Probably better not to go with a kernel check as you can build and install your own kernel, and some people would strip that out.
Although this askubuntu accepted answer states
If the kernel version => 4.19, it's WSL Version 2.
Any other options/ideas?
Addendum: github/WSL repo has the issue #4555.