microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.54k stars 823 forks source link

Linux home folder to be the same as windows home folder. #5090

Open dyanakiev opened 4 years ago

dyanakiev commented 4 years ago

Is your feature request related to a problem? Please describe. I need to manage .ssh keys both on windows and linux, this will help that, and other stuff.

Describe the solution you'd like Allow using windows home folder as linux home folder.

ad-on-is commented 4 years ago

You can set mnt/c/Users/xxx as your home-folder in /etc/passwd.

dseynhae commented 4 years ago

The solution indicated by @ad-on-is (clever name!) is what I have done:

  1. Before changing the /etc/passwd file, copy ALL the files from your initial home /home/<user_name> (especially the startup files like.bashrc, and the administration directories like .ssh) to the future new home /mnt/c/Users/<user_name>.
  2. Edit the /etc/passwd file (you will need administration/sudo privileges);
  3. Locate the line that begins with your . That same line should have 1000:1000 as your UID (User ID) and GID (Group ID): that is what WSL assigns as the default account when you first install the distro.
  4. The last field in that line is your home directory (should be :/home/<user_name>). Change that to the mounted directory /mnt/c/Users/<user_name>.
  5. Reboot WSL; This is probably easiest to do in a CMD administration window:
    sc stop LxssManager
    sc start LxssManager

At this point, your WSL window should come up exactly as before, but with the new directory as the home directory.

NOTES:

dseynhae commented 4 years ago

One more remark: if you want to KEEP your home in /home/<username>, but make it CORRESPOND to your /mnt/c/Users/<user_name>, you could bind it in your /etc/fstab... Let me know if that needs to be explained in more detail.

Come to think of it, if this feature does get approved and implemented, that's probably how it should be done:

  1. When first starting the distro, create the /home/<user_name> directory.
  2. Bind /mnt/c/Users/<user_name> to it in /etc/fstab.
  3. Mount everything in the /etc/fstab.
  4. Populate the home directory with the template startup files...
ad-on-is commented 4 years ago

Since there are still I/O performance issues with /mnt, I personally wouldn't want this to be the default setup when installing a distro.

@beltaurus Thx, I carry that nickname since the early 2000s, being that nerdy friend who's always ON-line.

dyanakiev commented 4 years ago

Currently im not using WSL 1 or 2, im waiting for the new stable windows update with WSL 2 to be released and then i will play with that. In the past i used my windows home folder with the /etc/passwd path change method, there where some permissions issues that i solved by modifying the wsl conf. Mainly i stopped using WSL because of some performance issues, but i will give it a try again with WSL2.

ad-on-is commented 4 years ago

As I mentioned, performance issues are due to I/O speeds on /mnt, which are not better in WSL2, some say it's even worse compared to WSL1.

But when working with WSL2, it's recommended to store your work-files inside /home/user, where performance is nearly bare-metal.

trajano commented 4 years ago

I would like it to be configurable to make it the default to save the hassle of modifying the /etc/passwd file. It would also make it a more seamless experience for most people who are dabbling on it.

isimmons commented 2 years ago

So, not complaining because I knew I'd screw something up here. I did the above mentioned solution and broke docker desktop. I think it was because I copied all (I mean ALL) files and folders over blindly. When I installed docker, it created a .docker folder in my windows home dir and in the wsl home dir. Apparently they have different contents or the permissions to the directory might be a problem. But when I copied, it overwrote the existing one. To fix it I did a full purge and reset on docker, renamed the .docker folder, restarted windows and then all was good. Docker re-created the .docker folder and I opened a terminal (wsl working on new home directory) and recreated all my images and deployments.

All this just so I could have

isimmons33@xpsdt:~/code/node/udemy_steven_grider/microservice_course/blog/infra/k8s$

instead of

isimmons33@xpsdt:/mnt/c/Users/isimm/code/node/udemy_steven_grider/microservice_course/blog/infra/k8s$

It helps keep the long path from wrapping in terminal inside vscode

I should probably move work like this into /home/user anyway and then use \wsl$ if I need to access the files in explorer