--- type: "topic" created: "2024-01-27T21:40:52.697Z" updated: "2024-01-27T21:40:52.697Z" --- # Windows Subsystem for Linux (wsl) ```bash # https://petri.com/how-to-install-wsl-on-windows-server/ # Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux # https://learn.microsoft.com/en-us/windows/wsl/install-manual ``` ```bash wsl --update # https://learn.microsoft.com/en-us/windows/wsl/install-manual dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart # https://you.com/search?q=wslregisterdistribution+failed+with+error%3A+0x80004002&tbm=youchat&cfr=chatb&cid=c2_d1b54505-473d-4355-94d4-de4192af7c61 dism.exe /online /cleanup-image /restorehealth sfc /scannow wsl --set-default-version 2 # https://www.microsoft.com/store/productId/9N0DX20HK701 # https://www.microsoft.com/store/productId/9PDXGNCFSCZV ``` ```bash apt install software-properties-common apt update apt-get install links unzip -y nano /etc/wsl.conf ``` ```conf [boot] systemd=true ``` ```bash systemd wsl # https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/ # https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-10#2-install-wsl wsl --unregister ubuntu wsl --install -d ubuntu apt install software-properties-common apt update apt-get install links unzip php8.1-fpm php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-soap php8.1-zip php8.1-bcmath -y nano /etc/wsl.conf ``` ```conf [boot] systemd=true ``` ```conf date.timezone = US/Arizona display_errors = On memory_limit = 256M upload_max_filesize = 100M post_max_size = 100M ``` ```bash piwigo Logan0907 piwigo piwigo_ piwigo Logan0907 Logan0907 mikepharesjr@msn.com ``` ```bash # Hello there, This error message is affiliated with Windows update and solving the update issue might help you in this. Can you double check that the Windows Subsystem for Linux optional feature is still enabled? The below steps will reset the Windows update components and see if that helps Open Command Prompt (Admin) Copy and paste the following commands, pressing Enter each time: net stop wuauserv net stop cryptSvc net stop bits net stop msiserver # Press Win + E to open File Explorer Go to the following directories and delete the contents of these folders: C:\Windows\System32\catroot2 C:\Windows\SoftwareDistribution # Open Command Prompt again and paste these command lines: net start wuauserv net start cryptSvc net start bits net start # msiserver Restart your PC. Hope this resolves your Query !! --If the reply is helpful, please Upvote and Accept it as an answer-- ``` ```bash wsl hostname -i netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=127.0.1.1 netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.27.160.1 netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.27.174.2 ``` ```PowerShell # https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723 $remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '" $found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; if( $found ){ $remoteport = $matches[0]; } else{ echo "The Script Exited, the ip address of WSL 2 cannot be found"; exit; } #[Ports] #All the ports you want to forward separated by coma $ports=@(80,443,10000,3000,5000); #[Static ip] #You can change the addr to your ip config to listen to a specific address $addr='0.0.0.0'; $ports_a = $ports -join ","; #Remove Firewall Exception Rules iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' "; #adding Exception Rules for inbound and outbound Rules iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP"; iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP"; for( $i = 0; $i -lt $ports.length; $i++ ){ $port = $ports[$i]; iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr"; iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport"; } ``` ```bash wsl -d Ubuntu Ubuntu-MAAS ``` ```bash # https://learn.microsoft.com/en-us/windows/wsl/wsl-config code-insiders .wslconfig ``` ```conf [wsl2] networkingMode=mirrored ``` - [usbipd-win](https://github.com/dorssel/usbipd-win) ```bash winget install usbipd ``` - [wsl2-how-to-prepare-and-attach-virtual-drives-vhd](https://anthony-f-tannous.medium.com/wsl2-how-to-prepare-and-attach-virtual-drives-vhd-ac17b1fc7a61) ```Powershell New-VHD -Path $env:USERPROFILE\wsl2-shared.vhdx -Dynamic -SizeBytes 10GB wsl -d Ubuntu --mount --vhd $env:USERPROFILE\wsl2-shared.vhdx --bare # wsl --unmount \\?\C:\users\mikep\wsl2-Images-7007a9df.vhdx ``` ```bash parted /dev/sdd print # Error: /dev/sdd: unrecognised disk label parted /dev/sdd mklabel msdos parted -a optimal /dev/sdd mkpart primary ext4 0% 100% lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT /dev/sdd mkfs.ext4 /dev/sdd1 e2label /dev/sdd1 vhd-part1 lsblk -o NAME,LABEL,FSTYPE,SIZE,MOUNTPOINT /dev/sdd mount UUID=f8aac60b-32f3-43d4-8919-d76816d64907 /home//vhd-part1 mount -l | grep vhd-part1 touch /home//vhd-part1/test ls /home//vhd-part1/test rm /home//vhd-part1/test umount /home//vhd-part1 ``` ```Powershell # https://learn.microsoft.com/en-us/windows/wsl/disk-space#how-to-locate-the-vhdx-file-and-disk-path-for-your-linux-distribution wsl.exe --system -d Ubuntu df -h /mnt/wslg/distro wsl df -h / (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Ubuntu' }).GetValue("BasePath") + "\ext4.vhdx" # C:\Users\mikep\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState # \\wsl.localhost\Ubuntu\var ``` ```PowerShell # convert docker to wsl # https://polach.me/posts/transform-any-linux-docker-image-to-wsl2-distribution-by-powershell-easily/ # docker pull fedora # docker create -t -i fedora bash # docker export --output="fedorawsl2img.tar" fedora # wsl.exe -–import Fedora c:\FedoraWslDisk fedorawsl2img.tar download-wsl2-imgage.ps1 -Image library/fedora -Tag 32 -Destination C:\WslImages\Fedora ```