Hyper-V reference
Table of Contents
Initial setup (once)
Install Hyper-V
- Start > Turn Windows features on or off
- Enable Hyper-V (and all children)
- Click OK
- Reboot
Add a second network interface
You only need to do this once - multiple VMs can share a network interface.
- Open Hyper-V Manager.
- Go to Action > Virtual Switch Manager.
- In "New virtual network switch", select "Internal" and click "Create Virtual Switch".
- Set the name to "Hyper-V Internal Network".
- Click OK.
- Go to Start > View network connections
- Right-click "vEthernet (Hyper-V Internal Network)" > Properties
- Select "Internet Protocol Version 4" and click Properties
- Select "Use the following IP address"
- Enter the IP
192.168.5.1
, or another IP of your choice - Click OK, then Close
Configure WSL 2
If you are using WSL 2 (not WSL 1) with Hyper-V, you need to allow the two virtual switches to communicate.
Run PowerShell as an administrator, then run:
Set-NetIPInterface -ifAlias "vEthernet (Default Switch)" -Forwarding Enabled
Set-NetIPInterface -ifAlias "vEthernet (WSL)" -Forwarding Enabled
Download Ubuntu ISO
Download the Ubuntu Server ISO (e.g. ubuntu-20.04.4-live-server-amd64.iso
).
VM setup
Configure DNS
e.g.
Name | Type | Address |
---|---|---|
example.djm.me |
A | 192.168.5.2 |
*.example.djm.me |
CNAME | example.djm.me |
Create a new VM
- Go to Action > New > Virtual Machine.
- If the "Before You Begin" screen is displayed, click Next.
- Enter a name for the VM, and click Next.
- Select Generation 2. Click Next.
- Enter the amount of memory to use (at least
3072 MB
for a netboot install). Leave "Dynamic Memory" ticked. Click Next. - Select "Hyper-V Internal Network". Click Next.
- Enter a size for the virtual hard disk. Click Next.
- Select "Install an operating system from a bootable image file", then select the Ubuntu ISO file. Click Next.
- Click Finish.
- Right-click the machine, then click Settings.
- In Add Hardware, select "Network Adapter" and click "Add". Set Virtual Switch to "Default Switch".
- In Security, untick "Enable Secure Boot".
- In Processor, set the number of processors.
- Click OK.
- Double-click the machine.
- Click Start.
Install Ubuntu
- Language
- Select English (UK)
- Installer update
- If prompted, update to the new installer
- Keyboard configuration
- Select layout and variant English (UK)
- Choose type of install
- Select Ubuntu Server
- Network connections
- Select eth1, then Edit IPv4
- Select method Manual
- Enter subnet
192.168.5.0/24
- Enter address
192.168.5.2
(make sure the last part is unique for each VM) - Leave the other fields blank
- Select eth1, then Edit IPv4
- Configure proxy
- Leave it blank
- Configure Ubuntu archive mirror
- Leave the default value
- Guided storage configuration
- Select Use An Entire Disk
- Select Done
- Storage configuration
- Change
ubuntu-lv
to use all available space (just enter999
) - Select Done, then Continue
- Change
- Profile setup
- Enter your name
- Enter the server name (local part only - e.g.
kara
) - Choose a username and password that you will use to log in
- Upgrade to Ubuntu Pro
- Skip
- SSH Setup
- Tick Install OpenSSH Server
- Optionally select Import SSH identity from GitHub and enter your username to import your SSH key
- Featured Server Snaps
- Don't select any
- Installing system
- Wait for it to finish
- Installation complete!
- Select Reboot
- When prompted, press Enter to reboot (the virtual DVD is ejected automatically - ignore any "Failed unmounting cdrom" errors)
Take a snapshot
It is a good idea to take a snapshot of the VM now, so you can roll it back later if it fails, or for testing.
You can now close the window - the VM will keep running in the background. (You can also close the main Hyper-V window.)
Connect via SSH
ssh dave@example.djm.me
Set up guest OS
See Ubuntu Setup.
Update dotfiles
Add it to my dotfiles SSH config.