[OpenWrt-Devel] Hyper-V Support for X86 or X86_64

Ning Ye ning at oaklight.us
Sun Jul 27 18:37:27 EDT 2014


Hi All,

Hyper-V support for X86 or X86_64 were noticeably  missing.  There is a previous patch for Kernel 3.3 but never maintained or merged into trunk.  Here's my take on adding the Hyper-V support for the current kernel.  No new sub targets or profiles are created, as long as the target is x86 or x86_64.  The generic works well or any other profiles.  

Also added a new VHD target image menu .  The latest stable qemu-img supports Hyper-V vhd and vhdx.  The old & current qemu 0.14.1 builds invalid vhd images.  I am working on updating it to 2.0.0.  Currently I am converting vmdk into vhd using third party tools.

Ning Ye
Signed-off-by: Ning Ye <ning at oaklight.us> 

------------
diff --git a/config/Config-images.in b/config/Config-images.in
old mode 100644
new mode 100755
index 39e51e4..7020f84
--- a/config/Config-images.in
+++ b/config/Config-images.in
@@ -239,6 +239,16 @@ menu "Target Images"
 		select TARGET_IMAGES_PAD
 		select PACKAGE_kmod-e1000
 
+	config VHD_IMAGES
+		bool "Build Hyper-V image files (VHD)"
+		depends on TARGET_x86 || TARGET_x86_64
+		select GRUB_IMAGES
+		select TARGET_IMAGES_PAD
+		select PACKAGE_kmod-hyperv-balloon
+		select PACKAGE_kmod-hyperv-net-vsc
+		select PACKAGE_kmod-hyperv-util
+		select PACKAGE_kmod-hyperv-storage
+
 	config TARGET_IMAGES_PAD
 		bool "Pad images to filesystem size (for JFFS2)"
 		depends on OLPC_BOOTSCRIPT_IMAGES || GRUB_IMAGES
diff --git a/package/kernel/linux/modules/virtual.mk b/package/kernel/linux/modules/virtual.mk
old mode 100644
new mode 100755
index 190d844..a67d71c
--- a/package/kernel/linux/modules/virtual.mk
+++ b/package/kernel/linux/modules/virtual.mk
@@ -186,3 +186,85 @@ define KernelPackage/xen-pcidev/description
 endef
 
 $(eval $(call KernelPackage,xen-pcidev))
+
+#
+# Hyper-V Drives depends on x86 or x86_64.
+#
+define KernelPackage/hyperv-balloon
+  SUBMENU:=$(VIRTUAL_MENU)
+  DEPENDS:=@(TARGET_x86||TARGET_x86_64)
+  TITLE:=Microsoft Hyper-V Balloon Driver
+  KCONFIG:= \
+    CONFIG_HYPERV_BALLOON \
+    CONFIG_HYPERVISOR_GUEST=y \
+    CONFIG_PARAVIRT=n \
+    CONFIG_HYPERV=y
+  FILES:=$(LINUX_DIR)/drivers/hv/hv_balloon.ko
+  AUTOLOAD:=$(call AutoLoad,06,hv_balloon)
+endef
+
+define KernelPackage/hyperv-balloon/description
+  Microsofot Hyper-V balloon driver.
+endef
+
+$(eval $(call KernelPackage,hyperv-balloon))
+
+define KernelPackage/hyperv-net-vsc
+  SUBMENU:=$(VIRTUAL_MENU)
+  DEPENDS:=@(TARGET_x86||TARGET_x86_64)
+  TITLE:=Microsoft Hyper-V Network Driver
+  KCONFIG:= \
+    CONFIG_HYPERV_NET \
+    CONFIG_HYPERVISOR_GUEST=y \
+    CONFIG_PARAVIRT=n \
+    CONFIG_HYPERV=y
+  FILES:=$(LINUX_DIR)/drivers/net/hyperv/hv_netvsc.ko
+  AUTOLOAD:=$(call AutoLoad,35,hv_netvsc)
+endef
+
+define KernelPackage/hyperv-net-vsc/description
+  Microsoft Hyper-V Network Driver
+endef
+
+$(eval $(call KernelPackage,hyperv-net-vsc))
+
+define KernelPackage/hyperv-util
+  SUBMENU:=$(VIRTUAL_MENU)
+  DEPENDS:=@(TARGET_x86||TARGET_x86_64)
+  TITLE:=Microsoft Hyper-V Utility Driver
+  KCONFIG:= \
+    CONFIG_HYPERV_UTILS \
+    CONFIG_HYPERVISOR_GUEST=y \
+    CONFIG_PARAVIRT=n \
+    CONFIG_HYPERV=y
+  FILES:=$(LINUX_DIR)/drivers/hv/hv_util.ko
+  AUTOLOAD:=$(call AutoLoad,10,hv_util)
+endef
+
+define KernelPackage/hyperv-util/description
+  Microsoft Hyper-V Utility Driver
+endef
+
+$(eval $(call KernelPackage,hyperv-util))
+
+#
+# Hyper-V Storage Drive needs to be in kernel rather than module to load the root fs.
+#
+define KernelPackage/hyperv-storage
+  SUBMENU:=$(VIRTUAL_MENU)
+  DEPENDS:=@(TARGET_x86||TARGET_x86_64) +kmod-scsi-core
+  TITLE:=Microsoft Hyper-V Storage Driver
+  KCONFIG:= \
+    CONFIG_HYPERV_STORAGE=y \
+    CONFIG_HYPERVISOR_GUEST=y \
+    CONFIG_PARAVIRT=n \
+    CONFIG_HYPERV=y 
+  FILES:=$(LINUX_DIR)/drivers/scsi/hv_storvsc.ko
+  AUTOLOAD:=$(call AutoLoad,40,hv_storvsc)
+endef
+
+define KernelPackage/hyperv-storage/description
+  Microsoft Hyper-V Storage Driver
+endef
+
+$(eval $(call KernelPackage,hyperv-storage))
diff --git a/target/linux/x86/config-3.10 b/target/linux/x86/config-3.10
old mode 100644
new mode 100755
index 69f2f08..3fa6344
--- a/target/linux/x86/config-3.10
+++ b/target/linux/x86/config-3.10
@@ -193,6 +193,14 @@ CONFIG_HW_RANDOM=y
 CONFIG_HW_RANDOM_GEODE=y
 CONFIG_HW_RANDOM_VIA=y
 # CONFIG_HYPERVISOR_GUEST is not set
+# CONFIG_HYPERV is not set
+# CONFIG_HYPERV_BALLOON is not set
+# CONFIG_HYPERV_NET is not set
+# CONFIG_HYPERV_STORAGE is not set
+# CONFIG_HYPERV_UTILS is not set
+# CONFIG_FB_HYPERV is not set
+# CONFIG_HID_HYPERV_MOUSE is not set
+# CONFIG_VMWARE_BALLOON is not set
 CONFIG_HZ_PERIODIC=y
 CONFIG_I8253_LOCK=y
 # CONFIG_I8K is not set
diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
old mode 100644
new mode 100755
index 5983718..80ef5cf
--- a/target/linux/x86/image/Makefile
+++ b/target/linux/x86/image/Makefile
@@ -178,6 +178,15 @@ ifneq ($(CONFIG_VMDK_IMAGES),)
   endef
 endif
 
+ifneq ($(CONFIG_VHD_IMAGES),)
+  define Image/Build/vhd
+	rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vhd || true
+	qemu-img convert -f raw -O vpc \
+		$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
+		$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vhd
+  endef
+endif
+
 define Image/Build/gzip
 	gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
 	gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
@@ -252,6 +261,7 @@ define Image/Build
 	$(call Image/Build/grub2,$(1))
 	$(call Image/Build/vdi,$(1))
 	$(call Image/Build/vmdk,$(1))
+	$(call Image/Build/vhd,$(1))
 	$(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
   else
 	$(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
diff --git a/target/linux/x86_64/config-default b/target/linux/x86_64/config-default
old mode 100644
new mode 100755
index 48145be..865aa81
--- a/target/linux/x86_64/config-default
+++ b/target/linux/x86_64/config-default
@@ -258,6 +258,13 @@ CONFIG_HW_RANDOM=y
 CONFIG_HW_RANDOM_INTEL=y
 # CONFIG_HW_RANDOM_VIRTIO is not set
 CONFIG_HYPERVISOR_GUEST=y
+# CONFIG_HYPERV is not set
+# CONFIG_HYPERV_BALLOON is not set
+# CONFIG_HYPERV_NET is not set
+# CONFIG_HYPERV_STORAGE is not set
+# CONFIG_HYPERV_UTILS is not set
+# CONFIG_FB_HYPERV is not set
+# CONFIG_HID_HYPERV_MOUSE is not set
 CONFIG_HZ_PERIODIC=y
 # CONFIG_I7300_IDLE is not set
 CONFIG_I8253_LOCK=y
diff --git a/target/linux/x86_64/image/Makefile b/target/linux/x86_64/image/Makefile
old mode 100644
new mode 100755
index c2f1ce9..efa5fa9
--- a/target/linux/x86_64/image/Makefile
+++ b/target/linux/x86_64/image/Makefile
@@ -156,6 +156,16 @@ ifneq ($(CONFIG_VMDK_IMAGES),)
   endef
 endif
 
+ifneq ($(CONFIG_VHD_IMAGES),)
+  define Image/Build/vhd
+	rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vhd || true
+	qemu-img convert -f raw -O vpc \
+		$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
+		$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vhd
+  endef
+endif
+
+
 define Image/Build/gzip
 	gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
 	gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
@@ -199,6 +209,7 @@ define Image/Build
 	$(call Image/Build/grub2,$(1))
 	$(call Image/Build/vdi,$(1))
 	$(call Image/Build/vmdk,$(1))
+	$(call Image/Build/vhd,$(1))
 	$(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
   else
 	$(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list