STANAANDREY

wsl install

Feb 21st, 2026 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # $InstallDrive = Read-Host -Prompt "Which drive letter? (e.g. D: or E:)"
  2.  
  3. # --- CONFIGURATION (Change these as needed) ---
  4. $DistroName = "Ubuntu-HDD"             # The name you want for WSL
  5. $InstallDrive = "E:"                   # Change to D:, C:, etc.
  6. $InstallFolder = "$InstallDrive\WSL"   # Where the files will live
  7. $UserName = "stade"                    # Your Linux username
  8. # ----------------------------------------------
  9.  
  10. # 1. Create Directories
  11. if (!(Test-Path $InstallFolder)) {
  12.     New-Item -ItemType Directory -Force -Path $InstallFolder
  13.     New-Item -ItemType Directory -Force -Path "$InstallFolder\Ubuntu"
  14. }
  15.  
  16. Write-Host "--- Checking for WSL Kernel Update ---" -ForegroundColor Cyan
  17. $KernelUrl = "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi"
  18. $KernelPath = "$InstallFolder\wsl_update.msi"
  19.  
  20. if (!(Test-Path $KernelPath)) {
  21.     Invoke-WebRequest -Uri $KernelUrl -OutFile $KernelPath
  22.     Write-Host "Kernel downloaded. Please finish the installer window if it pops up." -ForegroundColor Yellow
  23.     Start-Process $KernelPath -Wait
  24. }
  25.  
  26. Write-Host "--- Downloading Ubuntu App Package ---" -ForegroundColor Cyan
  27. $UbuntuUrl = "https://aka.ms/wslubuntu2204"
  28. $ZipPath = "$InstallFolder\Ubuntu.zip"
  29. $ExtractPath = "$InstallFolder\Temp_Files"
  30.  
  31. if (!(Test-Path $ZipPath)) {
  32.     Invoke-WebRequest -Uri $UbuntuUrl -OutFile $ZipPath
  33. }
  34.  
  35. Write-Host "--- Extracting Files (This takes a moment) ---" -ForegroundColor Cyan
  36. Expand-Archive -Path $ZipPath -DestinationPath $ExtractPath -Force
  37.  
  38. # Find the internal installer (x64.appx)
  39. $InternalAppx = Get-ChildItem -Path $ExtractPath -Filter "*x64.appx" | Select-Object -First 1
  40. $InternalZip = "$InstallFolder\install.zip"
  41. $FinalSource = "$InstallFolder\Source"
  42.  
  43. Rename-Item -Path $InternalAppx.FullName -NewName $InternalZip -Force
  44. Expand-Archive -Path $InternalZip -DestinationPath $FinalSource -Force
  45.  
  46. Write-Host "--- Importing WSL to $InstallDrive ---" -ForegroundColor Cyan
  47. # Unregister if it exists to prevent errors
  48. wsl --unregister $DistroName 2>$null
  49. wsl --import $DistroName "$InstallFolder\Ubuntu" "$FinalSource\install.tar.gz" --version 2
  50.  
  51. Write-Host "--- Setting up User: $UserName ---" -ForegroundColor Cyan
  52. # This adds the user and sets them as default in one go
  53. wsl -d $DistroName -- useradd -m -G sudo -s /bin/bash $UserName
  54. wsl -d $DistroName -- exec bash -c "echo -e '[user]\ndefault=$UserName' > /etc/wsl.conf"
  55.  
  56. Write-Host "--- DONE! ---" -ForegroundColor Green
  57. Write-Host "Your WSL is now on $InstallDrive. Launch it with: wsl -d $DistroName"
Advertisement
Add Comment
Please, Sign In to add comment