Running different distributions of Linux or variants of BSD on Hyper-V has gotten a lot easier than it was even 2-3 years ago, but there are still considerations one should take when building VMs or VM templates for deployment in Hyper-V (or Azure), and my distribution of choice for a very long time has been Debian stable. While it might not have the feature set that Ubuntu has running on Hyper-V or Azure, I prefer it partly because it’s comfortable to me, and partly because I tend to agree with the Debian creedo. This will likely work for most distributions out there (Ubuntu included), but since Ubuntu gets all the love on Hyper-V and Azure, I figured I’d do a post around how to get the best performance out of your Debian installations on Hyper-V. At the time of this writing, the current stable release is 8.3 (Jesse), so that’s what you’re going to see here. Note that this is based on the “best practices” documentation currently found here.
Creating a virtual hard disk to install Debian
The first thing you’ll encounter when setting up Linux on a VHDX is that by default, unlike installing Windows onto a VHDX disk, you must use settings different from the defaults to better align with how non-NTFS filesystems (like ext) work. The powershell to make this happen is:
New-VHD –Path \path\to\file.vhdx –SizeBytes 127GB –Dynamic –BlockSizeBytes 1MB
Create a Debian VM
Once the VHDX is created successfully, you should create a new VM and configure the disk appropriately. I’ve created a CreateVM.ps1 script and put it up haphazardly on GitHub that can be used on Windows 8 / Server 2012 or higher hosts to automate the creation of VMs on Hyper-V locally, here. Running that script to create a Generation 2 VM (I’m doing this on Windows 10, for instance) looks like this (I’ve got 2 vSwitches created, one called “External” and one called “Internal” – I’m attaching this to the “Internal” network. If you’re curious how the script works, give it a review):
Once you’ve got your Debian VM created, you’ll need to install Debian. Mount an ISO and get going – once you get to the filesystem selection, you’ll need to do it manually. Once the installer gets to the partitioning phase, press ALT+F2 to get a new console, and use fdisk and mkfs to create and format your disk the way it needs to be for Hyper-V.
Once you’ve created the partitions and formatted any non-EFI and non-swap partitions (again, in this example I’m creating one big partition to hold everything, but your installation may contain multiple partitions if you so choose), go back and clean things up so that your partitions will be mounted and used by pressing ALT+F1 to get back to setup – choose the “Manual” partitioning method here:
That’s it – once your installation is finished, the rest is up to you.
Here’s the numbers from a VM with a VHDX that hasn’t gone through the optimization process documented above, but is running in the exact same partition structure and filesystems, running on the same host (underlying disk subsystem for the VHDX is a Samsung 830 Pro SSD, for reference):