Location of /root/ on Windows 10 Ubuntu
Asked Answered
C

4

5

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 ?

Chromium answered 18/4, 2016 at 23:50 Comment(1)
Nowadays, Windows supports multiple Linux distributions in the same machine. The root location vay depending on the distribution you are using. You can find them into the %LOCALAPPDATA%\Packages. For Ubuntu 18.04, it is %LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgscOverset
R
6

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.

Rhinencephalon answered 16/9, 2016 at 19:24 Comment(0)
O
3

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
Overset answered 26/5, 2018 at 16:10 Comment(0)
K
1

It's the other way round: bash is accessing the windows filesystem which you will find at /mnt/c. Your files are (should be) in your windows filesystem and you can edit them as normal.

If you simply dislike the terminal interface, try something like conemu (https://conemu.github.io/). It's a convenient and pretty interface for command shell, powershell or whatever shell you like.

Kite answered 19/4, 2016 at 0:13 Comment(0)
T
1

❞ [is there] 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 ?

I found that in Cmd I can do

subst u: "\\wsl.localhost\Ubuntu-20.04"

PowerShell directly understands UNC paths, so in PowerShell can just cd to that location. Not sure if that supports running a Windows editor. But drive u: should be OK.

Thalia answered 16/7 at 0:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.