Change bash.exe with multiple linux subsystems on windows - windows-subsystem-for-linux

I first installed a Ubuntu linux subsystem with the windows store.
I then installed the hyper terminal for windows like explained in this tutorial : https://medium.com/#ssharizal/hyper-js-oh-my-zsh-as-ubuntu-on-windows-wsl-terminal-8bf577cdbd97
Like it is written in the tutorial I put C:\\Windows\\System32\\bash.exe in the hyper configuration file.
However, afterwards, I installed another linux subsystem, Wlinux.
So now I have two subsytems located here
Wlinux : C:\Users\martinpc\AppData\Local\Packages\WhitewaterFoundryLtd.Co....
Ubuntu : C:\Users\martinpc\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_7...
However, when I open the hyper terminal, It seem like I can only access the files of the ubuntu distrib and not the Wlinux. Therefore, I would like to know how I can point Hyper to Wlinux and not Ubuntu anymore. Thank you for your answer.

First of all, bash.exe has been deprecated. You should use wsl.exe in command lines. Check your installed distributions in WSL with wslconfig.exe /list /all command. Alternatively, for Windows 10 version 1903 and above, wsl.exe --list --all command can be used. Choose the distribution that you want to connect with HyperJS Terminal emulator. Open up Hyper.js configuration with Ctrl + , or open %UserProfile%\.hyper.js in any text editor. Edit the shell configuration from these two named values:
shell: 'C:\\Windows\\System32\\wsl.exe',
shellArgs: ['--distribution', 'Your-Distro-Name'],
Alternatively, you can use wslconfig.exe /setdefault <DistributionName> command to change default distribution. With this step, you can skip the shellArgs line in .hyper.js configuration file.

Related

Boot QEMU KVM with libvirt/sVirt but without using virt-install tool in command line

Can anyone help me on how to boot QEMU KVM with libvirt/sVirt but without using virt-install tool in command line.
or using virsh tool
In order to use virt-install, you need to install the following:
yum install qemu-kvm qemu-img libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils tigervnc-server
Then, you can start the daemon:
systemctl start libvirtd
Now, download the OS you want to install, and then copy it to the folder shown below:
cp CentOS-7-x86_64-Everything-1708.iso /var/lib/libvirt/images/
Finally, run virt-install. Here is an example of what the script should look like:
os="--os-type=linux --os-
variant=centos7.0"
location="--location=/var/lib/libvirt/images/CentOS-7-x86_64-Everything-1708.iso"
cpu="--vcpus 2"
ram="--ram 2048"
name="centos7"
disk="--disk /dev/mapper/centos_192- root,size=40"
type="--virt-type qemu"
network="--network network=default"
graphics="--graphics none"
virt-install $os $network $disk $location $cpu $ram $type $disk $graphics --name=$name
After running virt-install, verify that the VM is running using virsh:
virsh list
Id Name State
----------------------------------------------------
4 centos7 running
Virt-install command-line options
Below are some command-line options, but this isn't an extensive list, so I encourage you to do some research in order to fully take advantage of this tool.
os="--os-type=linux --os-variant=centos7.0" --
Some of these commands have main options, as well as sub options. For example, if you type os-type=linux, then you need to further specify --os-variant=centos7.0. You can get a list of OSes that virt-install supports by typing osinfo-query os.
location="--location=/var/lib/libvirt/images/CentOS-7-x86_64-Everything-1708.iso"
This is where you've copied the ISO image file containing the OS you want to install.
cpu="--vcpus 2"
The CPU command-line option enables you to specify the number of vCPUs assigned to the VM. In this example, I'm assigning two vCPUs.
ram="--ram 2048"
The RAM command-line option enables you to specify the amount of memory assigned to the VM. In this example, I'm assigning 2,048 MBs -- or 2 GBs.
name="centos7"
The name command-line option enables you to assign a name to the VM. In this example, I'm naming the VM centos7.
disk="--disk /dev/mapper/centos_192-root,size=40"
This is where the VM will be installed and the size, in gigabytes, to be allocated. This must be a disk partition and not a mount point. Type df -h to list disk partitions.
type="--virt-type qemu"
The type command-line enables you to choose the type of VM you want to install. You can use KVM, QEMU, Xen or KQEMU. Type virsh capabilities to list all of the options. In this example, I'm using QEMU.
network="--network network=default"
Use network=default to set up bridge networking using the default bridge device. This is the easiest method, but there are other options.
graphics="--graphics none"
The graphics command-line option specifies that no graphical VNC or SPICE interface should be created. Use this for a kickstart installation or if you want to use a ttyS0 serial connection.

How to create a Linux GUI app short cut for WSL2 on Windows10?

I have properly installed and setup WSL2. It works fine.
I also setup X11 forwarding and X server (VcXsrv). I can launch GUI apps such like konsole or gvim or even google-chrome from a bash shell.
Now I want to launch konsole by simply double clicking a short cut on the desktop without launching the bash command mode terminal. How should I do it?
I tried running this in cmd:
> wsl /usr/bin/konsole
and it reports:
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
I'm guessing it is because some X11 forwarding configurations were not properly setup, so I created a k.sh as follows:
#!/usr/bin/bash
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
export LIBGL_ALWAYS_INDIRECT=1
/usr/bin/konsole &
The first two lines were the X11 settings in my .bashrc, the last line launches konsole.
It works fine under bash environment; but when I ran
wsl k.sh
from windows cmd environment, it silently quitted without launching the konsole.
I'm out of ideas. What should I do to directly launch konsole or other Linux GUI apps under windows without having to getting into bash?
Thanks in advance.
You are asking about two different command-lines, and while the failures in running them via the wsl command have the same root-cause, the underlying failures are likely slightly different.
In both cases, the wsl <command> invocation results in a non-login, non-interactive shell where the command simply "runs and exits".
Since the shell is non-login/non-interactive, your startup files (such as ~/.bashrc and ~/.bash_profile, among others) are not being processed.
When you run:
wsl /usr/bin/konsole
... the DISPLAY variable is not set, since, as you said, you normally set it in your ~/.bashrc.
Try using:
wsl -e bash -lic "/usr/bin/konsole"
That will force bash to run as a login (-l), interactive (-i) shell. The DISPLAY should be set correctly, and it should run konsole.
Note that the quotes probably aren't necessary in this case, but are useful for delineating the commands you are passing to bash. More complicated command-lines can be passed in via the quotes.
As for:
wsl k.sh
That's likely a similar problem. You are doing the right thing by setting DISPLAY in your script, but I notice that you aren't using a fully-qualified path it. This would normally work, of course, if your script is in a directory on the $PATH.
But I'm guessing that you might add that directory to the $PATH in your startup config, which means (again) that it isn't being set in this non-login, non-interactive shell.
As before, try:
wsl -e bash -lic "k.sh"`
You could also use a fully-qualified path, of course.
And, I'm fairly sure you are going to run into an issue with trying to put konsole in the background via the script. When WSL exits, and the bash shell process ends, the child konsole process will terminate as well.
You could get around this with a nohup in the script, but then you also need to redirect the stderr. It's probably easiest just to move the & from the script itself to the command-line. Change your k.sh to:
#!/usr/bin/bash
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
export LIBGL_ALWAYS_INDIRECT=1
/usr/bin/konsole
Then run it with:
wsl -e bash -lic "k.sh &"`
Finally, a side note that when and if you can upgrade to Windows 11, it will automatically create Windows Start Menu entries for any Linux GUI app you install that creates a .desktop file. You can manually create .desktop files to have WSL create Start menu items for most applications.
For reference, in Windows 11 it's easier. To run a GUI application without a terminal window popping up, you just need to call wslg.exe instead of wsl.exe.
So, for example:
target: C:\Windows\System32\wslg.exe konsole
start in: C:\WINDOWS\system32
shortcut key: None
comment: Konsole
This tutorial shows how to install VcXsrv and and edit .bashrc to ensure that the "DISPLAY env var is updated on every restart".
DISPLAY env var needs to be dynamic setting.
I've used it successfully with WSL2 on Windows10 Version 21H2 (OS build 19044.2130) to run Chrome, Edge, and thunar. I'm using the Ubuntu 20.04 Linux distro.
To edit .bashrc follow these instructions.

PhpStorm SSH / SFTP cygwin

I want to use my cygwin configuration for SSH ou SFTP connection but doesn't work.
My configucation file "config" is in directory C:\cygwin64\home\<username>\.ssh. This configuration file define an SSH proxy jump and send some environment variables. This configuration file work fine in cygwin to connect in SSH or SFTP.
In PhpStorm settings I've specified the shell path in Tools > Terminal to be C:\cygwin64\bin\bash.exe --login -i. All local terminal use cygwin fine. But the ssh connection don't use my configuration file. I tried copying configuration in C:\Users\<username>\.ssh directory but that does not work.
Can you help me?
Generally, creating %USERPROFILE%/.ssh/config file pointing to the actual location of keys (using a valid Windows path) should help. But PhpStorm does not support ProxyJump and ProxyCommand instructions in it because there is no support for it from OpenSSH client's Windows port and we cannot use Cygwin or MinGW OpenSSH clients, which support proxying, but require running in theirs own shell subsystem. Here's a related bug report: https://youtrack.jetbrains.com/issue/IDEA-214679
I found the solution. You need to install the latest version of OpenSSH. To achieve this, I did the following actions:
Installing the scoop package manager (https://scoop.sh/) using PowerShell
$ Set-ExecutionPolicy RemoteSigned -scope CurrentUser Answer Y
$ Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
Installing OpenSSH
$ scoop install win32-openssh
normally the installation modifies the environment variable %PATH% to add the path something like C:\Users\<username>\scoop\shims. Otherwise you have to add it.
Modification of the environment variable %PATH% to remove the path C:\Windows\System32\OpenSSH
Enable the "OpenSSH Authentication Agent" service
On keyboard press Windows + R
Type: services.msc and press Enter.
Double click on the "OpenSSH Authentication Agent" service
Select the "Automatic" start type and start the service.
After these actions, I was able to connect from the Windows cmd terminal. I tested from PhpStorm and it works too.

"Windows Subsystem for Linux has no installed distributions" even though 'Ubuntu' is installed

I recently moved my wsl directory to another drive due to low storage in C: drive. As per the answer provided in this StackOverflow post, I used lxrunoffline tool and moved my Ubuntu distribution to another drive (E:\wsl in my case). As soon as the distribution was moved successfully, I ran wsl to test and it worked like a charm.
Everything went fine until one day I accidentally renamed the E:\wsl folder to something else. Well, as expected, wsl didn't work. Then, I reverted back to the name wsl and expected it to work but to my surprise, it didn't find any installed distribution after that even though it's installed... 😕
E:> wsl
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore
Is there any way to revert back to the old directory or make wsl point to a manual location?
EDIT: I don't want to reset Ubuntu as I want to retain the installed packages and preferences...
Well, I finally found a solution to this problem. 😊
This is as simple as registering the distribution using lxrunoffline tool using the rg or register command.
E:\LxRunOffline\LxRunOffline-v3.3.3>lxrunoffline rg
[ERROR] the option '-d' is required but missing
Options:
-n arg Name of the distribution
-d arg The directory containing the distribution.
-c arg The config file to use. This argument is optional.
After running the register command, I was able to start wsl as usual. But that would log you in as a "root" user and would thus start in "/root" directory. I ran the following command to start wsl as different user (this is for Ubuntu):
ubuntu config --default-user <user-name>

How to enable X11 forwarding in PyCharm SSH session?

The Question
I'm trying to enable X11 forwarding through the PyCharm SSH Terminal which can be executed via
"Tools -> Start SSH session..."
Unfortunately, It seems there is no way of specifying the flags like I would do in my shell for enabling the X11 Forwarding:
ssh -X user#remotehost
Do you know some clever way of achieving this?
Current dirty solution
The only dirty hack I found is to open an external ssh connection with X11 forwarding and than manually update the environment variable DISPLAY.
For example I can run on my external ssh session:
vincenzo#remotehost:$ echo $DISPLAY
localhost:10.0
And than set on my PyCharm terminal:
export DISPLAY=localhost:10.0
or update the DISPLAY variable in the Run/Debug Configuration, if I want to run the program from the GUI.
However, I really don't like this solution of using an external ssh terminal and manually update the DISPLAY variable and I'm sure there's a better way of achieving this!
Any help would be much appreciated.
P.s. Making an alias like:
alias ssh='ssh -X'
in my .bashrc doesn't force PyCharm to enable X11 forwarding.
So I was able to patch up jsch and test this out and it worked great.
Using X11 forwarding
You will need to do the following to use X11 forwarding in PyCharm:
- Install an X Server if you don't already have one. On Windows this might be the VcXsrv project, on Mac OS X the XQuartz project.
- Download or compile the jsch package. See instructions for compilation below.
- Backup jsch-0.1.54.jar in your pycharm's lib folder and replace it with the patched version. Start Pycharm with a remote environment and make sure to remove any instances of the DISPLAY environment variable you might have set in the run/debug configuration.
Compilation
Here is what you need to do on a Mac OS or Linux system with Maven installed.
wget http://sourceforge.net/projects/jsch/files/jsch/0.1.54/jsch-0.1.54.zip/download
unzip download
cd jsch-0.1.54
sed -e 's|x11_forwarding=false|x11_forwarding=true|g' -e 's|xforwading=false|xforwading=true|g' -i src/main/java/com/jcraft/jsch/*.java
sed -e 's|<version>0.1.53</version>|<version>0.1.54</version>|g' -i pom.xml
mvn clean package
This will create jsch-0.1.54.jar in target folder.
Update 2020:
I found a very easy solution. It may be due to the updated PyCharm version (2020.1).
Ensure that X11Forwarding is enabled on server: In /etc/ssh/sshd_config set
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
On client (MacOS for me): In ~/.ssh/config set
ForwardX11 yes
In PyCharm deselect Include system environment variables. This resolves the issue that the DISPLAY variable gets set to the system variable.
EDIT: As seen in the below image it works. For example I used the PyTorch implementation of DeepLab and visualize sample images from PASCAL VOC:
X11 forwarding was implemented in 2021.1 for all IntelliJ-based IDEs. If it still doesn't work, please consider creating a new issue at youtrack.jetbrains.com.
By the way, the piece of advice about patching jsch won't work for any IDE newer than 2019.1.
In parallel, open MobaXTerm and connect while X11 forwarding checkbox is enabled. Now PyCharm will forward the display through MobaXTerm X11 server.
This until PyCharm add this 'simple' feature.
Also, set DISPLAY environment variable in PyCharm run configuration like this:
DISPLAY=localhost:10.0
(the right hand side should be obtained with the command echo $DISPLAY in the server side)
Update 2022: for PyCharm newer than 2022.1: Plotting in SciView works by only setting ForwardX11 yes in .ssh/config (my laptop OS is ubuntu 22.04). I did not set any other parameters either on the server or local side.