itblog.team-holm.net
Hyper-V


Centos 7 Template checklist for SCVMM 2012R2

Getting Centos 7 template ready in SCVMM 2012 R2

-2nd of April 2015

In this blog article, we will list the steps needed to be done inside a Centos 7 OS to make it a VM ready to be a template in SCVMM 2012R2. The article describes a VM template setup intended for a environment using SpaceWalk for patching as a centralized solution. If your enviroment does not use SpaceWalk, you might consider using it or take whatever ideas from this article to use in your system. In case that is not preferred, feel free to not include the steps that you are not in need of including.

Naming:
First off, the Template host name will be CENTOS64, this is due to the scripts that we will use later for initializing the new virtual machine when it boots. The scripts check among other things that the hostname has been changed from the initial template hostname before they proceed. This hostname will change to the VM name when the VM is deployed from the template.

Getting started:
This guide assumes you are logged in as root or that you have sudo rights to act as root. After installing a minimal install of Centos 7, make sure the necessary packages needed for basic management and interaction with Hyper-V are set up. You might also need other tools for basic system management. Below is an example.
		yum install hyperv-daemons
		yum install python-pyasn1
		yum install wget telnet net-tools bind-utils curl lsof

Don't forget to update the system with the newest release patch releases:
		yum update

Installing virtualization specifics:
Also remember that the SCVMM agent needs to be installed on the virtual machine. It is needed for a successful deploy of a vm from the template. Make sure LIS works / is installed. This should be included in Centos 7 as a part of initial setup (perhaps not if you choose a minimal install of the OS?). See the links below on how to do this.
Set up the OS:
1. Set up the preferred colors for the shell:
		echo "export PS1=$'\\[\E[1m\E[31m\\]\\h:\\w # \\[\E(B\E[m\\]'" >> /root/.bashrc
		echo "export PS1=$'\\[\E[1m\E[32m\\]\\h:\\w # \\[\E(B\E[m\\]'" >> /etc/profile.d/colorprompt.sh
2. Make sure that root login is not permitted in /etc/ssh/sshd_config and that we are using Protocol 2.
3. Put the SpaceWalk Server name and IP into /etc/hosts:
		12.34.56.78   the-spacewalkserverhostname
4. Install the SpaceWalk client, but don't register it to a SpaceWalk server: 5. Create /etc/init.d/registerSpacewalk.sh as shown in the following link(can be linked to from /etc/rc.local to start at startup):
Change the text "the-spacewalkserver" in the script with the name you used in /etc/hosts for your SpaceWalk server. If you are using a deployment subnet, remember to enter it into the script. You don't want the SpaceWalk client to register with the SpaceWalk server in the wrong subnet. See below.
		$NETADDR =~ ^192\.168\.100\.[0-9] 
Will become the following if 10.12.228.0/24 is your deployment subnet:
		$NETADDR =~ ^10\.12\.228\.[0-9]
As explained, if the subnet used in the deployment VLAN is 10.12.228.0/24. This will ensure that the VM being deployed from the template won't register to the SpaceWalk server on boot if the VM is still in the deployment subnet. In this case of deployment setup, it is thought that the VM is set into a temporary deployment subnet automatically while scripts are running to talk to and customize the VM. If you have no such setup in your environment, you can remove the if structure regarding this check from the script.

When the script is created, make it runable and add it as a startup service:
		chmod +x /etc/init.d/registerSpacewalk.sh
		chkconfig --add registerSpacewalk.sh
Preferably you could create the script somewhere else, and add it to /etc/rc.local. This will make sure it will run after all other startup scripts have run, and you won't need to add it as a service as done above.

The script and this setup will make sure that the deployed VM from this template will register itself automatically to the given SpaceWalk server you specify. For this to happen, the VM must be able to talk to the SpaceWalk server over the network and resolve whatever name you use in the script via /etc/hosts.

Set up the yum repository config files:
Make sure all configuration files under /etc/yum.repos.d except the SpaceWalk configuration files have enabled=0 under every section within these. We don't want to use other repo's then our SpaceWalk repo.

Create a template cleanup script:
You will ned a script to clean up the OS and ready it for template deployment. For example place it under /root/make-template.sh. See below for the script code.
	#!/bin/bash

	rm -rf /etc/ssh/ssh_host*
	rm -rf /etc/udev/rules.d/70-persistent-net.rules
	rm -rf /etc/touchme
	#/root/compileProgressbar.sh

	#rm -rf /etc/sysconfig/network-scripts/ifcfg-eth0
	#TODO: Generate this file on boot with correct mac.

	chmod -x /root/make-template.sh

	/sbin/service rsyslog stop
	/sbin/service auditd stop

	/bin/package-cleanup --oldkernels --count=1

	/usr/bin/yum clean all

	/usr/sbin/logrotate -f /etc/logrotate.conf
	/bin/rm -f /var/log/*-???????? /var/log/*.gz
	/bin/rm -f /var/log/dmesg.old
	/bin/rm -rf /var/log/anaconda

	/bin/cat /dev/null > /var/log/audit/audit.log
	/bin/cat /dev/null > /var/log/wtmp
	/bin/cat /dev/null > /var/log/lastlog
	/bin/cat /dev/null > /var/log/grubby

	/bin/rm -f /etc/udev/rules.d/70*

	/bin/sed -i '/^(HWADDR|UUID)=/d' /etc/sysconfig/network-scripts/ifcfg-eth0

	/bin/rm -rf /tmp/*
	/bin/rm -rf /var/tmp/*

	/bin/rm -f /etc/ssh/*key*

	/bin/rm -f ~root/.bash_history
	unset HISTFILE

	/bin/rm -rf ~root/.ssh/
	/bin/rm -f ~root/anaconda-ks.cfg

	echo "Shutdown this virtual machine and convert it to template in Hyper-V."
Remember to make the script executable to be able to run it:
		chmod +x make-template.sh
This script should be run right before you turn off your VM to convert it to a template. Make sure that you clone your VM before you convert it, so that you have a working copy you can use. When all this is done, you convert the cloned VM to a template and import it into a VMM Library where it will be ready for deployment. The process on how to do this will not be described here, but can be found in various Microsoft technet documentation.


Source: SCVMM 2012 R2 and Linux experience

Tagged as: LinuxHyper-VHowTo

Getting started with Hyper-V for the VMWare Admin

Getting started with Hyper-V for the VMWare Admin

-16th of December 2014

Table of contents:

A. Getting started:


1. How to create a cluster with two or more Hyper-V hosts:
http://technet.microsoft.com/en-us/library/jj863389.aspx

Especially in this process: To add a disk in Available Storage to CSV(Cluster Shared Volumes):
http://technet.microsoft.com/library/jj612868

2. How to install VMM:
http://technet.microsoft.com/en-us/library/bb740755.aspx

3. How to setup WSUS for VMM:
http://technet.microsoft.com/en-us/library/gg675084.aspx

B. Nice to know:

1. How to search for a VM guest based on its IP or MAC address:
Get-Vm |Get-VirtualNetworkAdapter |Where {$_.IPv4Addresses -like "192.168.123*"} | Select Name, IPv4Addresses
Get-Vm |Get-VirtualNetworkAdapter |Where {$_.MACAddress -like "00:15:5D:*"} | Select Name, MACAddress
It seems not to be possible to search for VM guests based on theyr IP address ussing the graphical user interface in VMM.
And getting host names based on MAC address:
Get-VMHost | %{ get-scvmhostnetworkadapter -VMHost $_ | where-object {$_.PhysicalAddress -like "00:25:B5*" }} | Select VMHost, PhysicalAddress

2. How register an existing Hyper-V virtual machine on to a Hyper-V host:
				$VMHost = Get-SCVMHost -ComputerName "HyperVHostName"
				Register-SCVirtualMachine -VMHost $VMHost -Path "C:\ClusterStorage\MyVM"
It seems not to be possible to search for VM guests based on theyr IP address ussing the graphical user interface in VMM.

3. How to set the first boot device(here the CD-ROM) on Generation 2 VM guests:

From the following:


We will get this in PowerShell:
Set-SCVirtualMachine -VM "VMName" -FirstBootDevice "SCSI,0,1"
To set the first boot device to be a NIC using PXE boot:
Set-SCVirtualMachine -VM (Get-VM "VMName") -FirstBootDevice "NIC,0"
You can also start Cluster Manager -> Nodes -> choose VM and set boot device there. It is not possible to do this on Generation 2 virtual guests in the GUI via VMM. It is however possible on Generation 1 virtual guests(it has to be powered off, here it is powered on):



As a comparrison, a generation 2 virtual machine guest looks like this in the same menu area:



Please see: http://technet.microsoft.com/library/dn440675.aspx
"Because of underlying differences between generation 1 and generation 2 virtual machines, the startup order (boot order) for different devices (such as a hard disk or CD) is not handled the same way in the two generations. To customize the startup order for a generation 2 virtual machine in System Center 2012 R2, you must use a Windows PowerShell command that specifies the first boot device, rather than an ordered list of boot devices."

4. How to create NIC on VM and also set static IP-adress from a static IP-Pool defined in VMM:

			$VMNetwork = Get-SCVMNetwork -VMMServer vmmServerFQDN -Name "VLAN 127 Network" 
			$VMSubnet = Get-SCVMSubnet -VMMServer vmmServerFQDN -Name "VLAN 127 Network_Subnet"

			New-SCVirtualNetworkAdapter -VM "VMNameHere" -MACAddress "00:00:00:00:00:00" -MACAddressType Static `
			-Synthetic -EnableVMNetworkOptimization $false -EnableMACAddressSpoofing $false `
			-EnableGuestIPNetworkVirtualizationUpdates $false -IPv4AddressType Static -IPv6AddressType Dynamic `
			-VMSubnet $VMSubnet -VMNetwork $VMNetwork

			#Then choose either alternative 1 or alternative 2:
			#Alternative 1:
			$IPPool = Get-SCStaticIPAddressPool | where-object {$_.VMSubnet.name -eq $VMSubnet.Name}
			Grant-SCIPAddress -StaticIPAddressPool $IPPool -GrantToObjectType VirtualNetworkAdapter  `
			-GrantToObjectID ((Get-SCVirtualNetworkAdapter -VM "VMNameHere"))[0].ID
					
			#Alternative 2:
			$Adapter =(Get-SCVirtualNetworkAdapter -VM "VMNameHere" | where  {$_.VLanID -eq "127"})
			Set-SCVirtualNetworkAdapter -IPv4AddressType Static -VirtualNetworkAdapter $Adapter -IPv4Addresses "IPv4 Adresse Her" 
			#In alternative 2 VMM will automatically findthe IP pool for $VMNetwork if it exists
			

5. How to find addresses in a IP-Pool:
Find used/assigned addresses:
Get-SCIPAddress -Assigned -StaticIPAddressPool (Get-SCStaticIPAddressPool -Name "AddressPoolName")

Find all assigned addresses that are not in use any more:
Get-SCIPAddress -UnAssigned -StaticIPAddressPool (Get-SCStaticIPAddressPool -Name "AddressPoolName")

Unassigne all IP's from a IP-pool:
Revoke-SCIPAddress -AllocatedIPAddress (Get-SCIPAddress -Assigned -StaticIPAddressPool (Get-SCStaticIPAddressPool -Name "IP Pool Name"))

6. How to get the fillingdegree on a datastore:



The same thing can also be done in Failover Cluster Manager:



7. How to find what VM's are running on a datastore:
Get-Cluster "ClusterName" | Get-ClusterNode | Foreach {Get-VM -ComputerName $_.Name | Where {$_.Path -match "Volume1"}}

8. How to find orphaned disks:
Paste the following into a ps1 file and run it after switching "ClusterNameHere" with the correct name of the cluster.
			[CmdletBinding(ConfirmImpact='High',SupportsShouldProcess=$true)]
			PARAM (
				   [string]$ClusterName = "ClusterNameHere",
				   [string]$LocalClusterStoragePath = "C:\\ClusterStorage",
				   [string]$ClusterStorageUNCTail = "C$\ClusterStorage",
				   [string[]]$Extensions = @( '*.vhdx', '*.vhd', '*.iso' )
			)

			BEGIN {
				   #Get all disks registered in Hyper-V:
				   if ($host.Name -eq "ConsoleHost") {Write-Host -Foregroundcolor Yellow "Using the following parameters: "}
				   $baseHost = (get-VMHostGroup | % {$_.AllChildClusters | where-object {$_.ClusterName -eq $ClusterName}  `
				   		| get-vmhost})[0];
				   if ($host.Name -eq "ConsoleHost") {Write-Host -Foregroundcolor Yellow "   baseHost: $baseHost"}
				   $baseHostname = $baseHost.Name.Split(".")[0];
				   if ($host.Name -eq "ConsoleHost") {Write-Host -Foregroundcolor Yellow "   baseHostname: $baseHostname"}
				   $baseCluster = (get-VMHostGroup | % {$_.AllChildClusters | where-object {$_.ClusterName -eq $ClusterName}});
				   if ($host.Name -eq "ConsoleHost") {Write-Host -Foregroundcolor Yellow "   baseCluster: $baseCluster"}
				   $uncBase = [string]$("\\"+$baseHostname+"\"+$ClusterStorageUNCTail); 
				   if ($host.Name -eq "ConsoleHost") {Write-Host -Foregroundcolor Yellow "   uncBase: $uncBase"}
				   $disks = $baseCluster | get-vmhost | Get-Vm | `
				   Foreach-Object {$_.virtualdiskdrives | % {[String]($_.VirtualHardDisk.Location) `
				      -replace $LocalClusterStoragePath, $uncBase}}
				   
				   $List = @($Extensions | ForEach-Object {
						 $extension = $_;
						 if ($host.Name -eq "ConsoleHost") {Write-Host -Foregroundcolor Yellow "- Filtering extension: $extension"}
						 dir -Path $uncBase | % {
								dir -Path $uncBase\$_ | %{
									   dir -Path $($uncBase+"\"+($_).Parent.Name+"\"+$_) -Filter $extension | `
									   		Select-Object -ExpandProperty FullName                             
								}
						 }
				   }) | Where-Object { 
						 $_ -notin $disks 
				   } | Select-Object -Unique
				   if ($host.Name -eq "ConsoleHost") {Write-Host -Foregroundcolor Yellow $("`n**Found " + $List.count + " files..")}
				   $List
			}
			

9. Hyper-V equivalents to SDRS and DRS in VMWare:
Distributed Resource Scheduler in VMWare os "Dynamic Optimization" in System Center Virtual Machine Manager 2012 R2.
Choose the fabric pane in VMM and right click the site where yoiu want to adjust the settings, and choose properties.



10. Access rights in VMM:
Requires to create a Tenant Administrator or Application Administrator in a Private Cloud.

1. Settings -> Create User Role:



2. Attach the role to a Private Cloud and delegate what objects can be administrated.



11. Hyper-V vs VMWare vSphere:
Drawbacks with Hyper-V compared to VMWare vSphere:
  • It is not possible to list what virtual machines are on a storage device via the GUI.
  • A virtual guest has to be powered off so that a NIC can be added to it.
  • The IP-addresses of the hosts are not shown in VMM. Powershell has to be used.
  • The handeling of access rights is not as granulated and straight forward to handle as in VMWare.
  • VMWare vSphere has more GUI options for doing various administrative tasks easily.
  • Hyper-V and SCVMM do not have a full equivalent to VMware's Storage DRS.
  • Live migrations of storage in SCVMM seems to way too often not to be able to clean up after itself, resulting in orphaned files.

  • Benefits with Hyper-V in regards to VMWare:
  • Licenses and costs
  • Hyper-V has a practical networking model(see 'System Center VMM Networking' below)

  • 12. More on Hyper-V and VMM:


    Source: System Center Virtual Machine Manager 2012 R2

    Tagged as: Hyper-VHowToScripts

    Main page
    Security
    Crypto
    Microsoft
    Linux
    Scripts
    VMWare Hyper-V
    Taglist
    Active Directory
    Citrix
    Commands
    Cryptography
    Hyper-V
    Linux
    Network
    Scripts
    SQL 2008
    SQL 2016
    Tools
    VMWare
    Games
    HowTo
    Routers