2

As a previous StackOverflow question alluded to, is it possible to use any normal recovery tools (live booting from usb, grub command line, etc.) on a WSL program and, if so, how?

For instance, if one accidentally modified sudo permissions and could no longer use sudo without getting the “/etc/sudoers is world writable” error. In this case, how would one revert the /etc/sudoers permissions, since this chmod command itself needs sudo and so normally you would need to do a live boot to change file permissions?

Update: For my own “proof of concept” purposes I initially tried to mount my Windows drive (with WSL) from a completely separate Ubuntu computer to see if I could change the sudoers file permissions from there.

Although it seemed as if I was able to change the permissions from Ubuntu, once I got back into Windows and WSL, the sudoers file showed as corrupted (garbage ls -lah data). I used the information provided by @user1686 in comments and @NotTheDr01ds in an answer to access WSL as root and then create a new sudoers file with correct permissions.

0

1 Answer 1

6

Given your "for instance", WSL easily allows you to start the default instance as root (without a password) with wsl -u root from PowerShell or CMD or, if it's not the default instance, wsl -d <DistroName> -u root. You could then run visudo without requiring a sudo password.

WSL also allows "backups" of the entire filesystem using wsl --export <DistroName> <filename.tar>. This could be likely be automated to create a backup schedule using a script in Windows Task Manager. Recovery would then be a matter of restoring to the latest using wsl --import (see wsl --help for more info). Note that imported instances do not store the default username, so you would also need to create an /etc/wsl.conf with a user section.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .