How to Create Guest OS (Linux) Templates in Hyper-V

advertisement
How to Create Guest OS (Linux)
Templates in Hyper-V
Cloud OSS How to Create Guest
Hyper-V Service OS (Linux) Templates
Manager
in Hyper-V
Deploying Guest OS Master Images (VM Templates)
Introduction
This section provides information that will help you create Linux based guest OS templates in Microsoft
Hyper-V used by Interworks Cloud OSS Service Manager during VM provisioning.
To follow these instructions successfully you will need:


Administrative access to SCVMM Server (via SCVMM Console and permissions to the Library
Objects/Share Folders)
Adequate ISO images or CD/DVD discs containing the operating systems for the guest OS.
Downloading CentOS 6.5 and Oracle Linux 6.5 images
You can download the CentOS 6.5 ISO image from here. This link contains a number of mirrors with the
CentOS images.
For this guide we will be using the CentOS-6.5-x86_64-bin-DVD1.ISO image (not all mirrors contain this
ISO so you may need to check a couple of mirrors).
You can download the Oracle Linux 6.5 ISO image from here. You will need to register or sign-in with
your existing Oracle account in order to download the ISO.
The downloaded images will be in .GZIP format and you will first need to decompress them in order to
end up with, compatible with SCVMM images in .ISO format.
Later on, the uncompressed .ISO image will have to be uploaded to the SCVMM server where the
SCVMM console is hosted.
Creating a Virtual Machine
The first thing we need to do in order to deploy the template is to create a Virtual Machine and install the
CentOS 6.5 or Oracle Linux 6.5 Operating System. Once you have downloaded the ISO image you are
ready to create the Virtual Machine.
1) Log in to SCVMM server and open the SCVMM console. Next, click on Library tab.
Fig 1. SCVMM console Library
2) Right click on Library Servers and create a Library Server. Create a Library Share and name
it ISO or choose an alternative name that you prefer.
(You may skip this step if you already have a Library Server and Library Share configured in SCVMM)
Fig 2. Creating a Library Server and Library Share
3) Select the ISO Library Share and click on Import physical resource.
Fig 3. Viewing the contents of selected Library Share
4) Click on "Add resource..." in the appearing window.
Fig 4. Adding a resource to the Library
5) Navigate to the CentOS .ISO image that you have previously uploaded to SCVMM Server and click
on Open.
Fig 5. Adding .ISO image to the Library
6) Click on Browse to select the destination for the imported .ISO image.
Fig 6. Browsing for imported resource destination
7) Select the Destination Folder (Library Share) and click on OK.
Fig 7. Selecting imported resource destination
8) Click on Import.
Fig 8. Importing resource
9) Wait until the import process is finished and close the Jobs window that appears.
Fig 9. Running the import process
10) The ISO image should now appear in the folder selected in step 7.
Fig 10. Viewing the ISO image Library Share
11) You will now need to create a Virtual Machine (VM) using the uploaded image. On SCVMM
console click on VMs and Services.
Fig 11. VMs and Services
12) Click on Create Virtual Machine.
Fig 12. Creating a new VM
13) In the appearing window choose "Create the new virtual machine with a blank virtual hard
disk" and click on Next.
Fig 13. Creating a new virtual hard disk (VHD) for VM
14) Type in the Virtual machine name, choose Generation 1 and click on Next.
Fig 14. VM name and generation
15) Select "Cloud Capability Profiles"
Fig 15. Cloud Capability Profiles
16) Select Hyper-V.
Fig 16. Cloud Capability profiles (Hyper-V selection)
17) Set the minimum recommended resources for running a Guest OS Template VM (1 processor /
1024 MB Memory / 10 GB hard disk).
Fig 17. Setting CPU resources
Fig 18. Setting Memory resources
Fig 19. Setting Hard Disk resources
18) In Virtual DVD Drive choose "Existing ISO image" and browse for the uploaded .ISO image on the
Library Share.
Fig 20. Mounting the .ISO
image
19) Select the .ISO Image to be inserted in the Virtual DVD Drive and click OK.
Fig 21. Selecting .ISO
image
selected
Fig 22. The .ISO image is
20) Select Network Adapter 1 and click Remove. In the appearing window, click on Yes.
Fig 23. Remove Network Adapter
1
Removing Network Adapter
Fig 24.
21) Click New -> Legacy Network Adapter to add a Legacy Network Adapter to the VM template.
Fig 25. Adding a Legacy Network Adapter
22) Select Connect to a VM Network and the click Browse.
Fig 26. Connect Legacy Network Adapter to a VM Network
23) Select a VM Network and click OK.
Fig 27. Selecting VM Network
24) Once you finish with Hardware Configuration, click on Next.
Fig 28. Finishing Hardware Configuration
25) In the Select Destination tab, click on Next.
Fig 29. Select Destination Tab
26) Select the Hyper-V Host on which the VM will be created in and click on Next.
Fig 30. Choosing Hyper-V node for VM
27) In the Configure Settings tab, click on Next.
Fig 31. Choosing storage location
28) In the Add Properties tab, choose CentOS Linux 6 (64 bit) on the OS drop-down list and click
on Next.
Fig 32. Choosing an Operating System
29) Finally, click on Create in the Summary tab.
Fig 33. Settings confirmation and VM creation
30) Wait until the VM creation is completed and close the Jobs window.
Fig 34. VM creation in progress
31) As soon as the VM is created, it will be listed in SCVMM console as belonging to a Hyper-V Cluster
and/or a Hyper-V node.
Fig 35. New VM listed
32) Click on Power On to start the Virtual Machine. Notice that the status of the VM changes to "Starting"
and then "Running".
Fig 36. Start the New VM
Fig 37. VM is starting
Fig 38. VM is
running
33) Click Connect or View->Connect via Console in order to connect to the console.
Fig 39. Connect to VM via Console
34) Choose to "Install or upgrade an existing system"
Fig 40. CentOS initial installation screen
35) Choose whether to test or skip testing the media before installation and click on "Next" in the screen
that follows.
Fig 41. Install media test dialogue box
36) In the Welcome to CentOS page, click on Next.
Fig 42. Welcome to CentOS page
37) Choose your preferred Language and Keyboard layout. Once you choose, click on Next.
Fig 43. Preferred
language
44. Preferred keyboard layout
38) In the Type of Devices page, select "Basic Storage Devices" and click on Next. In the pop-up
window, click on "Yes, discard any data".
Fig
Fig 45. Installation
devices
46. Storage Device Warning
39) Enter the FQDN (Fully Qualified Domain Name) you want to use for this Virtual Machine.
Fig
Fig 47. Virtual Machine Template FQDN
40) Click on the "Configure Network" button and Edit the "System eth0" network interface. Configure
the IPv4 settings so that you can access the template at a later time.
Configure IPv4 settings you choose in the highlighted fields, as shown in the example below:
Fig 48. Network
configuration
49. System etho network settings
Fig
41) Select the appropriate time zone and click on "Next". In the following screen set a "root" password.
Fig 50. Time
settings
Fig 51. Setting root password
42) In the following screen select "Use All Space" and click on "Next". In the pop-up window, click on
"Write changes to disk".
Fig 52.
Partitioning
Fig 53. Write changes to disk
43) Choose installation type (Since this is going to be a server template, we choose the "Basic Server"
option). The installation process will begin once we click "Next".
Fig 54. Installation
type
55. Starting installation process
44) When the installation process is over click on "Reboot".
Fig
Fig 56. Rebooting upon successful installation
Preparing the Virtual Machine for Template
45) After the Reboot process is completed successfully, shutdown the Virtual Machine by logging in as
root with the password you entered during the installation and run the following command:

shutdown –h now
Fig 57. Shutting down the Virtual Machine
46) While the Virtual Machine is turned off, go to VMM console, right click on the VM and click on
Properties.
Fig 58. Setting VM's Properties
47) Go to Hardware Configuration, click on the "Legacy Network Adapter" and then click on Remove
in order to remove it. In the pop-up window click on Yes.
Fig 59. Removing Legacy Network Adapter
48) Click on New->Network Adapter in order to add a "Standard Network Adapter". Click on the
Adapter and select Connect to a VM Network, then click on OK.
Fig 60. Adding a Standard Network
Adapter
VM Network
Fig 61. Connect to a
49) Turn the Virtual Machine on and login as root. By default CentOS and Oracle Linux do not enable the
network adapter on startup. If you run the command "ifconfig" you will only find the loopback adapter
listed.
Fig 62. Running ifconfig
50) Also by default the first adapter will be eth0. However, if we attempt to enable it by using the "ifconfig
eth0 up" command we will receive a "no such device" error message as shown in the figure below:
Fig 63. Attempting to bring etho interface up
This is because eth0 is assigned to the legacy adapter we just removed. In order to fix this we need to
clear the existing adapter rules and update the configuration file for eth0.
51) First, we will be updating the configuration file for eth0. In order to do this, we run the following
commands:


cd /etc/sysconfig/network-scripts/
nano ifcfg-eth0
We should receive a screen similar to the one below:
Fig 64. Updating config file for eth0
52) From the config file, remove the line that starts with HWADDR and set the value for
BOOTPROTO=static. Press Ctrl-X + Y + Enter, in order to exit and save your changes.
Fig 65. Updated config
file
Updated config file is saved
Fig 66.
53) Run the following commands in order to remove the network rules and reboot the Virtual Machine:
o
o
rm /etc/udev/rules.d/70-persistent-net.rules –f
shutdown –r now
Fig 67. Removing Network Rules and Rebooting the VM
54) After rebooting, run the "ifconfig" command to verify that network is set to eth0 and an IP address is
configured.
Fig 68. Verifying eth0 proper state and configuration
You may also ping a public website in order to confirm Internet connectivity. You can now go on with the
required installation/configuration of the Virtual Machine in order to prepare it for a template.
55) Hyper-V backup essentials have to be added so that the Virtual Machine will be able to support Live
Backup. In order to do this, run the following commands:
o
o
curl –L –o
backupessentials.tar.gz https://github.com/LIS/backupessentials/tarball/1.0
tar –xvzf backupessentials.tar.gz
Fig 69a. Adding backup essentials to the VM
o
o
o
o
cd LIS-backupessentials-4e3121f/hv/hv-rhel6.5/rpm/
chmod +x install.sh
./install.sh
Reboot
Fig 69b. Adding backup essentials to the VM
56) Install the key/value pair (KVP) infrastructure, by running the following command:

o
yum install hypervkvpd
When the "Is this ok" pops up, click "y".
Fig 70a. Installing
KVP
70b. Installation of KVP is complete
Fig
Accordingly install libvirtwhich is the API that HypervISOr's layer uses ??? what is this ????, by running
the following command (when the "Is this ok" question pops up, click "y"):
o
yum install libvirt
Fig 70c. Installation of libvirt is complete
57) Download the Hard disk extend scripts on your Workstation from here. Unrar the file and extract
scripts at the destination of your preference.
Fig 71. Downloading the Hard disk extend scripts
58) .Run the WinSCP or any other SCP client tool. Browse to the destination where you saved rc.local
file on your Workstation. Select the file and click on Upload.
Fig 72a. Open
WinSCP
Fig 72b. Uploading rc.local file
59) Copy and overwrite the rc.local file from the CloudWorks-Linux-ExtendScripts folder to the /etc/
directory on the Linux Operating System. At thethe Upload pop-up window, type "/etc/" in the remote
directory field and click on OK. On the Confirm pop up window click on Yes.
Fig 73a. Copying
rc.local
Fig 73b. Overwriting rc.local
60) Grant executable permissions to the new rc.local file by running the following command:
o
chmod +x /etc/rc.local
Fig 74. Granting executable permissions to rc.local
61) Copy the disk_extend_script1.sh and the disk_extend_script2.sh under the /etc/rc.d/init.d/ directory of
the Linux Operating System and grant executable permissions to the scripts byusing the following
commands:
o
o
chmod +x /etc/rc.d/init.d/disk_extend_script1.sh
chmod +x /etc/rc.d/init.d/disk_extend_script2.sh
Fig 75a. Upload the disk extend
scripts
extend files to /etc/rc.d/init.d/
Fig 75b. Copying the disk
Fig 75c. Granting executable permissions to the disk extend scripts
62) Remove the wtmp reboot counter with the following command:
o
rm –rf /var/log/wtmp
Fig 76. Removing wtmp reboot coonter
Note: If you don't remove this log, there might be an issue with the Disk Extend feature
63) Add the SCVMM Guest Agent. You can find the SCVMM Agent inside your SCVMM Server under
the folder C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\agents\ .
You have to find the scvmmguestagent.1.0.2.1014.x64.tar and the install.sh. Copy them on your
Virtual Machine with the WinSCP client tool and install them by using the following commands:
o
o
o
cd /the/directory/you/copy/the/agent/and/the/shell/script
chmod +x install.sh
./install.sh scvmmguestagent.1.0.2.1014.x64.tar
Fig 77a. Adding SCVMM Guest Agent to
VM
Fig 77b. SCVMM Guest Agent
successfully installed
64) The last step before creating the template is to clear network rules once more so that the new adapter
from the Cloud OSS provisioning platform will be added as eth0. In order to do this, run the following
command:
o
rm /etc/udev/rules.d/70-persistent-net.rules –f
Fig 78. Clearing network rules
65) Shutdown the Virtual Machine by running the following command:

o
shutdown –h now
Fig 79. Shutting down VM
Creating the Template
66) In SCVMM console right click on the CentOS-6.5-for-Template VM and choose Create > Clone.
Fig 80. Creating a clone VM
67) In the Identity tab, Specify machine name for this VM clone and click on "Next".
Fig 81. Specifying clone machine name
68) In the Configure Hardware tab click on Availability below Advanced and check the "Make this
Virtual Machine High Available" option. Click on Next
Fig 82. Turning on high availability
69) In the Select Destination tab, select "Place the virtual machine on a Host" and choose your host
cluster or standalone server. Click Next.
Fig 83. Placing the VM on a
host
Selecting
Host
Fig 84.
70) Set all other options to default and click "Create" at the end of this wizard. Wait for the cloning
process to complete.
Fig 85a. Selecting
Path
Fig 85b. Selecting Network
Fig 85c. Adding
Properties
Fig 85d. Creating VM clone
Fig 85e. Cloning process
After the cloning process is completed you will have a clone of the Base VM you have
configured. You will use this for creating the VM Template. The original VM (i.e. the VM
clone) is destroyed after a VM Template is created.
Later on, you might need to modify your VM template. In that case you will use the base
VM available that has thankfully remained intact.
71) Select Library in SCVMM console on the bottom left. On the upper left of the SCVMM console, right
click on Templates and choose "Create VM Template".
Fig 86. Creating a VM Template
72) In the Select Source tab, select "From an existing virtual machine that is deployed on a
host" and click on Browse to locate the clone you've created in step 70. Once you select the clone VM,
click on Next. In the appearing window, click on Yes.
Fig 87. Selecting the VM from which to create the
template
Fig 88. Approving that the original VM will be
destroyed
73) In the Identity tab, specify VM Template name and click on Next. In the Configure Hardware tab,
click on Next.
Fig 89. Specifying VM Template
name
hardware configuration
Fig 90. Template
74) In the Configure Operating System Settings tab, select "linux os profile" for "Guest OS profile"
and select "CentOS Linux 6 (64 bit)" for "Operating system", in the dropdown menus (for Oracle Linux
select "Oracle Linux 6 (64 bit)"). Click on Next.
Fig 91. Specify Operating system
75) In the Select Library Server tab, select the appropriate library server and click on Next. In the Select
Path tab, click on Browse to select the path on the Library Server to save the template and click on Next.
Fig 92. Selecting a library to place the VM
template
Fig 93. Selecting the path to place the
VM template
76) View your "Summary" configuration settings and click on "Create".
Fig 94. Finalizing VM Template wizard
77) Congratulations! Your Guest OS (Linux) template has been created. You may proceed with creating
the Guest OS (Windows) Templates for your Cloud Servers.
Download