You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your Windows build number: Microsoft Windows [Version 10.0.17134.112]
What you're doing and what's happening: No way to do unattended install of WSL
What's wrong / what should be happening instead:
I have to install WSL on several machine and I would like to do it in automated manner (as a part of a workstation setup, so it should work without any prompts etc). I've tried with this approach: https://docs.microsoft.com/en-us/windows/wsl/install-on-server but it still requires input... Is there a way to setup WSL without user action?
The 4th step of installation on page that I linked is Create a UNIX user - this is a prompt that I can't skip, I would like to be able to provide this user (eventually keep default).
@Owdaan That user creating command adduser was written in the launcher e.g. ubuntu.exe. YOu may close the command prompt window after installing but the default user will be root. To remove that adduser you have to manually write a small binary.
voskrese I was using lxrun, but it is deprecated. Biswapriyo Nath (@Biswa96) Ok this may work, but still it would be nice to have that without extra custom launcher...
Distributions that are up-to-date with the distribution launcher sample have an option for non-interactive install. I know the Ubuntu 18.04 app supports this: ubuntu1804.exe install --root
Ben Hillis (@benhillis) This looks exactly what I need - is there an public link to new version of Ubuntu (1804) like it was for 1604? I can't find any and I'm not sure if i will get access to businessstore...
Isn't good enough for my use case. I want an unattended install that is the same as installing from the store, but where I supply a default account and password. I'm trying to set up a dev environment, and I don't want my devs to have to worry about running su all the time. With install --root: wsl drops you to root, which is a very different environment when you're trying to build and test software, but without it the install is not unattended.
If you are using WSL there's a followup step we recommend after running the setup script. When the script finishes you will only have a root user with a blank password. You should manually create a non-root user via $ sudo adduser [USERNAME] sudo with a non-blank password. Use this user going forward. For more info on WSL please refer to the documentation.
without really explaining how to "use this user going forward".
Using Vos (@MVoz)'s very helpful deep knowledge, I was able to make an almost-scripted install by:
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu.appx -UseBasicParsing
Add-AppxPackage -Path ~/Ubuntu.appx
RefreshEnv
Ubuntu1804 install --root
Ubuntu1804 run apt update
Ubuntu1804 run apt upgrade -y
Ubuntu1804 run adduser -m user
Ubuntu1804 run 'echo user:password | chpasswd'
Ubuntu1804 run 'chsh -s /bin/bash user'
reg.exe query HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss\ # to get the GUID of the container
reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss\{1422a095-2e43-4bf8-8108-d209cabe2a07}' /v DefaultUid /t REG_DWORD /d 1000 /f
It's not totally scripted, because the "get the GUID" step is hard. I'm not familiar enough (yet!) with Powershell to work out how to parse that out (oh, I guess there's a whole powershell regedit API isn't there?).
Um, anyway I guess I've answered my own question: you can do an unattended install if you just need linux with a root user, but you can't really do it if you want a regular user account, at least not yet.
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu.appx -UseBasicParsing
Add-AppxPackage -Path ~/Ubuntu.appx
RefreshEnv
$distro = "ubuntu1804" # unfortunately, there's no obvious way to get this value out of the previous command
$username = "ubuntu"
$password = "ubuntu"
& $distro install --root
# create user account
& $distro run useradd -m "$username"
& $distro run sh -c "echo "${username}:${password}" | chpasswd" # wrapped in sh -c to get the pipe to work
& $distro run chsh -s /bin/bash "$username"
& $distro run usermod -aG adm,cdrom,sudo,dip,plugdev "$username"
& $distro config --default-user "$username"
This makes doing initial system updates trickier though, because DistroLauncher doesn't come with -u; maybe it's better to leave that up to the user, but if you do want to include it in your initial provisioning then either:
Activity
Naadwo commentedon Jul 9, 2018
The 4th step of installation on page that I linked is Create a UNIX user - this is a prompt that I can't skip, I would like to be able to provide this user (eventually keep default).
MVoz commentedon Jul 9, 2018
lxrun.exe /?Biswa96 commentedon Jul 9, 2018
@Owdaan That user creating command
adduserwas written in the launcher e.g.ubuntu.exe. YOu may close the command prompt window after installing but the default user will be root. To remove thatadduseryou have to manually write a small binary.Naadwo commentedon Jul 9, 2018
voskrese I was using lxrun, but it is deprecated.
Biswapriyo Nath (@Biswa96) Ok this may work, but still it would be nice to have that without extra custom launcher...
MVoz commentedon Jul 9, 2018
@Owdaan
ubuntu.exe /?HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\ ... ID"DefaultUid"=dword:00000000- root -0"DefaultUid"=dword:000003e8- user1(Owdaan) -1000Naadwo commentedon Jul 9, 2018
voskrese I don't see how this may help.
It would actually help if --default-user switch would work, but it is ignored during installation.
Regarding edit - of course I can set that, but first I need to have WSL installed (and installer always prompts for username)
WSLUser commentedon Jul 9, 2018
You want microsoft/windows-dev-box-setup-scripts#32 and probably microsoft/windows-dev-box-setup-scripts#33 as well. Feel free to pitch in to help with those initiatives.
benhillis commentedon Jul 9, 2018
Distributions that are up-to-date with the distribution launcher sample have an option for non-interactive install. I know the Ubuntu 18.04 app supports this:
ubuntu1804.exe install --rootNaadwo commentedon Jul 10, 2018
Ben Hillis (@benhillis) This looks exactly what I need - is there an public link to new version of Ubuntu (1804) like it was for 1604? I can't find any and I'm not sure if i will get access to businessstore...
WSLUser commentedon Jul 10, 2018
@Owdaan They released this blog post yesterday to help address your question (other than business store) https://blogs.msdn.microsoft.com/commandline/2018/07/09/upgrading-ubuntu/
kousu commentedon Mar 20, 2021
Isn't good enough for my use case. I want an unattended install that is the same as installing from the store, but where I supply a default account and password. I'm trying to set up a dev environment, and I don't want my devs to have to worry about running
suall the time. Withinstall --root:wsldrops you to root, which is a very different environment when you're trying to build and test software, but without it the install is not unattended.Even the internal Microsoft boxstarter team punts on this: https://github.com/microsoft/windows-dev-box-setup-scripts/blob/d488050/README.md#how-to-run-the-scripts
without really explaining how to "use this user going forward".
Using Vos (@MVoz)'s very helpful deep knowledge, I was able to make an almost-scripted install by:
It's not totally scripted, because the "get the GUID" step is hard. I'm not familiar enough (yet!) with Powershell to work out how to parse that out (oh, I guess there's a whole powershell regedit API isn't there?).
Um, anyway I guess I've answered my own question: you can do an unattended install if you just need linux with a root user, but you can't really do it if you want a regular user account, at least not yet.
kicking it upstream: microsoft/WSL-DistroLauncher#90
kousu commentedon Mar 21, 2021
I got an unattended install with a non-root user account fully working thanks to powershell:
kousu commentedon Mar 21, 2021
Ahh I didn't read the docs enough, there's
$distro config --default-user. So this does it:kousu commentedon Mar 21, 2021
Or, this is probably even better:
This makes doing initial system updates trickier though, because DistroLauncher doesn't come with
-u; maybe it's better to leave that up to the user, but if you do want to include it in your initial provisioning then either:or: