Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of /root/ on Windows 10 Ubuntu

I installed the bash on Ubuntu on Windows 10 - the insider preview edition. Windows terminals are however are sort of cumbersome to use if one is used to Ubuntu's terminal. I was wondering if there is a way to access the Ubuntu filesystem from Windows so that I can do the development in some other editor and run the code from Ubuntu-bash ?

like image 678
samar Avatar asked Apr 18 '16 23:04

samar


Video Answer


2 Answers

Any terminal program that can open a Windows command prompt should be able to run bash (bash.exe launches the Windows Linux Subsytem), so you don't have to be stuck with command.exe.

Conemu (mentioned by @anotherfred) or Cmder are some of the fan favorites. You can also use Powershell if you like that.

You can access your Windows files from WSL at /mnt/c (and /mnt/d if you have a d: drive, etc). That works relatively well if you want to do command line stuff and still access the files using your favorite Windows editor.

You can see your WSL file system from Windows at:

%LocalAppData%\lxss\rootfs

though I wouldn't mess with it from within Windows.

/root would be under

%LocalAppData%\lxss\rootfs\root

and

/home would be under

%LocalAppData%\lxss\rootfs\home

These two are mounted separately so that they are not deleted when you remove WSL.

like image 110
cgranier Avatar answered Sep 20 '22 00:09

cgranier


Windows 10 versions released since the end of 2017 (including the Fall Creators Update and Windows Insiders Builds 17063+) supports multiple linux distributions running on the same machine. In consequence, WSL must store the root filesystem for each distribution in a different location.

The root filesystem is not located anymore at

%LocalAppData%\lxss\rootfs

New location of the filesystem folders

Each linux distribution installed from the Windows Store stores the root filesystem in a different folder at

%LocalAppData%\Packages\<distro folder>\LocalState

The <distro folder> vary from one distribution to the other. For instance, the following are the <distro folder> in my test computer:

  • Ubuntu 16.04 : CanonicalGroupLimited.Ubuntu16.04onWindows_79rhkp1fndgsc
  • Ubuntu 18.04 : CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc
  • Debian : TheDebianProject.DebianGNULinux_76v4gfsz19hv4
  • Kali linux: KaliLinux.54290C8133FEE_ey8k8hqnwqnmg

If you wanna access the root or the home filesystems, you must use the appropriated folders. For instance, to go to the folders for the KaliLinux, you must go to:

%LocalAppData%\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\rootfs   # root
%LocalAppData%\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\home     # home

Obtaining the path using lxRunOffline

LxRunOffline is a tool to manage WSL linux distributions. It can be used to install or move a WSL distribution to any folder of your computer.

You can use lxRunOffline get-dir to obtain the path of the installation folder. The root is in the rootfs sub-folder.

C:\> lxrunoffline list
Ubuntu-18.04
ubuntu-copy

C:\> lxrunoffline get-dir -n Ubuntu-18.04
C:\Users\nnn\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState

C:\> lxrunoffline get-dir -n ubuntu-copy
d:\wsl\installed\ubuntu-copy

Obtaining the path Programmatically

If you are interested, you can obtain the path using a program. The information about the installed distributions and their configuration is stored in the Windows Registry.

You can check the information using the regedit and the following path:

HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss

There is all the configuration of the diverse distributions you have installed. For instance, You can use Powershell to obtain the information of the base path for the default distribution.

$WSLREGKEY="HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss"
$WSLDEFID=(Get-ItemProperty "$WSLREGKEY").DefaultDistribution
$DISTROPATH=(Get-ItemProperty "$WSLREGKEY\$WSLDEFID").BasePath
echo "the filesystems are located at $DISTROPATH"

To check the filesystems for all your installed distributions, you can use Powershell too.

(Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | ForEach-Object {Get-ItemProperty $_.PSPath}) | select DistributionName,BasePath
like image 24
Jaime Avatar answered Sep 20 '22 00:09

Jaime