Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # $InstallDrive = Read-Host -Prompt "Which drive letter? (e.g. D: or E:)"
- # --- CONFIGURATION (Change these as needed) ---
- $DistroName = "Ubuntu-HDD" # The name you want for WSL
- $InstallDrive = "E:" # Change to D:, C:, etc.
- $InstallFolder = "$InstallDrive\WSL" # Where the files will live
- $UserName = "stade" # Your Linux username
- # ----------------------------------------------
- # 1. Create Directories
- if (!(Test-Path $InstallFolder)) {
- New-Item -ItemType Directory -Force -Path $InstallFolder
- New-Item -ItemType Directory -Force -Path "$InstallFolder\Ubuntu"
- }
- Write-Host "--- Checking for WSL Kernel Update ---" -ForegroundColor Cyan
- $KernelUrl = "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi"
- $KernelPath = "$InstallFolder\wsl_update.msi"
- if (!(Test-Path $KernelPath)) {
- Invoke-WebRequest -Uri $KernelUrl -OutFile $KernelPath
- Write-Host "Kernel downloaded. Please finish the installer window if it pops up." -ForegroundColor Yellow
- Start-Process $KernelPath -Wait
- }
- Write-Host "--- Downloading Ubuntu App Package ---" -ForegroundColor Cyan
- $UbuntuUrl = "https://aka.ms/wslubuntu2204"
- $ZipPath = "$InstallFolder\Ubuntu.zip"
- $ExtractPath = "$InstallFolder\Temp_Files"
- if (!(Test-Path $ZipPath)) {
- Invoke-WebRequest -Uri $UbuntuUrl -OutFile $ZipPath
- }
- Write-Host "--- Extracting Files (This takes a moment) ---" -ForegroundColor Cyan
- Expand-Archive -Path $ZipPath -DestinationPath $ExtractPath -Force
- # Find the internal installer (x64.appx)
- $InternalAppx = Get-ChildItem -Path $ExtractPath -Filter "*x64.appx" | Select-Object -First 1
- $InternalZip = "$InstallFolder\install.zip"
- $FinalSource = "$InstallFolder\Source"
- Rename-Item -Path $InternalAppx.FullName -NewName $InternalZip -Force
- Expand-Archive -Path $InternalZip -DestinationPath $FinalSource -Force
- Write-Host "--- Importing WSL to $InstallDrive ---" -ForegroundColor Cyan
- # Unregister if it exists to prevent errors
- wsl --unregister $DistroName 2>$null
- wsl --import $DistroName "$InstallFolder\Ubuntu" "$FinalSource\install.tar.gz" --version 2
- Write-Host "--- Setting up User: $UserName ---" -ForegroundColor Cyan
- # This adds the user and sets them as default in one go
- wsl -d $DistroName -- useradd -m -G sudo -s /bin/bash $UserName
- wsl -d $DistroName -- exec bash -c "echo -e '[user]\ndefault=$UserName' > /etc/wsl.conf"
- Write-Host "--- DONE! ---" -ForegroundColor Green
- Write-Host "Your WSL is now on $InstallDrive. Launch it with: wsl -d $DistroName"
Advertisement
Add Comment
Please, Sign In to add comment