Sunday, January 3, 2021

What To Do in Case Hyper-V "Default Switch" is Missing or Disappear?

Starting my laptop today, I noticed that in my Task Manager, the "Default Switch" adapter has disappeared from the network adapters. Then I noticed that I can't ssh to the Hyper-V VM I setup few days earlier. This quite puzzled me because as turns out the ArchWSL I setup with WSL2 also failed to start, and this error flooded my event viewer. As a side note, the VM starts fine, but it doesn't have any network at all.

Tried to delete Hyper-V feature and reinstalling it back, issue still persist. sfc /scannow, "Windows protection did not find any integrity violations". So one best guess is that somehow removing Hyper-V doesn't remove all the network switches configuration. Time to do something dangerous.

Strong Notice: Steps below is dangerous to do. Consider creating system restore point prior performing steps I mentioned below. You'll also lose all your Hyper-V VMs (and all Virtual Switch configurations) so ensure you have exported your VM beforehand.

  1. Be prepared for lots of reboots.
  2. Uninstall Hyper-V and all its related components. In optionalfeatures.exe, untick Hyper-V, Virtual Machine Platform, and Windows Hypervisor Platform. Unticking Windows Subsystem for Linux is not needed (despite using Hyper-V for WSL2). Then, click reboot.
  3. Open regedit.exe, then navigate to HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\vmsmp\parameters\SwitchList and delete all subkeys there. Same goes to NicList above SwitchList, remove all subkeys.
  4. Reboot
  5. Repeat step 3 until there are no more subkeys.
  6. If you deleted some values in step 5, reboot.
  7. Go to C:\ProgramData\Microsoft\Windows\Hyper-V, you may need to take the ownership of that folder, don't worry. Windows Explorer will ask you to do so in 1 click of a button.
  8. Delete everything in that folder.
  9. Reboot
  10. Repeat step 3 and 5 again
  11. Do the reverse of step 2, including the reboots.
  12. After the system boots up for a while, open elevated powershell and command prompt. In the elevated powershell, type "Get-VMSwitch". This one should hang, don't worry. Then in the elevated command prompt, execute "sc start hns".
  13. Wait for a moment, then you should see "Default Switch" back in Task Manager. And the elevated powershell window should return values (no longer hangs).
  14. Reconfigure your network switch if needed
  15. Import back your VMs.

I don't quite remember the steps but that's what I've been done. Now WSL2 starts again and I cna ssh back to the VMs after I imported it.

What a blog post to start 2021

https://knowyourmeme.com/photos/1918696-disappointed-black-guy

... unless it shows 34 December 2020 instead


No comments:

Post a Comment