WSL: Debian usrmerge fails
On Windows 18362.207, running Debian.
Upgrading to Debian 10 Buster is successful. However, a subsequent sudo apt-get install usrmerge fails, resulting in an installation that’s difficult to get to a recoverable state. It partially succeeds, but is unable to complete. It additionally complains that it must succeed before further updates and installations.
This basically requires a user to do a Debian reinstallation to recover from. Oops.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 31
The root cause is: WSL1 currently doesn’t support moving (renameing) directory while some file in that directory is being used. For example, if
/somedir/somefileis being used, thenmv /somedir /somedir2will result inPermission denied.The
sudoprogram uses dynamic libraries in/lib/x86_64-linux-gnu/security/. So if you are usingsudoto execute commands, you will never be able to move that directory. Thus the workaround is: do not usesudoin linux shell, usewsl -u rootin windows command prompt instead.Here are the steps to workaround this specific problem under WSL1:
wsl --shutdownto fully close all linux processes.wsl -u rootto get root access and do fixes in linux shell, you might need to run/usr/lib/usrmerge/convert-usrmergemultiple times.Here is a fun hack that worked for WSL1: The key is 9P FS works even when WSL is shut down. Lets suppose you already started. If not, the first step is to fail:
I ran into the above issue. However I did the following: from a root terminal
wsl.exe -u rootin a cmdsudo suwith your PWsu -with root PWnow in a cmd do
wsl --shutdown. In your favorite way from windows:\\wsl$\Debian\lib\\wsl$\Debian\libtmpto\\wsl$\Debian\lib(I used explorer… I use WSL for a reason, could care less about windows file manipulation command line)then read and weep:
edit: Fix delete instruction I mistyped, and add instruction from the top in case anybody tries from the top, and its
\\wsl$, not\\$wslThank you @pickard1 ! This worked for me.
Here are the exact steps I performed.
I edited my .wslconfig and added:
Then I performed a
wsl.exe --shutdownandwsl.exe -u root. Then I ranmount | grep '\/usr\/lib\/'to get a list of the mounts in use (there were 4). I then began runningumount /usr/lib/...for each of these. Some of them are dependent on each other so it might fail to unmount until you unmount one of the others. Once you get them all unmounted, then run/usr/lib/usrmerge/convert-usrmerge.If that completed successfully, then remove the entry you added in the .wslconfig and do another wsl.exe --shutdown.
I did it. 😃 After I set the mountFsTab=false option in [automount] in wsl.conf, I was able to remove the mountpoints for /lib/modules. Then the upgrade went through!!
Apparently as simple as:
I’m not sure it actually changed, since
wsl -l -vstill listed my “Ubuntu” installation as version 1 … but after I did this running/usr/lib/usrmerge/convert-usrmergeworked (I wonder if all it needed was a reboot).In any case I moved it back (??) by doing:
And then I bumped into issue #4640, which is then solved by removing a
sudo rm -f /etc/apt/apt.conf.d/20snapd.conf. Notice snapd package had already been removed because it also breaks the upgrade from 20.04 to 21.10 for some obscure reason.I was able to reproduce this. By accident, unfortunately. Running usrmerge left me with a broken Debian install in WSL that required a reinstall to recover from.
I tried it again on a fresh install from the Microsoft Store, which gave me Debian 10.9, and it failed the same way. I’m using WSL 1. Not sure if the permission issue is any different under WSL 2.
I’m hoping this is resolved by default when the Debian distro in the store is updated to Debian 11 and I can do a fresh install with merged-usr already applied by default.
In window explorer, just copy
\\wsl$\Debian\lib\x86_64-linux-gnu\securityto\\wsl$\Debian\usr\lib\x86_64-linux-gnu\security, then in wsl termianlsudo apt update && sudo apt upgrade -y, finally it comesFollowup: usrmerge does work without error when running Debian as WSL 2.
And migrating back to WSL 1 after running usrmerge while in WSL 2 does work as well.
So anyone needing to use WSL 1 and wanting to do a usrmerge, your workaround is to just switch your Debian to WSL 2 first, run usrmerge, and then switch back to WSL 1.
Thanks, and fixed. Yeah this saved me big time too, and I refused “convert to WSL2” as any reasonable solution, period.
You can pry my wicked win32 hacks inside WSL1 programs from my cold dead hands… WSL1 forever!! or rather at least until back to native linux if it sunsets.
For those who may come later:
Got the same error trying to update my Debian WSL1 install
Converting the WSL1 install to WSL2 made it so that convert-usrmerge could succeed.
Tried running convert-usrmerge (needs sudo) but it works!
Converted back to WSL1 and the rest of my updates are running fine!
I came here because of problems upgrading WSL2 version of Ubuntu 20 to 22. What happened was that
usrmergewas unable to mv/lib/modulesto/usr/lib/modulesbecause of the presence of the WSL2 kernel in/lib/modules.The solution was to temporarily switch back to WSL version 1. Then, run
dpkg --configure -ato finish the failed install. Finally switch back.WSL will place the kernel in the old place,
/lib/modulesand not/usr/lib/modulesbut at least usrmerge has finished and won’t complain.I was getting the following error when upgrading to bookworm while currently on WSL 2:
The problem here is WSL mounts the
modulesdirectory into/libwhen starting up debian.The way I fixed it was downgrading to WSL 1, following @boxfire workaround above (https://github.com/microsoft/WSL/issues/4279#issuecomment-1259981099), then upgrading back to WSL 2.
There’s probably a more sane way to do this where the
modulesdirectory can be configured to mount somewhere else.For anyone googling this, this is the actual solution: https://askubuntu.com/a/1486648/1733922
This saved me when doing the Debian 11 -> 12 update on my work machine where I don’t have admin privileges. I was not able to delete the
\\wsl$\Debian\libdirectory, but renaming it tolib.oldwas possible and sufficient. I could then delete the old directory afterwards from within WSL.It worked for me too, thank you very much @boxfire and @tjkirch. By the way the path is ‘wsl$’ ($ is suffix instead of prefix), i think? (I was not sure, I’m not good at Windows)
Thanks for these tips @boxfire! This saved my install. I use WSL2, so the other tips about switching to WSL2 didn’t apply to me, but yours worked fine. Just one tweak:
This should say to delete
lib, nottmp.Same problem here, when upgrading my WSL 1.0 from Ubuntu 20.04 to 21.10 the usrmerge+WSL1 broke my installation 😦 …
Any guidelines on how to upgrade to WSL2 to run
/usr/lib/usrmerge/convert-usrmergeand then convert back to WSL 1 ?