hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.

Home Page:http://www.packer.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WSL distro (Ubuntu) missing on the Windows Server 2022 Image created with Windows-2022.pkr.hcl

Codes-Lab opened this issue · comments

commented

Hi all,

I am new to the community and just started to work with Packer. I am currently trying to build a Windows-2022 image with Packer having WSL and Ubuntu as distribution installed. Surprisingly the image creation until the last step prints out that Ubuntu is installed as the default distro but somehow I cannot see the Ubuntu distro when I created the VM from the image although WSL is installed and working.

Edit: I updated the windows-2022.pkr.hcl template to install the WSL and ubuntu with the following custom scripts.

Install-Binary -Type MSI -Url "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi"
 Write-Host "Setting WSL default version to 2"
 wsl --set-default-version 2

 # Installing Ubuntu
 $ubuntuAppxPath = Invoke-DownloadWithRetry "https://aka.ms/wslubuntu2004" -Path "${env:SystemDrive}\Users\${env:INSTALL_USER}\$fileName"
 Write-Host "ubuntuAppxPath is : ${ubuntuAppxPath}"

 Write-Host "Expanding Ubuntu bundle"
 [string] $tempName = [System.Guid]::NewGuid()
 $ubuntuExpandPath = "${env:SystemDrive}\Users\$env:INSTALL_USER\Ubuntu\$tempName"
 Expand-Archive $ubuntuAppxPath $ubuntuExpandPath

 Write-Host "Expanding ubuntu application"
 $ubuntuAppx = Get-Item -Path $ubuntuExpandPath/*_x64.appx
 Move-Item $ubuntuAppx $ubuntuExpandPath/ubuntu.zip
 Expand-Archive $ubuntuExpandPath/ubuntu.zip $ubuntuExpandPath -Force

 Write-Host "Installing Ubuntu"
 & $ubuntuExpandPath\ubuntu.exe install --root
 if($LASTEXITCODE -ne 0) {
    Write-error "Failed to install Ubuntu 2004 under wsl"
 }

Ubuntu was downloaded from https://aka.ms/wslubuntu2004 to a folder installer and it was under Users and I could the installed files under this folder in the VM created from Image.

Logs from the image creation:

==> azure-arm.image: Provisioning with powershell script: /home/vsts/work/1/s/images/windows/templates/../../win/scripts/Installers/Windows2022/Install-Ubuntu.ps1
    azure-arm.image: list of installed wsl Windows Subsystem for Linux has no installed distributions.   Distributions can be installed by visiting the Microsoft Store:   https://aka.ms/wslstore   
    azure-arm.image: Downloading Ubuntu 20.04
    azure-arm.image: Downloading package from https://aka.ms/wslubuntu2004 to C:\Users\installer\UbuntuonWindows.zip...
    azure-arm.image: Package downloaded in 122.63 seconds
    azure-arm.image: ubuntuAppxPath is : C:\Users\installer\UbuntuonWindows.zip
    azure-arm.image: Expanding Ubuntu bundle
    azure-arm.image: Expanding ubuntu application
    azure-arm.image: Installing Ubuntu
    azure-arm.image: Installing, this may take a few minutes...
    azure-arm.image: Installation successful!
    azure-arm.image: Ubuntu installation successful

==> azure-arm.image: Provisioning with powershell script: /home/vsts/work/1/s/images/windows/templates/../scripts/WSLCheck.ps1
    azure-arm.image: list of installed wsl Windows Subsystem for Linux Distributions:   Ubuntu (Default)   
    azure-arm.image: Docker status
    azure-arm.image: wslDocker  * Docker is not running
==> azure-arm.image: Provisioning with Powershell...
==> azure-arm.image: Provisioning with powershell script: /tmp/powershell-provisioner2805888685
    azure-arm.image: IMAGE_STATE_COMPLETE
==> azure-arm.image: Querying the machine's properties ...
==> azure-arm.image: Querying the machine's additional disks properties ...
==> azure-arm.image: Powering off machine ...
==> azure-arm.image: Generalizing machine ...
==> azure-arm.image: Capturing image ...
==> azure-arm.image: 
==> azure-arm.image: Deleting Virtual Machine deployment and its attatched resources...

Does anyone have faced a similar issue or am I dumb to understand it, does someone have any idea how to fix it?

More Information: It seems the registry entry for the Lxss default Distribution went missing in the created image.
Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss

Hi 👋 thanks for reaching out.

For general questions we recommend reaching out to the [community forum](https://discuss.hashicorp.com/c/packer) for greater visibility.
As the GitHub issue tracker is only watched by a small subset of maintainers and is really reserved for bugs and enhancements, you'll have a better chance of finding someone who can help you in the forum.
We'll mark this issue as needs-reply to help inform maintainers that this question is awaiting a response.
If no activity is taken on this question within 30 days it will be automatically closed.

If you find the forum to be more helpful or if you've found the answer to your question elsewhere please feel free to post a response and close the issue.
commented

I learned that WSL distribution (in my case Ubuntu) installation is user-specific, I created a new user and used the same user in my pipelines which fixed the issue for me. So this is not a problem for me anymore.