Categories
Linux

Creating an “optimised” Debian UEFI / Gen2 Hyper-V Virtual Machine

First, we’ll use PowerShell to create your new Hyper-V VM. You’ll need to edit the variables at the top of this script (in bold) – note the size of the OS disk will be 32GB, you can change this, but will need to adjust partition layout / sizes accordingly.

# Change text in BOLD
$vmname = "DEBIAN" # Desired Virtual Machine Name
$vmpath = "E:\" # Root folder for Hypver-V VM (a folder will automatically be created for the VM itself)
$virtual_switch = "vSwitch" # Hypver-V Host vSwitch name to connect VM to
$netboot_iso = "C:\Users\chris\Downloads\debian-8.6.0-amd64-netinst.iso" # Debian Net Install ISO Path

# Create a new VHD:
New-VHD –Path "$vmpath\$vmname\Virtual Hard Disks\$vmname.vhdx" –SizeBytes 32GB –Dynamic –BlockSizeBytes 1MB

# Create the new VM:
New-VM -Name $vmname -MemoryStartupBytes 4096MB -Generation 2 -VHDPath "$vmpath\$vmname\Virtual Hard Disks\$vmname.vhdx" -SwitchName $virtual_switch
Add-VMDvdDrive $vmname 
Set-VMDvdDrive -VMName $vmname -Path $netboot_iso

# Disable secureboot the vm (will not boot from ISO without this):
Set-VMFirmware -VMName $vmname -EnableSecureBoot Off

# Disable Dynamic Memory (not supported by Debian):
Set-VMMemory $vmname -DynamicMemoryEnabled $false

# Now, power on the machine.
Start-VM -Name $vmname

Now, connect to the VM via the Hyper-V console and proceed to load the Debian setup wizard. Continue through the wizard until you are prompted to configure partitions / storage; at this point breakout to a new console (Ctrl-Alt F1).

Now we’ll manually define our partitions / desired filesystem based on the latest Microsoft recommendations here. Above, we created a 32GB VHD – if you changed this figure, change the commands below to suit. Where I have written “<default>” just hit enter. Note, you will wipe the drive this partition layout is applied to, you do this at your own risk.

Desired partition layout:

  • UEFI System Boot : 512MB
  • root / – ext4: 27GB
  • swap : <remaining space>

From your new console, use these commands:

fdisk /dev/sda
g
p
	n
	1
	<default>
	+512M
	t
	1

	n
	2
	<default>
	+27G

	n
	3
	<default>
	<default>
	t
	3
	14
w

Now, switch back to the Debian setup wizard and select “manual” for disk configuration / partitioning, then select each of the partitions and configure as below:

Partition 1: use as: UEFI System Partision (ESP)
Partition 2: use as: ext4, mount point "/"
Partition 3: use as: swap

Complete the installation as normal – you’re all done.

4 replies on “Creating an “optimised” Debian UEFI / Gen2 Hyper-V Virtual Machine”

Leave a Reply

Your email address will not be published. Required fields are marked *