I deployed a dev environment on wsl and I'm so excited about it. My only problem is the existence of an init file in the root path of the system.

root subdirectories

For one of my clients, I need to have an /init directory, this is a constraint that cannot be changed.

Needless to say, this renders my exciting and newly found wsl dev environment unusable for this project.

Is there a way to change the path of the wsl init file?

  • Does the directory have to be called exactly /init? Can you change the name of the directory at least? – Fanatique Nov 5 '19 at 9:41
  • @Fanatique Unfortunately no, as I mentioned it is a constraint that cannot be changed. – Aetos Nov 5 '19 at 9:41
  • 1
    FYI, WSL isn't the first system to reserve this path – the Linux kernel has used /init as the initramfs main executable's path since 2005. Creating a custom directory there was already a somewhat bad choice. – user1686 Nov 5 '19 at 9:42
  • @grawity I agree, but it was not my choice unfortunately and I have to work with it as is. My client is a big one (Very difficult to make change occur in their processes), and this directory is key to the project. – Aetos Nov 5 '19 at 9:43
  • @Biswapriyo, thank you for the warning. Will be glad to read your response :) – Aetos Nov 5 '19 at 10:34

tl;dr: The /init file can not be removed from a running WSL distribution. Because the subsystem is using that file and all processes in that running WSL distribution are forked from it.

  • So, what we can do? The file is locked by the subsystem while running that distribution. The workaround is to wait or to terminate that running distribution. Use wsl.exe --terminate Distro command where Distro is the name of running WSL distribution which you want to terminate. Go to the folder where the distribution is installed, follow this or this. Delete the init file.

  • Or, if you want to make a tarball of the whole WSL distribution then there is no need to terminate the running distribution. Create tarball and exclude init:

cd /
tar -cpf backup.tar --exclude=/backup.tar --exclude=/init --xattrs --one-file-system /

Check all the commandline options before running this command. Preserving file permission is must.

  • Where does the init file comes from? The init file is created by Microsoft WSL developers and not similar with systemd, sysVinit or other traditional GNU/Linux init systems. The actual file is System32\lxss\tools\init. When a distribution is launched the Linux Subsystem Manager Service (LXSS) copies that file in the rootfs folder (with CopyFileW() Win32 API). For WSL2 first the \tools folder is mounted with 9p protocol then used as above.

  • Even when I delete it, as soon as I start wsl again the init will show up once more. So how to liberate the name init in the root of the folder?? When I create a directory /init in the root folder via windows, and I try to start wsl, it just says Access denied – Aetos Nov 5 '19 at 17:11
  • As I mentioned before LxssManager service copies it everytime after WSL distribution is launched. So you can't remove it if the distro is running. – Biswapriyo Nov 5 '19 at 17:20
  • Then I'm not sure what you suggest I do, If I can't remove it while the distro is running. Then I can't remove it at all? I must be misunderstanding something – Aetos Nov 5 '19 at 17:21
  • So what is the purpose of removing the init file? or "tarballing" the whole wsl distro? – Aetos Nov 5 '19 at 17:25
  • @Aetos The answer doesn't suggest that init can be removed entirely. It requires for WSL and that's how it works. As grawity said, the directory name isn't a good choice. – Biswapriyo Nov 5 '19 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.