This post helped my get what I was looking for however I needed to run multiple commands (start xrdp, tweak eth0 mtu, update resolv.conf) and running wsl.exe
multiple times would instantiate multiple root logins causing some issues with file locking resolv.conf
possibly because WSL does some setup at each login, not positive.
I am using wsl2 Kernel version: 5.10.102.1 Windows 10 with Ubuntu 20.04.5 LTS. My needs were
- Start xrdp (so I can connect to a gui session)
- Set eth0 mtu to 1350 (WSL had trouble with connectivity while on VPN due to mtu)
- Update
resolv.conf
with upstream resolvers (kept getting updated by WSL regardless of generateResolvConf = false
in wsl.config
)
So to expand on the answer from @NotTheDr01ds here is what I did.
- Put all commands in a new shell script
.mystartup.sh
in home directory
- Call
.mystartup.sh
as root from .profile
Here is what I added to .profile
# startup stuff
# run startup script as root
wsl.exe -u root /home/user/.mystartup.sh
And here is .mystartup.sh
# startup stuff
# service xrdp start
service xrdp status || service xrdp start
# setup lower mtu for vpn links
ifconfig eth0 mtu 1350
echo "eth0 mtu updated!"
# remove link to /run/resolvconf/resolv.conf & create new
rm -f /etc/resolv.conf
touch /etc/resolv.conf
chmod u+rwx,g+rwx,o+rx /etc/resolv.conf
# setup nameservers
echo "# this resolv.conf created using user .profile script" >> /etc/resolv.conf
echo "# wsl auto-generate must be disabled in /etc/wsl.config" >> /etc/resolv.conf
echo "nameserver 10.0.0.50" >> /etc/resolv.conf
echo "nameserver 10.0.0.51" >> /etc/resolv.conf
echo "resolv.conf modified with custom dns resolvers!"
echo
systemctl --failed
?C:\WSL\Ubuntu\ubuntu1804.exe
with the argumentrun /path/to/linux/executable
.