Skip to content
This repository

Retrieve the FreeBSD code with the HyperV drivers from github

# cd /usr
# git clone

Build the Kernel

# cd /usr/freebsd
# make buildkernel KERNCONF=HYPERV_VM 

Install the kernel

# make installkernel KERNCONF=HYPERV_VM

If you built the kernel with the default HYPERV_VM makefile, the drivers will be included in the kernel image. To check if the modules are present, use the strings command and look for HyperV related symbols:

# strings /boot/kernel/kernel | grep hv_

If you built the kernel with the default makefile, the boot will fail with a ROOT MOUNT ERROR. This is due to FreeBSD using the Fast IDE driver also being integrated into the kernel image. There are two ways around this.

Alternative 1 – Disable Fast IDE driver at the start time

  1. Boot the system.
  2. On FreeBSD boot menu, select 6. Escape to loader prompt.
  3. At the boot loader prompt, enter the following command:
    a. set hw.ata.disk_enable=1
    b. boot
    Note: Step 3.a just disables the Fast IDE driver and use the ATA driver to take control of any IDE. The system should be started without Fast IDE support.

Alternative 2 – Manual configurations needed prior to install a kernel with Storvsc Fast IDE support

  • Reboot the system into single user mode. This can be accomplished by selecting boot menu option 4, or performing a ‘boot -s’ from the boot prompt. Alternatively, you can boot a specific kernel by specifying “boot -s”. Note the ordering of the last command.

  • In Single user mode, create GEOM labels for each of the IDE disk partitions listed in your fstab (both root and swap) - see also FreeBSD Labeled Filesystems. For example:

# cat /etc/fstab
# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/ad0s1b             none            swap    sw              0       0
/dev/ad0s1a             /               ufs     rw              1       1
/dev/acd0               /cdrom          cd9660  ro,noauto       0       0
# glabel label rootfs /dev/ad0s1a
# glabel label swap /dev/ad0s1b
# glabel status
Name  Status  Components
rootfs N/A    ad0s1a
swap   N/A    ad0s1b

Additional information on GEOM labels can be found at:

Reboot into multiuser mode (default). Edit your /etc/fstab to include the labels. For example:

# Device           Mountpoint  FStype   Options     Dump  Pass#
/dev/label/swap    none        swap     sw          0     0
/dev/label/rootfs  /           ufs      rw          1     1
/dev/acd0          /cdrom      cd9660   ro,noauto   0     0

The virtual machine is now ready for testing.

The steps above is to build the kernel with default configurations, however, in the real world, we need to modify the configuration file, i.e. HYPERV_VM to build a customized kernel. One of recommended changes is to comment out the line of makeoptions, which will do a full build. The default configuration file only includes the ones for Hyper-V, while most of the support modules are removed.

# $FreeBSD$
include       GENERIC
ident         HV_VMBUS

#makeoptions  MODULES_OVERRIDE=""

# Adaptive locks rely on a lock-free pointer read to determine the run state
# of the thread holding a lock when under contention; under a virtualisation
# system, the thread run state may not accurately reflect whether the thread
# (or rather its host VCPU) is actually executing.  As such, disable this
# optimisation.
Something went wrong with that request. Please try again.