WSL session can not survive hibernation in No Hyper-V Windows - windows-subsystem-for-linux

In order to run VirtualBox I have to disable Hyper-V features by editing bcd as follows:
bcdedit /copy {current} /d "Windows 10"
bcdedit /set {current} description "No Hyper-V"
bcdedit /set {current} hypervisorlaunchtype Off
But when I run Windows in "No Hyper-V" my WSL session can not survive a hibernation, as the system wakes up WSL session disappeared.
Any advice? Thanks,

Related

CMD gives error Feature Name Microsoft-Hyper-V Is Unknown

I tried to disable Hyper-V in the Command Prompt and it gave this error :
Feature Name Microsoft-Hyper-V Is Unknown
The Hyper-V has not been disabled.
Try this:
Open elevated command prompt and run bcdedit /set hypervisorlaunchtype off and restart
If that doesn't work, try this instead:
Open optionalfeatures.exe and un-check Hyper-V
Hope this helps!

Windows commands inside WSL hang a very long time

wsl --version
WSL version: 0.60.0.0
kernel version: 5.10.102.1
WSLg version: 1.0.34
MSRDC version: 1.2.2924
Direct3D version: 1.601.0
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.160
Distro Version
Ubuntu 20.04.4 LTS
This issue is found when I upgrade my windows to 10.0.22621.160
Reproduce steps:
execute "wsl.exe --version" (a windows command)
--> the console output the result and frozen for dozens of seconds that I can't input next command.
execute "wsl.exe --version | cat" (windows command with pipe)
--> the console output the result and ready for next command normally.
execute "uname -a" (a native linux command)
--> the console output the result and ready for next command normally.
execute "wsl.exe --version > /proc/self/fd/1 (pipe to standard output)
--> same as "wsl.exe --version", the console will frozen dozens of seconds
So I think there must be something wrong with the standard output for windows command running in WSL session.
PS: I've raised a case to microsoft feedback hub and the github.
https://github.com/microsoft/WSL/issues/8544
https://aka.ms/AAhd1ld

WSL after trying all the steps to upgrade to version 2 if get a failure: WslRegisterDistribution failed with error: 0x80370102

Launch any WSL from within VS Code "No WSL distros found. New distros can be installed from the Microsoft Store.
Source Remote - WSL (Extensions)
BUTON: "Add Distro" --> takes you to the store. Install the version of Linux, and try to start it and you get the following. I've had WSL working before and now cannot get it back to the original working WSL.
I tried some things to update to version 2 and I could list version with command "WSL -l -v" it showed up but not anymore. I've got the features set properly. WSL feature is enabled. I did try setting a bios "Virtualization Technology" this is on a HP laptop with AMD 64 bit cpu. That is off now after finding it doesn't help.
Features on: "Virtual Machine Platform", "Windows Hypervisor Platform" "Windows Subsystem for Linux" There are others but these seem relevant.
Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x80370102
Error: 0x80370102 The virtual machine could not be started because a required feature is not installed.
Press any key to continue...
This had to have the bios setting. Also because of being Windows 10 Home didn't have Hyper V feature, but there is a batch that can add this. There is a msi to install WSL 2 so wsl.exe was upgraded. This got the results to show WSL version 2 for ubuntu-20-04 install Also there was some resets needed to get the "WSL -l -v" command to have running.
I don't know 100% certain that these are the cure to the issue. But may help someone who cannot get the Linux to start w/out various error running on windows subsystem Linux. Took me better part of a day to fix.
find the following by googling "del hyper-v.txt" you will hit a page telling you "How to activate Hyper-V in Windows 10 Home"
source of batch command
https://github.com/MicrosoftDocs/Virtualization-Documentation/issues/915
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del hyper-v.txt
Dism /online /enable-feature /featurename:Microsoft-Hyper-V -All /LimitAccess /ALL
pause
Reboot, still not running, but needed the following sequence.
wsl --shutdown
netsh winsock reset
netsh int ip reset
ipconfig /release
ipconfig /renew
ipconfig /flushdns
wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
initially there was a root user only. Updated new user with the following in %userprofile% folder. Omit the dash and dot.
Ubuntu2004 config --default-user addedUsername
The WSL now is seen by VS Code extensions and no longer flagging to update to version 2. Now on to RxJS tutorial under VS Code.
Make sure all related settings in the bios are enabled.
Make sure all related features in the windows features are turned on.
Alright, if there is an error:
Turn off all related features
Restart it.
Turn on.
Restart it.
related features = ( virtualization )

Setting up Password Free SSH from Linux to Windows 10

I'm trying to set up a password free ssh path from a linux server to a windows machine. I currently have MobaSSH running on the windows machine. I can ssh from the linux server to the windows machine fine and execute commands just fine but I have to enter a password.
I create a public RSA key on the linux system and using WinSCP I copied the file over to the C:\Users\MyUserName\.ssh folder and restarted the MobaSSh service on the windows machine.
It still won't let me ssh in without a password. What am I missing here? Any help vastly appreciated.
OpenSSH is available for Windows 10 and has worked very reliably for me. I can consistently connect from a Linux machine without a password. Here is how to set it up.
upgrade to Windows 10 version 1809 or higher
check via: powershell -c "(Get-Item 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion').GetValue('ReleaseID')"; see also systeminfo | findstr /B /C:"OS Name" /C:"OS Version" for Pro vs. Home, build number
upgrade via Windows Update settings or Download Windows 10 (the latter works around an issue where some systems are stuck at 1803)
install SSH client and server (as administrator; source) - in Windows PowerShell:
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd # remote login should be possible following this command
Set-Service -Name sshd -StartupType 'Automatic'
Get-NetFirewallRule -Name *ssh* # there should be a firewall rule named "OpenSSH-Server-In-TCP" # optional
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 # optional
enabling public key login for administrators (source) - from Linux command-line:
scp ~/.ssh/id_rsa.pub administrator#remote_computer_name:'C:\ProgramData\ssh\administrators_authorized_keys' # if using an alternate method, ensure file is not UTF-16 encoded
icacls C:\ProgramData\ssh\administrators_authorized_keys /remove "NT AUTHORITY\Authenticated Users"
icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r
get-acl C:\ProgramData\ssh\ssh_host_dsa_key | set-acl C:\ProgramData\ssh\administrators_authorized_keys
enabling public key login for non-administrators - in Windows PowerShell:
Install-Module -Force OpenSSHUtils -Scope AllUsers # for: Repair-AuthorizedKeyPermission
cd C:\Users\...
ssh-keygen # create ~/.ssh
# add key(s) to ~/.ssh/authorized_keys
$ConfirmPreference = 'None'; Repair-AuthorizedKeyPermission -FilePath .ssh\authorized_keys
# if above fails, try ''%%Set-ExecutionPolicy Unrestricted -Scope CurrentUser%%''; see also https://github.com/PowerShell/Win32-OpenSSH/issues/1245#issuecomment-440388604

Vagrant can't connect to the VM

EDIT6: submitted an official path bug: https://github.com/mitchellh/vagrant/issues/7512
EDIT5: When I do vagrant destroy and vagrant up, everything works easily. But when I turn off the VM and turn it back on (you have to restart your PC some day), it won't work again. Either the sequence for vagrant up when the VM is created is bugged or VirtualBox is bugged. Destroying and rebuilding the VM is not the option, cause the DB migration and everything takes ~30 mins at least. Either way, DON'T USE VAGRANT ON WINDOWS 10.
EDIT4: I downgraded to Virtual Box 5.0.0.10, that fix the wrong path problem, but the error Command not in installer persists.
EDIT3: When I went into vagrant up --debug, I found out that it cycles. It gets into line
INFO subprocess: Starting process: ["C:/Program Files/Oracle/VirtualBox/VBoxManage.exe", "showvminfo", "8aaee3a3-806f-4
8ad-9928-91e2b7baba5d", "--machinereadable"]
and then it does
INFO subprocess: Command not in installer, restoring original environment...
The path to VM uses forwards slashes instead of backslashes. Is this a bug? Is there a way to manually set path to VM? I have put C:\Program Files\Oracle\VirtualBox in my PATH.
EDIT2: DON'T USE VAGRANT ON WINDOWS 10, it's bugged in many ways, also VM is not optimalized for win10 yet, you'll get bunch of issues that you won't be able to solve. Also tried the Otto from Hashicorp, not working either. Rip.
EDIT: okay, so when I do vagrant destroy and vagrant up, after 10 minutes of installation it works like a charm. But after I restart my PC or logout in any way, Vagrant is unable to connect to the VM, neither with a private key, nor with login/password. Is that a bug?
When I do vagrant up, VM starts properly, but Vagrant is unable to connect. All it says is Warning: Remote connection disconnect. Retrying...
When I try to connect via vagrant ssh, I get only ssh_exchange_identification: read: Connection reset by peer. When I check GUI of the VM, it is waiting for login, and when I login with defult login/password, it is working as intended, so the problem must be Vagrant not being able to connect to the VM.
I tried:
checking if my pc supports virtualization and checking if it is on
trying to connect with password instead of a key
configuring networking adapetrs
turning off firewall
clean reinstall
I am using Vagrant 1.8.1 and VirtualBox 5.0.20 on Windows 10.
This is my vagrant file:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provider :virtualbox do |vb|
vb.memory = 2048
vb.gui = true
vb.cpus = 2
end
config.vm.network :private_network, type: "dhcp"
config.vbguest.auto_update = false
config.ssh.insert_key = false
config.vm.provision :shell, path: "bootstrap.sh"
end
[Edit 17/06/2016]
The problem should be resolved with Virtualbox 5.0.22.
https://www.virtualbox.org/wiki/Changelog
https://www.virtualbox.org/ticket/15412
[Original answer below]
In contrast to my earlier answer I now don't think that I encounter the same problem as you have described here. However I still think that you encounter a different variation the problem.
As of feedback received from Virtualbox development https://www.virtualbox.org/ticket/15412 I learned that Virtualbox 5.0.20 includes changes to the NAT Forwarding Rules to address other bugs. When a VM is saved and started again, Virtualbox now removes the network cable for 5 seconds. This is supposed to trigger the DHCP client to request a new lease. This information in turn is then used by Virtualbox to infer the IP address and NAT should work.
In my particular case I encounter this problem with Ubuntu 16.04 as guest VM whereas with Ubuntu 14.04 it works. This indicates to me that the DHClient on Ubuntu 14.04 does request a new lease after the cable was disconnected by Virtualbox whereas this is not the case with Ubuntu 16.04.
In order to verify that you encounter the same problem, I wonder if you could run the below test and let me know.
Login to the Trusty VM console (i.e. the one that you get displayed when you run the VM in the foreground)
Install 'arping' (sudo apt-get -y install arping)
Create the below script 'sendARP.sh'
#!/bin/bash
IFACE=$(ifconfig | grep 'Link encap:Ethernet' | awk '{print $1}')
IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
arping -c 1 -i $IFACE $IP
Make it an executable 'chmod +x sendARP.sh'
Save the Trusty VM (vagrant suspend)
Start your Trusty VM from saved state (vagrant up)
Login to the Trusty VM console (i.e. the one that you get displayed when you run the VM in the foreground)
Run the script 'sudo ./sendARP.sh'
Test whether you can connect via SSH from the remote location/ Virtualbox host
Bugs:
https://github.com/mitchellh/vagrant/issues/7306
https://www.virtualbox.org/ticket/15412