How to access my D:\ drive from the Ubuntu command line on Windows 10 - windows-subsystem-for-linux

When I open the Ubuntu windows store app and the bash command line (if I am not wrong?) comes up it's working directory is /home/username . I want to run a script which on my Windows is located in D:\University... . Can I do this and if so how?
I have only tried cd D:\ but I get " -bash: cd: D:: No such file or directory". I don't have any experience so far with Linux so I don't know if Ubuntu on Windows can only run in its own location or it can access all the files on my PC.

you can use mnt to access your drives.
root#user-pc: cd /mnt/d/your_destination_directory;

Related

pocketbase: command not found

I am trying to set up a pocketbase on a Debian server.
on the server I created a dir called pb and scp over the pocketbase file which I downloaded from https://pocketbase.io/docs/
I downloaded all three linux packages pocketbase_0.10.2_linux_amd64.zip , pocketbase_0.10.2_linux_arm64.zip and pocketbase_0.10.2_linux_armv7.zip
I download the file, unzip it and then move the pocketbase file over to the server.
Note, Ive downloaded these onto a windows machine and then SCP pocketbase file over to my server.
When I run pocketbase serve I get the error command not found.
I can't find a good solution to this issue.
Execute it as instructed by pocketbase's documentation if you are within the same directory as the bin file:
./pocketbase serve
If you want to run it as pocketbase serve alone you will need to move the bin file under /usr/bin or ideally /usr/local/bin which should be under your system's $PATH variable.
https://pocketbase.io/docs/
Run ./pocketbase --help or ./pocketbase [command] --help for more assistance.

Why can't I access WSL directories from my windows terminal?

I have made a python script in WSL using VSCode. I want to call this script from another python script that is running in Windows.
My plan was to use os.system() to command line into wsl and start the script from it's directory, however when I go into windows terminal to try to start it manually, I can't access any of my directories.
The path I am attempting to access from terminal is \wsl.localhost\Ubuntu\home\ben\apps and root user can't access it either.
Windows terminal:
(base) PS C:\Users\benja> wsl
ben#DESKTOP:/mnt/c/Users/benja$ cd ~
ben#DESKTOP:~$ ls
ben#DESKTOP:~$ ls -a
. .. .bash_history .bash_logout .bashrc .profile
ben#DESKTOP:~$ cd ..
ben#DESKTOP:/home$ ls
ben
ben#DESKTOP:/home$ cd /ben
-bash: cd: /ben: No such file or directory
ben#DESKTOP:/home$ cd ..
ben#DESKTOP:/$ ls
bin boot dev etc home init lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
ben#DESKTOP:/$ cd ..
ben#DESKTOP:/$ cd /home/ben/apps
You're accessing /ben aka root_directory/ben
try: ~/apps or cd ben
WSL has both Ubuntu and Debian. apps is in Ubuntu, however my WSL was defaulting to Debian. That is why the directories were empty.

Is there an way to make WSL2 mount its folders on another drive outside Windows Preview Build 20211?

I've this SSD drive that I bought only for work so I would like WSL2 to write on it. Found this article which I was following thru, to find out wsl --mount is working on Windows Preview Build 20211, not on my build (Win 10 1909 18363.1110).
Is there an way to do this?
Thanks!
Found out later, with a little change of terms on my research, that it could be done as in this tut here: https://www.sitepoint.com/wsl2/
To make it quick for anyone searching around here, you have to export your Linux image, unregister it from wsl and then import it again on the other drive. How it's done:
List your distros
In a Windows Powershell terminal, enter wsl --list. It should return what distros you have installed and if they're running.
Export your distro
In the same Powershell, enter mkdir D:\backup to make a dir for your backup then export it using wsl --export <distro> D:\backup\<distro>.tar. In my case, wsl --export Ubuntu D:\backup\ubuntu.tar.
Unregister the distro
You have to remove it from the C: drive with wsl --unregister Ubuntu and to make sure it worked, after the process is done list all distros again with wsl --list.
Import the distro on another drive
The syntax for this will be wsl --import <distroName> <target\directory> <origin\image>. So if you'd like to make an directory for your WSL in your new drive, just do mkdir D:\wsl or name it anyway you want. I already have a folder for that, so I went with wsl --import Ubuntu D:\wsl-dev D:\backup\ubuntu.tar.
You can verify if it's done by using the very same wsl --list.
And if you want to change your default user from root, follow below steps.
For Ubuntu 18.04, the command to change default user is
ubuntu1804 config --default-user <username>
Took me a while to figure out. Finally found it thanks to this link

How to access a WSL instance from another?

I am upgrading my WSL2 instance from Debian 10 to Ubuntu 20.04 LTS, because I need some newer packages.
How do I copy files and directories from Debian to Ubuntu, preserving the permissions and owner? (uid and gid are the same in the two Linuxes.)
Copying to windows first changes the permissions and owner of files.
explorer.exe also changes permissions and owner.
Preferably, I'd also like to avoid having to create a shared disk image file that I could mount from Debian and Ubuntu in turn.
I'd like something simpler, like accessing the second WSL instance directly from the first, e.g.,
$ cp -a <Debian>/myfiles/ <Ubuntu>/myfiles
Is this possible?
See also my similar question: How to access \wsl$\othercontainer\some\file from within a WSL container? where the short answer is:
sudo mkdir /mnt/othercontainer
sudo mount -t drvfs '\\wsl$\othercontainer' /mnt/othercontainer
ls -l /mnt/othercontainer/some/file
NOTE: It looks like symbolic links aren't supported.
Use tar. It will preserve all the file metadata.
In <Debian>, create myfiles.tar.gz:
tar zcvf myfiles.tar.gz myfiles
Copy myfiles.tar.gz to your windows drive e.g. with explorer.exe or with /mnt/c, and then copy myfiles.tar.gz to <Ubuntu>. In <Ubuntu>, untar it:
tar zxvf myfiles.tar.gz myfiles

Creating directories from Windows to WSL

Is it possible to create user-privilleged directories from Windows to WSL directly?
I can create a folder from Windows, but it won't be the same as mkdir in WSL. For example, using Windows Explorer I create a new folder A
But, coming back to WSL, I can't cd A:
-bash: cd: A: Permission denied
Unless I do chmod 0761 * eventually. Isn't there a way to do that automatically?