«

»

Mar 21

Print this Post

Debian 8.3 on Hyper-V (the recommended way)

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 the script runs and opens / connects to the Debian VM, you should see the VM connection window pop up.  Taking a look at the settings will show you something like this:

Investigating the VHDX file should show us that it’s block size is 1MB:

A quick look at a standard VHDX file will show the default (32MB), if you’re curious:

Install Debian

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.

Create the first (EFI) partition if this is a Gen2 (UEFI) VM:

Create the second (ext4, “Linux filesystem”) partition:

Create the third (swap) partition, and write changes to disk:

Next, you will need to format the EFI and ext4 partitions using mkfs – don’t forget to type “w” after you’re finished to write all of that to the disk!!!:

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:

Choose the second (ext4) partition:

Change the “Use as:” option from “do not use” to “Ext4 journaling file system”:

Set the “Mount point” option to be the root of the filesystem ( “/” ), and select “Done setting up the partition”:

Next, select “Finish partitioning and write changes to disk” and “Yes” when prompted to write changes to disks, and the installation should continue:

That’s it – once your installation is finished, the rest is up to you.

Test performance

You can run a benchmark to see what kind of performance you’re getting from your Debian VM (I’m using hdparm and bonnie++, but you can use dd or whatever tool of your choice here):

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):

If you want to validate that the Hyper-V Integration Components (ICs) are running, use lsmod to see that the hv_* components are indeed loaded:

Permanent link to this article: http://www.cluberti.com/blog/2016/03/21/debian-8-3-on-hyper-v-the-recommended-way/

Bad Behavior has blocked 394 access attempts in the last 7 days.