If you plan to run Ubuntu Server on Hyper-V generation 2, there are a few things to think about that we came across when setting up a Ubuntu 16.04 Server.

Secure boot

Generation 2 VHDx comes with Secure Boot which essentially is a signature checking mechanism during the OS loader to validate that only approved components are allowed to be run. Secure Boot is defined as part of the UEFI specification. Hyper-V implements a subset which allows Windows 8 and Windows 8.1 with default policies to load in a virtual machine with Secure Boot enabled. Problem is that you can’t boot an Ubuntu Server ISO with Secure Boot turned on, so what you have to to is to turn it off under firmware settings.

After that the VM will start without any issues.

Large VHDX

One thing that surprised us was when we made a growable disk it actually took up pretty large space on the physical hard drive as well. This is not what we’re used on as we primarily use VMware, but after some googling we found the answer. It turns out that the default block size for VHDx disks are 32 MB. So if you make a very large disk (let’s say 64 TB like in our case) it will create 32 MB blocks for all that 64 TB space when formatting the disk in the guest OS. To solve it you have to create a disk in Powershell with 1 MB blocksize instead.

New-VHD -Path D:\VHDX\example.vhdx -SizeBytes 64000GB -Dynamic -BlockSizeBytes 1MB

From the Microsoft Forum:

The .VHD and .VHDx images are sparse files. When a dynamic .VHDx is created with a maximum size of 127 GB, the initial size is about 256 KB. Because the default block size for .VHDx files is 32 MB, writing one 512 byte sector will result in a 32 MB section of the sparse file being allocated. When ext3 is allocating the MBR, the super block, the backup super blocks,
inodes, directories, etc., space is being allocated in the sparse file. Because of ext3’s suboptimal IO, how the data structures are laid out on disk, and the default block size, a large partition of the .VHDx file is allocated just by formatting. The workaround is to create a .VHDx file with a 1 MB block size rather than the default 32 MB.

Changing the block size in the UI is not implemented. It can
only be changed when the VHDx file is created through Powershell.