How do I change the root location for Bash in Windows 10?
Solution 1:
Not yet!
In Win10 Fall Creators Update, we've added the ability to install one or more Linux distros (Ubuntu, openSUSE, SLES, Fedora & others coming soon). Alas, we were not yet able to wrap-up the work required to enable distros to be installed/moved to a non-system drive. We'll be looking into completing this work in a future release.
Solution 2:
Now it possible with https://github.com/DDoSolitary/LxRunOffline
choco install lxrunoffline
- No Internet access required when installing.
- Install any Linux distros to any location on your disk.
- Moving existing installations to other locations.
- Duplicating existing installations. (To create backups.)
- Register existing installation directories. (For portable usage.)
Solution 3:
It's now possible to specify where you'd like to install your distro in WSL as of Windows Version 1903. Specifically this is possible using the wsl --export
and wsl --import
commands.
I'll explain the steps using Ubuntu as a sample distro.
Step 1: Export your distro
We need to get a .tar file of the minimal Linux root file system (Basically just the userspace stuff, like what a docker container would contain, or the mini root file system on Alpine Linux's download page).
- Export Ubuntu to your current folder to the file ubuntu.tar
- Run in CMD or Powershell:
wsl --export Ubuntu ubuntu.tar
- Run in CMD or Powershell:
Step 2: Import your distro back
Now we can import our distro back, and specify its install location.
- Create the install location
- For example: Create 'ubuntuStorage' in D:\
- Import the distro:
- Run in CMD or Powershell
wsl --import Ubuntu-New D:\ubuntuStorage\ .\ubuntu.tar
- Run in CMD or Powershell
- Optional: Remove your old distro after you verify it works
- Run in CMD or Powershell
wsl --unregister Ubuntu
- Run in CMD or Powershell
Some important considerations
As of the time of writing this there are some additional considerations. The first is this distro is now installed without using the Microsoft Store, meaning that you will not be able to use the store app. Instead to run it please run wsl -d Ubuntu-New
to start it (or set it as your default distro and run wsl
). Additionally, as of right now you will be logged in as the root user without a way to change the default user. We are tracking that and are working on a fix, you can view updates on the progress here.