Wsl2 windows 10 debian

About

As of March 2018 Debian is available for Windows users through the Windows store as an app for the Windows Subsystem for Linux (WSL).

The app gives you a Debian stable command line environment running on the Windows kernel (WSL1) or Hyper-V with the new WSL 2 interface depending on your Windows 10 release version. Most of the packages in Debian stable should «just work».

Install

  • Note: As of the time of writing, 2024-06-28, your best option for installing and using Debian GNU/Linux on WSL will probably be to use the WSL 2 subsystem and systemd mode. The Microsoft documentation for achieving this is rather fragmented. Therfore a detailed instruction is given in more detail under a separate heading below.

To use the store app you have to enable the WSL subsystem first by following the guide.

Afterwards just install the Debian app from the Microsoft Store.

You will be asked to define a user and password upon first start. This user will also be given sudo rights.

There is a way to install the Debian WSL distro offline & without using Microsoft Market.

Further information about the ongoing development of WSL can be found in the WSL tag of the Microsoft blog.

WSL 2 with systemd support

Microsoft partnered with Canonical to bring systemd support to WSL 2, and it is also available for Debian and other GNU/Linux distributions.

WSL 2 with systemd is probably what you want for your freshly installed Debian GNU/Linux system, as WSL 2 is a prerequisite for GUI application support, and systemd is a prerequisite for many Debian packages. Read more about GUI apps here.

At the time of this writing, 2024-06-28, the documentation over at Microsoft Learn for acieving a Debian install in a WSL 2 subsystem with systemd activated is rather fragmented. Therefore the process is detailed here.

  • Note that a Windows 11 operating system for hosting WSL is assumed.

Lengtly description follows here:

To prepare your system:

  1. Make sure your computer has the Virtualization features enabled in UEFI Settings (some may refer to this as BIOS Settings).
  2. Activate and install the needed features and software on your Windows host OS. Open PowerShell in Administrator mode and type these commands:

     dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
     dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

  3. Reboot your Windows 11 host
  4. Update your WSL Linux kernel update package. Open PowerShell in administrator mode and enter the ffollowing command

     wsl.exe --update

    • This will install and update WSL from Microsoft Store
    • If you do dot wish or cannot use Microsoft Store, please consult this Microsoft Learn article

To install Debian GNU/Linux

  1. Giong forward we are in usermode. So you must open normal PowerShell without administrator mode for the steps in this section.

  2. Set WSL 2 as you default WSL version. This is a per-user setting in Windows.
     wsl --set-default-version 2

  3. Install Debian
     wsl --install -d Debian

    • This takes some time
  4. Set a username and password for your Debian GNU/Linux installation when prompted

    • You are now logged in to your Debian system in command line mode
  5. Add some text to the file /etc/wsl.conf to activate systemd mode on next boot of WSL 2

     sudo echo '
     [boot]
     systemd=true' >> /etc/wsl.conf

    Provide the user password you set in the previous step when prompted.

  6. Verify the content of the file /etc/wsl.conf and correct any errrors. There should be only one section [boot] and exactly one instance of the line systemd=true in it.

     sudo editor /etc/wsl.conf

  7. Exit to PowerShell by issuing the command logout, or by pressing [Ctrl] + D

  8. Shut down your Debian WSL 2 instance from PowerShell

     wsl --shutdown -d Debian

  9. Start your Debian instance and log back in
     wsl -d Debian -u <username>

  10. Use apt to upgrade your WSL 2 Debian and apt or aptitude to install some packages (mesa-utils is required on the Debian side for the GUI apps integration to work)

     sudo apt update
     sudo apt dist-upgrade
     sudo apt install mesa-utils firefox-esr

  11. The installed programs can be started from a Debian shell, or from the Windows start menu.

Advanced Usage

WSL 2 brings GUI application and sytemd support to WSL. That is, you now can run Debian apps in an integrated desktop mode.

To activate the new GUI application support you have to update your WSL 2 environment to Debian bookworm or later.

After that you need to install mesa-utils this will install all the necessary packages for th GUI app support to work.

Most of the GUI apps in Debian should now just work out-of-the-box (e.g., try firefox).

Feedback

Please use the Microsoft Store review/feedback to report bugs or feature requests for now.

There is a IRC channel on OFTC to discuss WSL related stuff: #debian-wsl

You can also leave patches and issues at the WSL repo on Salsa.

Known Issues

Any software relying on systemd or low-level hardware accessibility might fail due to missing support from the current Windows kernel or virtualization interface.

systemd support has been added to WSL 2. See description of this above.

As WSL is a pretty new project from Microsoft improvement can be expected to happen with every new Windows stable channel release (approx. every 6 months). The app launcher will be updated to support stable release features continuously.

If WSL itself is installed from Microsoft Store, for example by issuing wsl —update in an elevated PowerShell prompt on the Windows Host, Microsoft claims WSL will be updated more frequently and independently of the Windows stable chanel releases.

FAQ

How do I keep my Debian environment up-to-date

as with any other Debian installation use apt/apt-get to install and update software from the official Debian mirrors (e.g., apt update && apt dist-upgrade)

How do I install a newer release?
You can install the app, change your sources.list and upgrade your install as with every other Debian installation.
How many people are using Debian via WSL?
Approximately 1,746,662 at last count (unique installs according to the Microsoft Partner Center dashboard 2024-11-20).

Code & Issues

The full app code and all build dependencies can be found in the WSL repo on salsa.

Debian is one of the oldest Linux distributions available that is currently being maintained actively. Ubuntu, which is the most popular Linux distribution, is based upon the experimental version ‘Sid’. And Ubuntu in turn acts as a base for numerous operating systems such as Linux Mint, Pop_OS!, Linux Lite, etc. Debian is mostly used by servers around the world because Debian is very stable.

Microsoft has recently updated their WSL or Windows Subsystem for Linux to version 2 (termed WSL2) and the Linux instance installed is more usable for all users now. In this tutorial, we will try to install this Debian Linux on our Windows machine using WSL2.

Enable/Install WSL2

If you are using Windows 11, WSL2 is already installed on your system, and you just have to enable it. We will discuss this after learning to install this on Windows 10. Windows 10 users have to first enable WSL on their system. From the Start Menu, search and run Turn Windows features on or off, and launch it. From Here, enable ‘Virtual Machine Platform‘ and ‘Windows Subsystem for Linux‘ and click OK and restart your PC.

Turn On WSL2

Turn On Windows Subsystem For Linux

Now, search and open ‘PowerShell’ application and right-click upon it to run it as administrator. Now, just type the following command and press the Enter key on your keyboard :

Run Powershell As Administrator From The Start Menu

Run PowerShell As Administrator From The Start Menu
wsl --set-default-version 2
wsl --list --online

If you are using Windows 11, open the ‘PowerShell’ application as Administrator and then run the following command :

wsl --set-default-version 2
wsl --list --online

Installing Debian on WSL2

List Available Distributions On WSL2 1

List of Available Distributions On WSL2

Now, the default version that is installed on your PC is Ubuntu (marked by an asterisk here), to install Debian, you can run the following command :

Installing Debian Using WSL2

Installing Debian Using WSL2

If prompted, you should also reboot your system.

Post installation tweaks

Once you restart your PC, you will see a Terminal window waiting for you asking you to create a Username and Password.

Enter Your Username And Password And You Are Now Done With The Installation

Enter Your Username And Password And You Are Now Done With The Installation

Now, you should also update your system to the latest version using the apt command, type the following in your Debian Machine :

sudo apt update && sudo apt full-upgrade
Update Your Debian Installation

Update Your Debian Installation

Summary

While WSL2 provides the complete command line experience to any developer/user, it is still not a complete replacement for actual Installation on a Virtual machine or on bare metal. Applications do not have hardware acceleration and hence drain the battery more and so on. It is still a good decision from Microsoft as many people will have the exposure to Linux command line and maybe even encourage people to fully switch to the Linux Desktop

References

Microsoft’s Official WSL2 Documentation

01 Oct 2024 — by ‘Maurits van der Schee’

So, maybe your employer want you to use Windows. Obviously you still want to use Linux as you want to run whatever operating system your production servers run. If running Virtualbox or VMWare causes too much switching between environments then WSL might be a solution. In this post I’ll show how to install WSL 2 with Debian 12 as the Linux distribution. First we show which Linux distributions you can choose from, by running (from the command prompt):

wsl --list --online

Output is:

The following is a list of valid distributions that can be installed.
The default distribution is denoted by '*'.
Install using 'wsl --install -d <Distro>'.

  NAME                            FRIENDLY NAME
* Ubuntu                          Ubuntu
  Debian                          Debian GNU/Linux
  kali-linux                      Kali Linux Rolling
  Ubuntu-18.04                    Ubuntu 18.04 LTS
  Ubuntu-20.04                    Ubuntu 20.04 LTS
  Ubuntu-22.04                    Ubuntu 22.04 LTS
  Ubuntu-24.04                    Ubuntu 24.04 LTS
  OracleLinux_7_9                 Oracle Linux 7.9
  OracleLinux_8_7                 Oracle Linux 8.7
  OracleLinux_9_1                 Oracle Linux 9.1
  openSUSE-Leap-15.6              openSUSE Leap 15.6
  SUSE-Linux-Enterprise-15-SP5    SUSE Linux Enterprise 15 SP5
  SUSE-Linux-Enterprise-15-SP6    SUSE Linux Enterprise 15 SP6
  openSUSE-Tumbleweed             openSUSE Tumbleweed

If you want to install Debian, you run:

wsl --install --distribution Debian

Output:

Installing: Virtual Machine Platform
Virtual Machine Platform has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Installing: Debian GNU/Linux
Debian GNU/Linux has been installed.

Now we have to restart Windows to enable WSL (v2). Then we see:

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: maurits
Adding user `maurits' ...
Adding new group `maurits' (1000) ...
Adding new user `maurits' (1000) with group `maurits (1000)' ...
Creating home directory `/home/maurits' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
No password has been supplied.
New password:
Retype new password:
No password has been supplied.
New password:
Retype new password:
No password has been supplied.
passwd: Authentication token manipulation error
passwd: password unchanged
Try again? [y/N] N
Changing the user information for maurits
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n]
Adding new user `maurits' to supplemental / extra groups `users' ...
Adding user `maurits' to group `users' ...

We can see the running WSL from a command prompt:

wsl --list -v

Output is:

  NAME      STATE           VERSION
* Debian    Running         2

See how we didn’t enter a password? It is not really required. Now open a windows prompt:

wsl -u root

Now type the following from within WSL to allow sudo without a password:

echo "maurits ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

Now you can exit and start the WSL again and use «sudo» without a password. Install some requirements from WSL:

sudo apt -y update && sudo apt -y upgrade
sudo apt install git wget htop curl

Now also enable systemd (for running MariaDB for instance) by running:

sudo nano /etc/wsl.conf

And in this (new) file add:

[boot]
systemd=true

Download and install VS Code installer (VSCodeUserSetup-x64-1.93.1.exe) in windows from:

https://code.visualstudio.com/

And follow the installer wizard, next, next, next, finish :-)

Next install the «WSL» extension in VS Code to allow access to your Debian environment.

Now restart your WSL using the following command from the windows prompt:

wsl --shutdown

Now ensure you have a SSH key in your WSL by running from within WSL:

ssh-keygen

Now echo the public key and add it to your Github profile:

cat ~/.ssh/id_rsa.pub

Optionally install some PHP development requirements I often use:

sudo apt install mariadb-server mariadb-client memcached php php-mysql php-memcache \
    php-zip php-intl php-mbstring php-cli php-gd php-xml php-curl php-yaml

After doing that you can clone a repository and start VS code from within WSL:

git clone git@github.com:mevdschee/php-crud-api.git
cd php-crud-api
code .

After starting VS Code the following should appear:

Updating VS Code Server to version ...
Removing previous installation...
Installing VS Code Server for Linux x64 (...)
Downloading: 100%
Unpacking: 100%
Unpacked 1765 files and folders to ...
Looking for compatibility check script at .../bin/helpers/check-requirements.sh
Running compatibility check script
Compatibility check successful (0)

You may have to run the last command twice to start VS Code. Don’t forget about «PHP Intelephense (by Ben Mewburn)» and «PHPStan (by swordev)» extensions if you are doing PHP development.

Adding RAM and CPU

The command «htop» on the WSL command-line will show the RAM and CPU usage of the WSL VM. If you feel that there is not enough RAM or CPU threads available in the WSL you can change the 2 CPU 4GB RAM default by making a config file in Windows using:

notepad.exe %UserProfile%/.wslconfig

And enter «8GB» for the memory and «4» for the processors (or another value):

[wsl2]
#Limits VM memory, this can be set as whole numbers using GB or MB
memory=8GB
#Sets the VM to use a number of virtual processors
processors=4

Now stop the WSL using:

wsl --shutdown

And start it again by clicking the nice Debian logo from the start menu to make the configuration effective. In the Windows Task Manager you will see «Vmmem» process representing the WSL machine.

NB: If you run WSL in Win10 pro in KVM on Linux (as I do) then set the sockets in KVM to a maximum of 2 and increase the core count of your VM instead.

Enjoy!

Links

  • Microsoft — How to install Linux on Windows with WSL
  • Microsoft — Advanced settings configuration in WSL
  • TomsHardware.com — How to Install Windows Subsystem for Linux in Windows 11

PS: Liked this article? Please share it
on Facebook,
Twitter
or LinkedIn.


Cover image for Run Debian in Windows 10 with WSL 2

We use Windows in our workstations at my current job (it was not my choice 🙊), but there is a lot of tasks that are easier to do in a Linux environment. Some days ago I needed to manipulate a huge CSV and just thought: «This would be a lot simple with cat, grep, sort, etc.».

So, I remember that I have read something about running Linux inside Windows using WSL and, well, why not give a try?

Setting up the environment

Some considerations:

  • WSL 2 is only available in Windows 10, Version 2004, Build 19041 or higher. Check your Windows version by selecting the Windows logo key + R, type winver, select OK.
  • All Windows commands should be typed in a PowerShell session with administrative privileges unless otherwise specified (right-click in the PowerShell icon and choose «Run as administrator»).

Here we go! Since I’m a command-line lover and do not have a Microsoft account to access Microsoft Store, I’ll do this from there as much as possible. First, let’s install a decent terminal emulator and Microsoft is doing a good job with Windows Terminal. I have downloaded v1.1.2021.0 and renamed it to WindowsTerminal.msixbundle. This is the latest version at the time of writing. The installation is pretty straight forward, just open a PowerShell instance, navigate to the directory where the executable was downloaded and type:

.\WindowsTerminal.msixbundle

Now, click in Instal and wait a few seconds to the windows of Windows Terminal show up. Close this window for now, we need to open it as Administrator soon.

The next step is to enable WSL. Use the same method stated at the top of the article to launch an instance of Windows Terminal with administrative privileges (damn, I wish that there was a «sudo» for this. Maybe Microsoft can launch an «addo» 🙃). Observe that should have a «PS» before your prompt, this indicates that you are in a PowerShell session. Now type:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

The ‘Virtual Machine Platform’ is needed to run WSL 2. To enable it, just type:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

You should see «The operation completed successfully.» to both commands. Now reboot your computer.

Once rebooted, open Windows Terminal again and set WSL2 as default:

wsl —set-default-version

If you already have a distribution installed and like to convert it to use WSL2, this is possible. First, check the current status.

wsl —list —verbose

The above command will show a list of installed distributions separated by NAME, STATE, and VERSION. For instance, if you have an Ubuntu installation that is running at version 1 you can type:

wsl —set-version Ubuntu 2

You also can revert it to WSL 1 if you are not satisfied with the result, just change the version number.

Download and installation

Now it is time to download the distribution that you wish to install. I chose Debian because it is very light and stable. Since Windows 10 Spring 2018 Update, curl.exe is present, so let’s use it.

curl.exe -L -o debian.appx https://aka.ms/wsl-debian-gnulinux

The installation step is also quite simple.

Add-AppxPackage .\debian.appx

A strange progress bar will be displayed. Once it disappears, it is done. Now Debian should be available in your applications menu, but don’t click there, use the Windows Terminal do open a Debian session. On the right side of the tab, there is an arrow that hides all the possible sessions.
Clicking on Debian will lead you to the user configuration screen. Choose your username and password and you are done.

Configuration

Now, I recommend that you update installation:

sudo apt update && sudo apt upgrade

Verify the version of Debian that was installed.

cat /etc/os-release

For an unknown reason by me, the downloaded image was still the Stretch version of Debian. No problem, let’s update it to Debian Buster. First, make a backup of your sources.list file.

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

Now, replace every «stretch» entry with «buster». You can do this with nano or vi or directly with sed.

sudo sed -i ‘s/stretch/buster/g’ /etc/apt/sources.list

Then update the system again.

sudo apt update && sudo apt upgrade && sudo apt full-upgrade

Now get rid of obsolete packages in your system.

sudo apt autoremove

Close the Debian tab and open another one to check if you have installed Debian Buster with success.

cat /etc/os-release

You should see something like the below:

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Final considerations

For a better file system performance, make sure to store your Linux project files in the Linux file system (not the Windows file system).
It is probable that when you open a Debian session your prompt show something like: username@hostname:/mnt/c/Users/username$ This is why WSL exposes the Windows file system through mount points placed in /mnt like /mnt/c and /mnt/d just type cd ~ to go to your real home.

Not only the file system of Windows is exposed by WSL, but you can use Windows applications too, try to type explorer.exe . As you can see, Windows Explorer will open with the files of your current directory loaded.

That is it, everything is set up and ready to use.

Back in 2017, Windows released Windows Subsystem for Linux that lets developers run a GNU/Linux environment, including most command-line tools, utilities, and applications directly in Windows without setting up a virtual machine or dual-boot.

WSL2 has since been released, and it’s an improvement over version 1. The new and improved version comes with performance boost, full system call compatibility, and built with a new architecture and that delivers features that make WSL an amazing way to run a Linux environment in Windows.

To install WSL 2 on Windows 10, these two requirements must be met:

  • Windows 10 May 2020 (2004), Windows 10 May 2019 (1903), or Windows 10 November 2019 (1909) or later
  • A computer with Hyper-V Virtualization support

Since you can now install Linux systems, including Debian directly in Windows, let’s go ahead and install Debian. Before you can do that, you must first enable WSL or WSL2 in Windows.

Enable WSL in Windows

To enable WSL in Windows, you will want to open PowerShell terminal as administrator. Click on Start then begin typing PowerShell.

Next, right-click Windows PowerShell app and choose to run as administrator.

When the console opens, run the commands below:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

After installing, you should get a success message similar to the lines below:

Deployment Image Servicing and Management tool
Version: 10.0.19041.844

Image Version: 10.0.19042.844

Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.

Enable Virtual Machine Platform

WSL 2 requires Windows 10 Virtual Machine Platform to be enabled. This is not Hyper-V. To enable the VM platform feature in Windows, run the commands below from the same PowerShell administrator’s console.

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

If you’re using Windows 10 version lower than 2004, then use the commands below:

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart

When you’re done running the commands above, restart your computer for all the configuration changes to apply. If you don’t restart, the below command might not be recognized.

After restarting your computer, login back in and launch PowerShell as administrator. Then run the commands below to configure WSL 2 as the default version of WSL.

wsl --set-default-version 2

PS: If you get an error about not having Linux kernel installed, get it from the link below and run it in Windows, then try the command above again.

https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

Install Debian in Windows 10

Now that WSL 2 is installed and ready to be used, open the link below to download and install a copy of Debian from Windows store.

  • Get Debian – Microsoft Store

Debian on Windows allows you to use Debian Terminal and run Debian command line utilities including bash, ssh, git, apt and many more.

Click the Get button and install. After installing Debian, you’ll want the option to launch Debian from Windows WSL environment.

After downloading and installing, you will get a Launch button.

After launching Debian, it should install and prompt to create your account.

Installing, this may take a few minutes…
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: ngubri
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
ngubri@DESKTOP-M1235UB:~$

That should do it!

Some troubleshooting commands to run when you run into issues.

wsl --set-default-version 1
bcdedit /set hypervisorlaunchtype auto start

Now simply launch Debian from Windows start by searching for it. You can also pin it to the taskbar and always have it launch from there.

That should do it!

To ensure that WSL 2 is enabled in your system, open the Windows command prompt and run the below-mentioned command:

 wsl -l -v
 //OR
 wsl --list --verbose

Note that the above command only works on Windows build version “18362” and higher. If the output indicates the WSL version properly, that means WSL 2 is enabled in your system:

If you are still running the WSL version 1, then use the following command to enable WSL 2:

 wsl --set-default-version 2

Though WSL 2 is the latest version, there are still some features that are only supported by WSL 1, such as quick access to files stored on Windows, serial port support, etc. So to set a specific version of WSL to a specific distribution, use the command:

wsl --set-version [distro_name] [wsl_version_number]

Replace the “[distro_name]” with the Linux distribution name and mentioned the WSL version in the place of “[wsl_version_number].” (example: wsl –set-version Debian 2)

Conclusion:

WSL is a Windows feature that allows Windows 10 users to run Linux on Windows 10 natively. There are two main versions of WSL; WSL 2 is the updated version of WSL 1 and supports all system calls, and 20% faster than its predecessor.WSL converts the Linux calls into windows calls and executes them, though WSL 2 has its own specifically designed kernel that no longer needed call system translation. After enabling WSL in Windows and installing Linux distribution, you can use bash shell for all compatible utilities. It is quite helpful for developers who are interested to learn Linux on Windows.

WSL 2 uses an actual Linux kernel that allows Linux containers. WSL 1 was genius with running Linux on the Windows kernel, but of course lacked some of the features, such as containers. 

Although the WSL 2 is the current and overhauled version, some exceptions might make you use WSL 1. Which version you should use is a personal choice, but I would recommend going with WSL 2 because it is efficient and allows you to install Linux updates easily.

Reference:

https://websiteforstudents.com/

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Msi cx620 windows 10
  • Как устранить активацию windows
  • Manual windows update blocker
  • Как восстановить системный реестр windows 10
  • Вход в систему с использованием выбранного метода входа запрещен windows 7