Gentoo Linux: Hyper-V R2 Enlightenment

If you ever worked with Hyper-V on Windows 2008 R2 you might know the Linux support is still an issue compared to other hypervisors like VMware. In the meantime Microsoft official supports SLES and RHEL as Hyper-V R2 guests. To have them running smoothly, you should install the Linux Integration Services Version 3.1 for Hyper-V on each Linux VM.

I spend some time to get Integration Services running on Gentoo Linux. The nice thing is, that with the release of Linux Kernel 3.0 and later the source of the Integration Services have been integrated into the kernels staging directory /usr/src/linux/drivers/staging/hv which is useful if you want to avoid external code.



Installing Gentoo Linux as a new VM

  • Create a new virtual machine on Hyper-V
  • Create an IDE HDD as installation target as the SCSI adapter does not work without the Linux Integration Services drivers
  • Replace the Network adapter with the Legacy Network adapter to have working LAN connectivity
  • Perform a regular installation of Gentoo Linux and boot into the new system
  • Create a Hyper-V snapshot as a valid restoration point

Installation and configuration of Linux Kernel 3.1

  • The first step is to unmask unstable kernel versions in portage
rawhide ~ # nano -w /etc/portage/package.keywords
sys-kernel/gentoo-sources ~amd64
  • Mask all kernel version earlier then 3.1 just to be sure
rawhide ~ # nano -w /etc/portage/package.mask
<=sys-kernel/gentoo-sources-3.1
  • You can use my kernel config as a starting point if you like. I’ve removed most of the useless stuff.
rawhide ~ # cd /etc/kernels
rawhide kernels # wget http://www.syncer.de/wp-content/uploads/2011/11/kernel-config-x86_64-3.1.0-gentoo
  • It is necessary to have the following in the config:
rawhide kernels # cat /etc/kernels/kernel-config-x86_64-3.1.0-gentoo
[...]
CONFIG_ATA=m
CONFIG_ATA_GENERIC=m
CONFIG_ATA_PIIX=m
CONFIG_HID_SUPPORT=y
CONFIG_HID=m
CONFIG_CONNECTOR=y
CONFIG_HYPERV=m
CONFIG_HYPERV_STORAGE=m
CONFIG_HYPERV_BLOCK=m
CONFIG_HYPERV_NET=m
CONFIG_HYPERV_UTILS=m
CONFIG_HYPERV_MOUSE=m
[...]
  • Let Genkernel do the job, just make sure the kernel config is valid for your setup
rawhide kernels # genkernel --all-ramdisk-modules --menuconfig --symlink --lvm all
  • You might want to adjust the GRUB configuration to have a valid fallback

Modify the initrd to load the hv_* modules

  • Now a small modifcation in the initramfs image is necessary to load the hv_* modules
  • Make sure /boot is mounted, in most of the cases Genkernel will do this for you
  • Adjust the initramfs name as neccesary
rawhide ~ # mkdir /tmp/initrd
rawhide ~ # cd /tmp/initrd
rawhide initrd # zcat /boot/initramfs-genkernel-x86_64-3.1.0-gentoo | cpio -i
rawhide initrd # cd /tmp
rawhide tmp # wget http://www.syncer.de/wp-content/uploads/2011/11/initrd_hv.patch
rawhide tmp # patch -p0 < initrd_hv.patch
rawhide tmp # cd /tmp/initrd
rawhide initrd # find . | cpio -H newc -o | gzip -9 > /boot/initramfs-genkernel-x86_64-3.1.0-gentoo

Build and enable the hv_kvp_daemon

  • The hv_kvp_daemon is also included in the hv staging directory
  • Building and installing the daemon is quite simple
rawhide ~ # cd /usr/src/linux/drivers/staging/hv/tools
rawhide tools # gcc hv_kvp_daemon.c -o hv_kvp_daemon
rawhide tools # strip hv_kvp_daemon
rawhide tools # install -o root -g root -m 0750 /usr/src/linux/drivers/staging/hv/tools/hv_kvp_daemon /usr/sbin/hv_kvp_daemon
  • I’ve prepared a simple runscript that will handle daemon start and stop
rawhide ~ # cd /etc/init.d
rawhide init.d # wget http://www.syncer.de/wp-content/uploads/2011/11/hv_kvp_daemon
rawhide init.d # chmod 0755 /etc/init.d/hv_kvp_daemon
rawhide init.d # rc-update add hv_kvp_daemon default

Additional considerations
With the modified initramfs in place you can easily replace the IDE with a SCSI HDD or replace the Legacy network adapter with the regular one. As I’m not a big fan of X11, I spend no time on getting hv_mouse.ko working. Modprobing the module caused a little trouble so it has been excluded from my configuration. Your questions and feedback are welcome.
 

Leave a Reply