In light of “Microsoft loves Linux” initiative, you can now deploy your Linux virtual machines by using templates in the System Center 2016: Virtual Machine Manager. As I was searching on how to do this (successfully), there were couple of articles that helped, so I’ve decided to do a short list of all the necessary steps (in one place).
Steps to make your Linux VM template deployments work:
- create a new (Generation 2) virtual machine (as you would normally do)
- install the Linux operating system in that virtual machine (as you would normally do)
- HINT: A list of supported Linux distributions and versions on Hyper-V is available here.
- install the Linux Integration Services (LIS) (as per this post):
- open the “modules” file
1sudo nano /etc/initramfs-tools/modules - add the following to the end of this file:
1234hv_vmbushv_storvschv_blkvschv_netvsc
- open the “modules” file
-
- save it (Ctrl+X and Y)
- install LIS and reboot the machine by using the following commands:
123sudo apt-get install --install-recommends linux-tools-virtual-lts-xenial linux-cloud-tools-virtual-lts-xenialsudo update-initramfs -usudo reboot - check if the services are running by using the command:
1sudo lsmod
- install the Virtual Machine Manager agent (as per this post):
- share the folder C:\Program Files\Microsoft System Center 2016\Agents\Linux on your VMM machine
- copy the VMM agent files to Linux virtual machine
- as a real Windows admin, I did it through the GUI
- install the agent:
1sudo ./install scvmmguestagent.1.0.2.1075.x64.tar
- fix the boot for Generation 2 virtual machine (boot information is by default stored in the VM configuration file, not on disk – Ben wrote a great article on this “issue”)
- Ben’s way (didn’t work for me):
- change directory to the boot EFI directory
1sudo cd /boot/efi/EFI - copy the ubuntu directory in to a new directory named boot
1sudo cp -r ubuntu/ boot - change directory to the newly created boot directory
1sudo cd boot - rename the shimx64.efi file
1sudo mv shimx64.efi bootx64.efi
- change directory to the boot EFI directory
- TriJetScud’s way in the comments (worked for me with Ubuntu 16.04 Generation 2 VM):
1sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --no-nvram --removable
- Ben’s way (didn’t work for me):
- shutdown the virtual machine and copy its VHDX to the VMM Library
- HINT: Don’t forget to refresh the VMM Library.
- go to the VMM Library, right-click the copied VHDX and select the Create VM template option
- proceed with creating the template as you normally would, to the part Configure Operating System
- HINT: If you are using Secure boot, don’t forget to select the MicrosoftUEFICertificateAuthority template in hardware settings.
- there, under Guest OS profile, you select the option to create a new Linux operating system customization settings
- next you specify your guest OS settings and finish creating the template
- now you can create a new Linux virtual machine from the template you’ve configured!
Hope it helps!
Cheers!