Best Practices for running Linux on Hyper-V

More performance, higher security and better stability Best Practices for running Linux on Hyper-V

Many companies put in parallel to Windows servers, and Linux. Also, such systems can be optimally under Hyper-V and provide an improvement in performance, higher security and more stability. We show that the implementation must be respected.


Linux is one of many companies to the infrastructure landscape is easy. With a little Know-how and also the Open-Source Server to Hyper-V, but can operate.
Linux is one of many companies to the infrastructure landscape is easy. With a little Know-how and also the Open-Source Server to Hyper-V, but can operate.

(Image: © deagreez –

Linux in the data centers of many companies simply. Microsoft has opened up more and more in the direction of Linux and provides also opportunities for optimization.

Generally speaking, as the latest Linux Kernel should be used, since it is constantly on improvements in the cooperation with Hyper-V integrated. Older versions than 2.6.37, for example, support no NUMA on Hyper-V.

Pictures gallery

Pictures gallery with 6 pictures

In addition, attention must be paid prior to the Installation of Linux on Hyper-V to ensure that the appropriate Distribution and Version works with Hyper-V. The Windows Server Version plays an important role. Officially CentOS is supported starting with Version 8, Fedora and Debian also, starting with Version 8.

Other distributions like Arch Linux and Manjaro Linux are not officially supported. Best compatible Linux distributions, working together with Windows Server 2019. Here, for example, also supports security features such as Shielded VMs with Linux.

Dynamically expanding disks

In many cases, the virtualization with Hyper-V on a dynamically expanding disks with the needs of the virtual operating systems to grow. Depending on your Linux Distribution and the file system settings in Linux, the virtual operating system a little lavish with this feature and requires additional storage space, although this is not yet occupied.

Microsoft recommends in this regard that the block size is set for the virtual hard disk to 1 MB. It is Ideal to create the dynamic disk in PowerShell before Creating the Linux VM, for example:

New-VHD -Path d:vmubuntutest.vhdx -size bytes 127GB Dynamic block size bytes, 1MB

Within the VM, Microsoft recommends in Linux using ext4 as the file system and does not recommend ext3. This is because ext4 is better with dynamic disks to cope. Here, Microsoft recommends that you set the value of Groups to 4096, for example:

mkfs.ext4 -G 4096 /dev/sdX1

In the Linux Kernel I/O Scheduler are available. Often blk or blk-mq comes as a Subsystem to use. Who decides which is the Scheduler can be used. For “blk” is the “noop”Scheduler is better for Hyper-V, in the use of the “blk-mq is” suitable “none” better. It is in Linux is also possible to use different hard drives different Scheduler.

In the article “10 pitfalls in the use of Hyper-V”, we have already dealt with the subject. Below, we will deepen the hints and tips for a better operation of Linux in conjunction with Hyper-V.

Generally speaking, however, it is not a good idea to reduce the size of virtual hard disks can be integrated in Linux, or to zoom in on, if there is already data stored on the disk. There is a risk of data loss here.

Generation 2 VMs use

Generally, it is recommend the use of Linux with Generation 2 VMs with UEFI, Secure to work the boat and the para-virtualized SCSI controllers. However, here, too, the Linux Distribution must be in the same position.

When you use Generation 2 VMs and Secure Boot, the template must be created supported and functioning. The configuration can be found in the settings of the VM in “security”. The Distribution does not support the function, and therefore, don’t start, it is necessary, the Option “Secure boot enable” to disable “security”.

Grub and Generation 2 VMs

If Generation 2 VMs are used, it may happen that the boot Manager Grub displays the entries, because the default operating system is started quickly. Here it may be useful to increase the Timeout for the menu from 4 to a value of about 100,000, and the menu is long enough to see.

If the Dump-Capture-crashing the Kernel at boot time should be allocated more memory for the Kernel. For this purpose, the Parameter can be “crash kernel=384M-:128M“to “crash kernel=384M-:256M“ in the Ubuntu Grub configuration file to be modified.

Increase performance by installing the VM Tools

In order to improve the performance of VMs with Linux on Hyper-V, you should install the respective VM-Tools. On the example of the operation of the Kali Linux which is carried out with the following command:

git clone chmod 555 linux-vm-tools/kali/2020.x/ sudo linux-vm-tools/kali/2020.x/

Generally speaking, it may be appropriate to set the Option “HVSocket” if you have your own integration services. This process can be done in PowerShell on the Hyper-V Host:

Set-VM “<Name of the VM>” enhanced session transport type HVSocket

When using Ubuntu, the extensions can be installed from the package Manager, for example:

apt-get update
apt-get install –install-recommends linux-virtual
apt-get install linux-tools-virtual linux-cloud-tools-virtual
reboot now

Usually, what is needed here, nor “sudo”. Microsoft provides for various Linux distributions, the Linux Integration Services are available for Download This should be installed on the supported distributions.

When Creating VMs, number of processors and memory can be adjusted. Generally speaking, 2 CPUs are recommended. In the case of performance problems can be tested, whether the Change to a processor brings a improvement.

In principle, current, supported Linux distributions can cope with dynamic memory. These settings should be for Linux. Here it may be useful to experiment with the settings to get the best performance.

We give tips for optimal virtualization with Hyper-V.