Skip to content

Instantly share code, notes, and snippets.

@paseaf
Last active January 6, 2023 08:20
Show Gist options
  • Save paseaf/2e3494d330387260b09258d09027a385 to your computer and use it in GitHub Desktop.
Save paseaf/2e3494d330387260b09258d09027a385 to your computer and use it in GitHub Desktop.
Hyper-V Linux on Windows How-Tos

Hyper-V How-Tos

Set up a Static IP for Hyper V guest OS

Motivation: to ssh to the VM without always figuring out what the VM's current IP is.

Windows' default switch dynamically assigns IP address to Hyper V Vms whenever Windows restarts.
To assign a static IP address to a VM, we need to set up an Internal Switch.

Steps:

  1. In Hyper V: Create an internal Switch

  2. In Control Panel\Network and Internet\Network Connections
    Configure its IPv4 properties as follows:
    IP address: 192.168.0.2
    Subnet mask: 255.255.255.0
    Default gateway: 192.168.0.1 // router

  3. Add the Switches to the VM. Your VM should have two network adapters: one Default and one Internal

  4. Log into the VM, configure Networking as follows:
    IPv4->Manual
    Address: 192.168.0.3
    Netmask: 255.255.255.0
    Gateway: 192.168.0.1

Now you should be able to ping to your VM on Windows with static IP 192.168.0.3

Add a new VM to existing Internal Switch

  1. In Hyper-V, add the Internal Switch to the VM
  2. In the VM, configure the switch as follows:
    IPv4->Manual
    Address: 192.168.0.4
    Netmask: 255.255.255.0
    Gateway: 192.168.0.1

Share files between guest and host OS

  1. On Linux guest: Set up samba server https://docs.fedoraproject.org/en-US/quick-docs/samba/
  2. On Windows host: Add a network location following this guide

Give Guest OS access to WebCam

https://www.tenforums.com/virtualization/174394-how-add-webcam-windows-10-vm-hyper-v.html

  • Failed on Fedora 35

Upgrade OpenSSH on Windows

It fixes some weird issues (like cannot send Ctrl-<space> via ssh).

  1. uninstall the current one from Settings -> Optional features
  2. Install the latest version and update PATH following https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH

Turn on Enhanced Mode for a VM

  1. Open PowerShell Administrator
  2. Run Set-VM -VMName 'Your VM Name' -EnhancedSessionTransportType HvSocket

VIM/NeoVIM Yank to Windows System clipboard from via SSH

  1. Install Xserver client [VcXSrv](https://sourceforge.net/projects/vcxsrv/
  2. Add to windows env variable: Name: DISPLAY, Value: localhost:0
  3. SSH to Linux with -Y: ssh -Y user@host
  4. Verify by checking if xcalc works
  5. Set VIM to yank to system clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment