WSL home directory behaviour unexpected #10033

Closed
opened 2026-01-31 02:10:49 +00:00 by claunia · 17 comments
Owner

Originally created by @pcolmer on GitHub (Aug 6, 2020).

Environment

Windows build number: 10.0.19041.0
Windows Terminal version (if applicable): 1.1.2021.0
Ubuntu 20.04.1 LTS

Steps to reproduce

  1. Install Ubuntu 20.04 as WSL.
  2. Start the default Ubuntu terminal.

Expected behavior

I would expect the terminal to start in the home directory of the user.

Actual behavior

The terminal starts at "/mnt/c/Users/phili", which is the Windows home directory.

Other notes

If you add a duplicate terminal profile, change the guid and comment out the source, it works as expected.

            {
                "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl",
                "commandline": "wsl.exe ~"
            },
            {
                "guid": "{daaee0d5-f525-4b10-98d1-d0ed1ede9f72}",
                "hidden": false,
                "name": "Ubuntu-no-source",
                // "source": "Windows.Terminal.Wsl",
                "commandline": "wsl.exe ~"
            },

In other words, the first profile above is the default one provided by Terminal. The second profile is my "hacked" one. The first one dumps me in my Windows home directory. The second one puts me in my Linux home directory.

In #6022, it was suggested that the behaviour changed depending on what had already happened, e.g. opening order or if WSL was already running. I took a video to show that this didn't seem to be the case for me.

Originally created by @pcolmer on GitHub (Aug 6, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: 10.0.19041.0 Windows Terminal version (if applicable): 1.1.2021.0 Ubuntu 20.04.1 LTS ``` # Steps to reproduce 1. Install Ubuntu 20.04 as WSL. 2. Start the default Ubuntu terminal. # Expected behavior I would expect the terminal to start in the home directory of the user. # Actual behavior The terminal starts at "/mnt/c/Users/phili", which is the **Windows** home directory. # Other notes If you add a duplicate terminal profile, change the guid and comment out the source, it works as expected. ``` { "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "commandline": "wsl.exe ~" }, { "guid": "{daaee0d5-f525-4b10-98d1-d0ed1ede9f72}", "hidden": false, "name": "Ubuntu-no-source", // "source": "Windows.Terminal.Wsl", "commandline": "wsl.exe ~" }, ``` In other words, the first profile above is the default one provided by Terminal. The second profile is my "hacked" one. The first one dumps me in my Windows home directory. The second one puts me in my Linux home directory. In #6022, it was suggested that the behaviour changed depending on what had already happened, e.g. opening order or if WSL was already running. I took a video to show that this didn't seem to be the case for me. ![](https://user-images.githubusercontent.com/1979931/84661173-dd47da80-af11-11ea-8925-c34aa8fb0ba4.gif)
Author
Owner

@zadjii-msft commented on GitHub (Aug 7, 2020):

Okay this is a spitball, but what happens if you add "startingDirectory": null to those profiles?

@zadjii-msft commented on GitHub (Aug 7, 2020): Okay this is a spitball, but what happens if you add `"startingDirectory": null` to those profiles?
Author
Owner

@jstorrs commented on GitHub (Aug 7, 2020):

My default profile does not have a "commandline" entry in the Ubuntu profile. It only has the "source" entry.

  {
    "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
    "hidden": false,
    "name": "Ubuntu",
    "source": "Windows.Terminal.Wsl"
  },

If I add:

  • "startingDirectory": null then bash opens in /mnt/c/WINDOWS/System32.
  • "startingDirectory": "C:\\" then bash opens in /mnt/c.
  • "startingDirectory": "~" then bash opens in /mnt/c/Users/jstor (windows home)
  • "startingDirectory": "/home/jstorrs" then bash opens in /mnt/c/Users/jstor (windows home)

For comparison:

  • wsl.exe will open in /mnt/c/Users/jstor (windows home)
  • wsl.exe ~ will open in /home/jstorrs (ubuntu home)
  • wsl.exe /home/jstorrs gives an error (it tries to execute /home/jstorrs)

So to me it looks like Windows.Terminal.Wsl is listening to "startingDirectory", but I don't know how to point it at a Ubuntu side path. So it mostly seems that the wsl.exe command has some extra logic to deal with ~ as a parameter.

When I googled this problem earlier the advice was to just put cd ~ to the end of .bashrc

@jstorrs commented on GitHub (Aug 7, 2020): My default profile does not have a `"commandline"` entry in the Ubuntu profile. It only has the "source" entry. { "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl" }, If I add: - `"startingDirectory": null` then bash opens in `/mnt/c/WINDOWS/System32`. - `"startingDirectory": "C:\\"` then bash opens in `/mnt/c`. - `"startingDirectory": "~"` then bash opens in `/mnt/c/Users/jstor` (windows home) - `"startingDirectory": "/home/jstorrs"` then bash opens in `/mnt/c/Users/jstor` (windows home) For comparison: - `wsl.exe` will open in `/mnt/c/Users/jstor` (windows home) - `wsl.exe ~` will open in `/home/jstorrs` (ubuntu home) - `wsl.exe /home/jstorrs` gives an error (it tries to execute `/home/jstorrs`) So to me it looks like Windows.Terminal.Wsl is listening to "startingDirectory", but I don't know how to point it at a Ubuntu side path. So it mostly seems that the wsl.exe command has some extra logic to deal with `~` as a parameter. When I googled this problem earlier the advice was to just put `cd ~` to the end of .bashrc
Author
Owner

@jstorrs commented on GitHub (Aug 7, 2020):

I was able to set the startingDirectory to my Ubuntu home following comments in the discussion here https://github.com/microsoft/terminal/issues/592

"startingDirectory": "//wsl$/Ubuntu/home/jstorrs"

@jstorrs commented on GitHub (Aug 7, 2020): I was able to set the startingDirectory to my Ubuntu home following comments in the discussion here https://github.com/microsoft/terminal/issues/592 `"startingDirectory": "//wsl$/Ubuntu/home/jstorrs"`
Author
Owner

@pcolmer commented on GitHub (Aug 10, 2020):

Okay this is a spitball, but what happens if you add "startingDirectory": null to those profiles?

I get the same result as @jstorrs, namely that it opens bash pointing at Windows/System32.

I am willing to concede that the default WSL Terminal profile behaves exactly the same way as just running wsl without any parameters but I would suggest that this is not the most desirable behaviour.

With WSL2, the strong recommendation is to stay within the Linux filing system because it is faster than the Windows filing system. The simplest way to achieve that is to specify "~" as the starting directory but using startingDirectory to do so doesn't work, even in my second profile where I've commented out "source": "Windows.Terminal.Wsl".

There does need to be a cleaner way in Terminal of telling WSL where to start. While specifying a wsl$ path is a solution, it isn't ideal - it isn't very intuitive to novice users.

@pcolmer commented on GitHub (Aug 10, 2020): > Okay this is a spitball, but what happens if you add "startingDirectory": null to those profiles? I get the same result as @jstorrs, namely that it opens bash pointing at Windows/System32. I am willing to concede that the default WSL Terminal profile behaves exactly the same way as just running `wsl` without any parameters but I would suggest that this is not the most desirable behaviour. With WSL2, the strong recommendation is to stay within the Linux filing system because it is faster than the Windows filing system. The simplest way to achieve that is to specify "~" as the starting directory but using `startingDirectory` to do so doesn't work, even in my second profile where I've commented out `"source": "Windows.Terminal.Wsl"`. There does need to be a cleaner way in Terminal of telling WSL where to start. While specifying a `wsl$` path is **a** solution, it isn't ideal - it isn't very intuitive to novice users.
Author
Owner

@Chris-Teng commented on GitHub (Aug 11, 2020):

I was able to set the startingDirectory to my Ubuntu home following comments in the discussion here #592

"startingDirectory": "//wsl$/Ubuntu/home/jstorrs"

That works!Thank u😉
But there maybe really needs a more human-friendly way to set the default wsl dir.

@Chris-Teng commented on GitHub (Aug 11, 2020): > I was able to set the startingDirectory to my Ubuntu home following comments in the discussion here #592 > > `"startingDirectory": "//wsl$/Ubuntu/home/jstorrs"` That works!Thank u😉 But there maybe really needs a more human-friendly way to set the default wsl dir.
Author
Owner

@brsvh commented on GitHub (Aug 14, 2020):

I get the same problem.

Environment
winver: OS Build 19041.388
windows terminal version: 1.1.2233.0
wsl distro: Ubuntu(20.04) from Microsoft Store.
wsl version: 2

Expected

open wsl tab with user home directory that in wsl, specifically is /home/brs.

Reproduce

"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu/home/brs",

will open with /mnt/c/Users/brs.

"source": "Windows.Terminal.Wsl",
"commandline": "wsl.exe ~ -d Ubuntu",
"startingDirectory": "//wsl$/Ubuntu/home/brs",

will open with /mnt/c/Users/brs.

"commandline": "wsl.exe ~ -d Ubuntu",
"startingDirectory": "//wsl$/Ubuntu/home/brs",

will open with /mnt/c/Users/brs.

"commandline": "wsl.exe ~ -d Ubuntu",

will open with /mnt/c/Users/brs.

"source": "Windows.Terminal.Wsl",
"commandline": "wsl.exe ~ -d Ubuntu",

will open with /mnt/c/Users/brs.

Additional info

Run wsl.exe ~ -d Ubuntu in powershell is works fine.

@brsvh commented on GitHub (Aug 14, 2020): I get the same problem. **Environment** winver: OS Build 19041.388 windows terminal version: 1.1.2233.0 wsl distro: Ubuntu(20.04) from Microsoft Store. wsl version: 2 **Expected** open wsl tab with user home directory that in wsl, specifically is `/home/brs`. **Reproduce** ```json "source": "Windows.Terminal.Wsl", "startingDirectory": "//wsl$/Ubuntu/home/brs", ``` will open with `/mnt/c/Users/brs`. ```json "source": "Windows.Terminal.Wsl", "commandline": "wsl.exe ~ -d Ubuntu", "startingDirectory": "//wsl$/Ubuntu/home/brs", ``` will open with `/mnt/c/Users/brs`. ```json "commandline": "wsl.exe ~ -d Ubuntu", "startingDirectory": "//wsl$/Ubuntu/home/brs", ``` will open with `/mnt/c/Users/brs`. ```json "commandline": "wsl.exe ~ -d Ubuntu", ``` will open with `/mnt/c/Users/brs`. ```json "source": "Windows.Terminal.Wsl", "commandline": "wsl.exe ~ -d Ubuntu", ``` will open with `/mnt/c/Users/brs`. **Additional info** Run `wsl.exe ~ -d Ubuntu` in powershell is works fine.
Author
Owner

@brsvh commented on GitHub (Aug 14, 2020):

hmmm... It seems like I have declared two wsl profiles in my settings.json.

like this:

{
    "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
    "hidden": false,
    "name": "Ubuntu",
    "source": "Windows.Terminal.Wsl",
},
{
    "guid": "{1cd32e5c-c707-4699-b105-f99539dc0776}",
    "hidden": false,
    "name": "Ubuntu",
    "source": "Windows.Terminal.Wsl",
     "startingDirectory": "//wsl$/Ubuntu/home/brs",
}

I commented out one of them, and it worked.

Plz ignore my previous comment.

@brsvh commented on GitHub (Aug 14, 2020): hmmm... It seems like I have declared two wsl profiles in my settings.json. like this: ```json { "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", }, { "guid": "{1cd32e5c-c707-4699-b105-f99539dc0776}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "startingDirectory": "//wsl$/Ubuntu/home/brs", } ``` I commented out one of them, and it worked. Plz ignore my previous comment.
Author
Owner

@zadjii-msft commented on GitHub (Aug 19, 2020):

I'm going to stick this on the 2.0 milestone to make sure we figure out a solution to this with the WSL team. I'm not sure why this is happening, but hopefully they'll be able to give us some insight.

/fyi @benhillis @craigloewen-msft

@zadjii-msft commented on GitHub (Aug 19, 2020): I'm going to stick this on the 2.0 milestone to make sure we figure out a solution to this with the WSL team. I'm not sure _why_ this is happening, but hopefully they'll be able to give us some insight. /fyi @benhillis @craigloewen-msft
Author
Owner

@benhillis commented on GitHub (Sep 8, 2020):

Seems like Windows.Terminal.Wsl is overwriting something?

@benhillis commented on GitHub (Sep 8, 2020): Seems like Windows.Terminal.Wsl is overwriting something?
Author
Owner

@dead-claudia commented on GitHub (Feb 23, 2021):

Possibly related: https://github.com/microsoft/terminal/issues/9252

@dead-claudia commented on GitHub (Feb 23, 2021): Possibly related: https://github.com/microsoft/terminal/issues/9252
Author
Owner

@ocitrev commented on GitHub (Apr 29, 2021):

I've been using the app execution aliases for my WSL distros in my WSL configs, and it works great.
When run without arguments, they launch the user's default shell in the user's home.
No need to set the startDirectory.

{
    "guid": "{31b0ca0b-67d0-479d-901d-31b29cf05a42}",
    "name": "Ubuntu",
    "source": "Windows.Terminal.Wsl",
    "commandline": "Ubuntu.exe"
},
{
    "guid": "{f752f8d9-f2aa-4761-9eff-bc857a48e281}",
    "name": "kali-linux",
    "source": "Windows.Terminal.Wsl",
    "commandline": "Kali.exe"
}
@ocitrev commented on GitHub (Apr 29, 2021): I've been using the app execution aliases for my WSL distros in my WSL configs, and it works great. When run without arguments, they launch the user's default shell in the user's home. No need to set the `startDirectory`. ```json { "guid": "{31b0ca0b-67d0-479d-901d-31b29cf05a42}", "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "commandline": "Ubuntu.exe" }, { "guid": "{f752f8d9-f2aa-4761-9eff-bc857a48e281}", "name": "kali-linux", "source": "Windows.Terminal.Wsl", "commandline": "Kali.exe" } ```
Author
Owner

@pcolmer commented on GitHub (Apr 30, 2021):

I've been using the app execution aliases for my WSL distros in my WSL configs, and it works great.

For anyone wanting to reference numbered Ubuntu builds, the names are like ubuntu2004.exe and ubuntu1804.exe.

This is a great tip, @ocitrev - thanks.

@pcolmer commented on GitHub (Apr 30, 2021): > I've been using the app execution aliases for my WSL distros in my WSL configs, and it works great. For anyone wanting to reference numbered Ubuntu builds, the names are like `ubuntu2004.exe` and `ubuntu1804.exe`. This is a great tip, @ocitrev - thanks.
Author
Owner

@zadjii-msft commented on GitHub (May 6, 2021):

This might be fixed, or at least mitigated by #9223

@zadjii-msft commented on GitHub (May 6, 2021): This might be fixed, or at least mitigated by #9223
Author
Owner

@plastikfan commented on GitHub (Sep 30, 2021):

So to me it looks like Windows.Terminal.Wsl is listening to "startingDirectory", but I don't know how to point it at a Ubuntu side path. So it mostly seems that the wsl.exe command has some extra logic to deal with ~ as a parameter.

When I googled this problem earlier the advice was to just put cd ~ to the end of .bashrc

Using that 'cd ~' in your shell's initialisation script is a bad idea. If you do so then if you open up vscode, then open an integrated terminal, it will also open in the home directory instead of the desired default behaviour of opening the workspace root directory. I tried to change this by configuring vscode (setting (for WSL remote): terminal.integrated.cwd to ${workspaceFolder}) but this does not work.

At last, I found something that works, in the windows terminals settings, set the starting directory to:

  • \wsl$<distro-name>\home<username>

eg:

\\wsl$\Ubuntu-20.04\home\username

As directory names in linux are case sensitive, make sure the username is cased properly, or else it won't work.

@plastikfan commented on GitHub (Sep 30, 2021): > So to me it looks like Windows.Terminal.Wsl is listening to "startingDirectory", but I don't know how to point it at a Ubuntu side path. So it mostly seems that the wsl.exe command has some extra logic to deal with `~` as a parameter. > > When I googled this problem earlier the advice was to just put `cd ~` to the end of .bashrc Using that 'cd ~' in your shell's initialisation script is a bad idea. If you do so then if you open up vscode, then open an integrated terminal, it will also open in the home directory instead of the desired default behaviour of opening the workspace root directory. I tried to change this by configuring vscode (setting (for __WSL remote__): terminal.integrated.cwd to ___${workspaceFolder}___) but this does not work. At last, I found something that works, in the windows terminals settings, set the starting directory to: - \\wsl$\<distro-name>\home\<username> eg: ``` \\wsl$\Ubuntu-20.04\home\username ``` As directory names in linux are case sensitive, make sure the username is cased properly, or else it won't work.
Author
Owner

@swahilli commented on GitHub (Dec 15, 2021):

This just reoccurred for me.

I was using
"commandline": "wsl.exe -d Ubuntu-20.04"
"startingDirectory": "//wsl$/Ubuntu-20.04/home/craig"

I had to change the command line to
"commandline": "wsl.exe ~ -d Ubuntu-20.04"

Thanks to jstorrs for the hint.

@swahilli commented on GitHub (Dec 15, 2021): This just reoccurred for me. I was using `"commandline": "wsl.exe -d Ubuntu-20.04"` `"startingDirectory": "//wsl$/Ubuntu-20.04/home/craig"` I had to change the command line to `"commandline": "wsl.exe ~ -d Ubuntu-20.04"` Thanks to jstorrs for the hint.
Author
Owner

@emrszon commented on GitHub (Jan 5, 2022):

"startingDirectory": "/home/jstorrs"

This work for me.

Thanks to @jstorrs for the hint.

@emrszon commented on GitHub (Jan 5, 2022): `"startingDirectory": "/home/jstorrs"` This work for me. Thanks to @jstorrs for the hint.
Author
Owner

@DHowett commented on GitHub (Feb 15, 2022):

The coming 1.12 release (and 1.13, if you are using Preview) is going to make this much more ergonomic. For profiles that launch wsl.exe, you will be able to use Linux paths in startingDirectory, and the default is ~ for all automatically generated WSL profiles. The fix was made in part in #9223 and in part in #12315 (fix in #12437; don't let the name mislead you :P)

@DHowett commented on GitHub (Feb 15, 2022): The coming 1.12 release (and 1.13, if you are using Preview) is going to make this much more ergonomic. For profiles that launch `wsl.exe`, you will be able to use Linux paths in `startingDirectory`, and the _default_ is `~` for all automatically generated WSL profiles. The fix was made in part in #9223 and in part in #12315 (fix in #12437; don't let the name mislead you :P)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#10033