Comments (16)
I've just tried to apply the workaround for the first time, already with your suggestions applied. I got WSL2 + Ubuntu 20.04. Far from being a Linux admin or anything.
The trick for me is that whenever I'd launch wsl after changing the default user, I'd only get root user with regular bash in my terminal. systemctl would not work either.
After checking the code a few times I figured that wsl could be somehow finding the user correctly - but when effectively launching with that user it would then grab the first in the list with that uid. In that case, the actual root
user.
Out of that thought I went vipw
and vipw -s
again and got the rootwsl
user before of root
in the list, thus making it the first entry in the list.
It kinda worked. After shutting wsl down and launching ubuntu again, I get the message: Can't lock the lock file "/root/.systemd.lock". Is another instance running?
, but I'm then logged in with my user.
systemctl is-active dbus
now brings me active
, also.
Notice that I haven't tried up anything further than that, so I don't know for a fact if anything weird would come out of this.
from wsl2-hacks.
Based on the comments here - I modified the instructions - hopefully helpful for everyone
from wsl2-hacks.
@atiensivu Looks like the closing fi
is missing for if [[ -z ${SYSTEMD_PID} ]]; then
(it should be right before the line # enter systemd namespace
).
Are you going to submit a PR back to this repo?
from wsl2-hacks.
@esatapedico I was getting the same error. It happens when daemonize
tries to grab the lock and systemd
is already running. The script already checks if it is running by looking for its process ID, so we can just use that to skip trying to run it again:
if [[ -z ${SYSTEMD_PID} ]]; then
# start systemd
/usr/bin/daemonize -l "${HOME}/.systemd.lock" /usr/bin/unshare -fp --mount-proc /lib/systemd/systemd --system-unit=basic.target
# wait for systemd to start
retries=50
while [[ -z ${SYSTEMD_PID} && $retries -ge 0 ]]; do
(( retries-- ))
sleep .1
SYSTEMD_PID=$(pgrep -xo systemd)
done
if [[ $retries -lt 0 ]]; then
>&2 echo "Systemd timed out; aborting."
exit 1
fi
fi
from wsl2-hacks.
One question I'm hoping someone can answer; on step 3 it mentions to use both vipw
AND vipw -s
. It shows exactly what to paste into the passwd file, but not the shadow file.
for the shadow file do I just copy the root line, and paste it below that, changing "root" to "rootwsl"? like this:
- Root line:
root:*:12345:0:99999:7:::
- Pasted Line:
rootwsl:*:12345:0:99999:7:::
from wsl2-hacks.
HALP!1
I just can't seem to get this working, can anyone please spot the problem for me?
My /usr/local/bin/wsl2hack
#!/bin/bash
# source: https://github.com/atiensivu/wsl2-hacks/blob/e20bbcab6a436147d0ba84cdb237fc7a79e23b00/README.md
# your WSL2 username
UNAME="kacey"
UUID=$(id -u "${UNAME}")
UGID=$(id -g "${UNAME}")
UHOME=$(getent passwd "${UNAME}" | cut -d: -f6)
USHELL=$(getent passwd "${UNAME}" | cut -d: -f7)
if [[ -p /dev/stdin || "${BASH_ARGC}" > 0 && "${BASH_ARGV[1]}" != "-c" ]]; then
USHELL=/bin/bash
fi
if [[ "${PWD}" = "/root" ]]; then
cd "${UHOME}"
>&2 echo "cd'ing to ""${UHOME}""."
fi
# get pid of systemd
SYSTEMD_PID=$(pgrep -xo systemd)
# if we're already in the systemd environment
if [[ "${SYSTEMD_PID}" -eq "1" ]]; then
exec "${USHELL}" "$@"
>&2 echo "Already in systemd environment."
fi
if [[ -z "${SYSTEMD_PID}" ]]; then
# start systemd
/usr/bin/daemonize -l "${HOME}/.systemd.lock" /usr/bin/unshare -fp --mount-proc /lib/systemd/systemd --system-unit=basic.target
# wait for systemd to start
retries=50
while [[ -z "${SYSTEMD_PID}" && $retries -ge 0 ]]; do
(( retries-- ))
sleep .1
SYSTEMD_PID=$(pgrep -xo systemd)
done
if [[ $retries -lt 0 ]]; then
>&2 echo "Systemd timed out; aborting."
exit 1
fi
fi
# enter systemd namespace
>&2 echo "Attempting to enter systemd namespace."
exec /usr/bin/nsenter -t "${SYSTEMD_PID}" -m -p --wd="${PWD}" /sbin/runuser -s "${USHELL}" "${UNAME}" -- "${@}"
Now when I try to set the default user to root, I get this:
If I ty to open a new Ubuntu tab in Windows Terminal, it shows this (so it at least seems like it's reading the new wsl2hack file):
Can anyone help me out? I'm pretty much a beginner at Linux so this may be something easy that I just don't know how to handle.
from wsl2-hacks.
In 20.04, /usr
is just a link to /usr/bin
, so putting fake bash in there replaces the real bash. Tripped me up for a minute!
from wsl2-hacks.
did you try running the command with elevated powershell prompt (right clicking on the powershell icon ?
from wsl2-hacks.
UNAME="kacey"
UUID=$(id -u "${UNAME}")
UGID=$(id -g "${UNAME}")
I could be missing something here, but didnt you set the user to " kacey " ?
should it be --default-user kacey ?
from wsl2-hacks.
Hi @wanfuse123
UNAME="kacey"
UUID=$(id -u "${UNAME}")
UGID=$(id -g "${UNAME}")I could be missing something here, but didnt you set the user to " kacey " ?
should it be --default-user kacey ?
I am a bit confused about that too. I'm following these instructions:
https://github.com/shayne/wsl2-hacks/blob/50d379fbc87f4ed9211c7682339cc75eadf1112e/README.md
and it says at # 2:
Add the following, be sure to replace with your WSL2 Linux username
# your WSL2 username
UNAME="<YOURUSER>"
My normal Ubuntu username is kacey.
But further down at # 4 it says (btw, I'm using the direct ubuntu version from the store, so my ubuntu.exe has no version # in it):
In a PowerShell terminal run:
ubuntu2004.exe config --default-user root
Am I doing it wrong?
from wsl2-hacks.
from wsl2-hacks.
Myself i found additional directions ( sorry don't remember where from) for booting ubuntu under wsl2 from non root user And just combined them.
Its possible it was directions from another fork of that project.
Search google for : booting ubuntu under wsl2 from non root user
Thanks for helping @wanfuse123 :)
Being a almost total newbie with Linux, can you help me understand how doing a:
ubuntu.exe config --default-user root
as a non-root user would be better (or work at all) over doing it as a root user? I'm a bit confused with that.
The above commands I am running as the "true admin" user account in Windows (the hidden Administrator account); if I do this command from my regular windows user account that has Admin privileges, I get this:
Also, is this what you meant? (and putting a non-root user for the user name? currently I use the user name 'root' just to be able to get back into my Ubuntu after I made all these changes).
wsl.exe --user <user name>
Also i dont think it should still be trying systemd if you have installed daemonize instead
Note proper changes to /etc/passwd and the corresponding file bash script file it points to.
AFAIK I copied the paths and script code verbatim. The only confusion I really have there is the shadow file (vipw -s
) because the tutorial doesn't directly address that.
As i recall daemonize was one of a few of the packages needing to be installed and systemd was bot one of them.
Again, I'm just a newbie but I thought systemd was a default part of Ubuntu and didn't have to be installed via a package? (definitely could be wrong here). I'm not sure why the script tests for systemd; that's beyond my Linux knowledge for sure, lol!
from wsl2-hacks.
It seems like I'm "halfway" there at least. When I do:
PS C:\Users\Administrator> bash.exe -c "whoami"
It says:
rootwsl
It just seems that I can't switch it to using the default account "root", like the tutorial shows.
Also, I used your tutorial @atiensivu , perhaps you can help? I'd also love some input from the others in this thread, as I have a feeling they know WAY more about this than I do, and probably already have thiers up and running. @scotte @esatapedico @JohnTasto
I'd really genuinely appreciate the help so I can move on to the things I'm stuck holding off on until I can get this working. :)
from wsl2-hacks.
Well, I've come to the conclusion that this just doesn't work. I give up.
Anyone else who may come across this, I'd suggest not wasting your time on it.
from wsl2-hacks.
@YouveGotMeowxy, I also struggled, but I managed to get this working for Ubuntu 20.04. I used the instructions on https://github.com/atiensivu/wsl2-hacks. The only part that was missing was the shadow file edit (which you highlighted above), and a closing fi
statement clause in the script. See below:
if [[ -z ${SYSTEMD_PID} ]]; then
# start systemd
/usr/bin/daemonize -l "${HOME}/.systemd.lock" /usr/bin/unshare -fp --mount-proc /lib/systemd/systemd --system-unit=basic.target
# wait for systemd to start
retries=50
while [[ -z ${SYSTEMD_PID} && $retries -ge 0 ]]; do
(( retries-- ))
sleep .1
SYSTEMD_PID=$(pgrep -xo systemd)
done
if [[ $retries -lt 0 ]]; then
>&2 echo "Systemd timed out; aborting."
exit 1
fi
fi
@atiensivu, please update your README.md
file with the missing fi
, and the shadow file edit - thank you. :)
from wsl2-hacks.
Following these instructions, when I start WSL, I'm root. Even though the default-user is rootwsl. The script successfully logs me in as myself if I run it manually, but it doesn't run on login (because it's set for rootwsl and I'm showing up as root?). What am I doing wrong?
passwd:
root:x:0:0:root:/root:/bin/bash
rootwsl:x:0:0:root:/root:/usr/local/bin/wsl2hack
I've also tried rootwsl:x:0:0:rootwsl:/root:/usr/local/bin/wsl2hack
as suggested here, but it's the same. I'm root when I log in, not rootwsl, and not myself.
My $PATH
also seems to disappear if I run the script manually. So I'll be logged in as myself, but a lot of commands (like sysctl
) will stop working because they're no longer on the path.
from wsl2-hacks.
Related Issues (20)
- Last line gives "Invalid argument" on Pengwin
- Systemd does not start despite the hack has been carefully applied as described in the instruction HOT 1
- failed to install wsl2host: The specified domain either does not exist or could not be contacted. HOT 1
- Too many levels of symbolic links when running ls -l /proc/sys/fs/binfmt_misc
- WSL2 and IPv6
- Create separate downloable files for `systemd-bash` and other utilities
- Broken with WSL + Ubuntu 20.10 HOT 1
- Windows Server 2022
- System has not been booted with systemd as init system (PID 1). Can't operate. HOT 1
- Put Windows IP in the hosts
- In Windows 11, init with an alternative
- fake-bash - ping no response
- Fork to wsl2-hacks-win11+ubuntu_22.04?
- Systemctl not active HOT 4
- Anyone tried this on Debian WSL Distro?
- How to run xfe and similar GUI apps under wsl2hack HOT 4
- the root user work around is not working
- Please help. Followed instructions but corrupted my Ubuntu 20.04 and can't get back in HOT 4
- Update instructions for Ubuntu 20.04 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wsl2-hacks.