Windows Template Creation Guide How to build your own Windows VM templates for deployment in Cloudturk.
TABLE OF CONTENTS 1. Preparing the Server... 2 2. Installing Windows... 3 3. Creating a Template... 4 4. Naming Conventions... 5 5. Generate Template SQL... 6 Appendix A: Installing Xen Hypervisor... 9 1
1. Preparing the Server To create a Windows VM template for Xen/KVM hypervisors you ll need a separate Open Source Xen 3/4 or KVM box on which to create your template. You can t create templates from scratch within Cloudturk! To prepare a physical box: 1. Install XEN or KVM hypervisor. For detailed instructions, refer to Appendix A. Installing XEN hypervisor of this document. 2. Install the latest version of Virtual Manager (see http://virtmanager.org/download.html) 3. Install ntfs 3g and ntfs fuse: # yum install fuse-ntfs-3g 4. Create Logical Volume Manager (LVM). There s a useful how to article here: http://www.walkernews.net/2007/07/02/how- to- create- linux- lvm- in- 3- minutes/ 5. Create disks using the LVM. Disk size depends on the version of Windows required for the template: Windows 2008: 20GB Windows 2003: 10GB 6. Using Virtual Manager, create a new virtual machine based on the partition created earlier in LVM. 2
2. Installing Windows The next step is installing Windows OS to the virtual machine we ve just created. To do so: 1. Add a DVD/CD ISO to the virtual machine you ve just created, and install the required Windows version. 2. Add the native Windows startup script to this VM: a. Go to Computer Settings > Windows Settings > Scripts (Startup/Shutdown) b. On the pane that appears, double- click Startup. c. Point the script to C:\cloudturk.bat For more detailed instructions, refer to the Microsoft documentation here: http://technet.microsoft.com/en- us/library/cc770556.aspx 3. If you re using Xen, install the Xen PV drivers and disable large sent offload for eth interface (see http://www.meadowcourt.org/downloads/). Skip this step for KVM. 4. Install SNMP services in a regular way. 5. Install Copssh into C:\cossh 6. Shut down your VM. The shutdown method depends on which version of Windows you just installed: Windows 2003/XP/2008 run sysprep in shutdown mode. See http://support.microsoft.com/kb/892778/en- us for details. Windows 2008R2 - shut down the VM in the normal way. 3
3. Creating a Template To create a Cloudturk Windows template, perform the following steps on your physical server: 1. Go to the location where you plan to store a template. 2. Run the following script to create a template from that node (see below for more details): echo "sh create-image 5 win03_x64_ent" echo kpartx -a /dev/vg0/lvol$1 mount -t ntfs-3g /dev/mapper/lvol$1p1 /mnt/l$1 rm -f /mnt/l$1/pagefile.sys umount /mnt/l$1 echo echo "Executing ntfsclone -s -o./$2.img /dev/mapper/lvol$1p1 " echo ntfsclone -s -O./$2.img /dev/mapper/lvol$1p1 echo echo kpartx -d /dev/vg0/lvol$1 dd if=/dev/vg0/lvol$1 of=./$2.img.mbr count=1 bs=512 tar -czvf $2.tar.gz $2.img $2.img.mbr cd - Where the highlighted parameters mean: /dev/vg0/lvol - the path to LVM 4
5 the number of the partition created in LVM. win03_x64_ent the name of the template you are creating with this script As a result, the.tar.gz archive will be created at the location where you run the script. The archive will include the.img and img.mbr files 4. Naming Conventions Cloudturk Windows templates should follow this naming convention: <DISTRIBUTION>_<ARCH>_<EDITION>[-SOFT][-TEMPLATEVERSION][- <VIRTUALIZATION>].tar.gz Required parameters: DISTRIBUTION - distribution short name and the version, e.g. WIN08 or WIN03 ARCH hardware platform (x64 or x86) EDITION Windows OS edition (STD Standard, ENT Enterprise, WEB web, PRO professional and DC Data center) Optional parameters: SOFT add this tag if you installed any additional software to the VM. TEMPLATEVERSION version of the current template (verx.x format) VIRTUALIZATION the virtualization platform the template is compatible with. Available value is kvm. If none specified, it means XEN is used. 5
Examples: win08_x64_std- ver2.1- kvm.img (Windows 2008 Standard Edition x64 for KVM, template version 2.1) win08_x86_std- ver2.2.img (Windows 2008 Standard Edition x86 for XEN, template version 2.2) 5. Generate Template SQL We have created a script to generate the SQL needed to add templates to the Cloudturk Control Panel. 1. Download the script: # wget http://templates.repo.cloudturk.com/generatecloudturk-templates-sql.sh 2. Run the script: For example, to get the SQL for Cloudturk CP version 2.3.2: # sh ~/generate-cloudturk-templates-sql.sh -v 2.3.2 -m SQL -d /data/templates/windows/ -t win08_x64_std_r2-ver3.1-kvm.img And the result will be: INSERT INTO `templates` (label, created_at, version, file_name, operating_system, operating_system_distro, allowed_swap, state, checksum, allow_resize_without_reboot, min_disk_size, template_size, operating_system_arch, operating_system_edition, operating_system_tail, allowed_hot_migrate, virtualization) VALUES ('Windows 2008 Standard Edition x86', NOW(), '3.1', 'win08_x64_std-ver3.1- kvm.img', 'windows','2008', 0, 'active', 6
'fe520abaff0b0fbe85b3a359c50e7027', 0, 20,'312468', 'x64', STD, R2, 0, 'kvm'); Where: label the optional template label version your template version file_name the file name of your template operating_system for Windows templates it would be windows operating_system_distro the particular distribution (2008 or 2003) allowed_swap there is no swap for Windows templates, so it is always 0 state active or inactive checksum the generated checksum. allow_resize_without_reboot 1 if the resize without reboot is allowed, otherwise 0 min_disk_size the amount of GB required for this template (20GB for Windows 2008, 10GB for Windows 2003) template_size the size of a template operating_system_arch x64 or x86 operating_system_edition this can be STD Standard, ENT Enterprise, WEB web, PRO - professional and DC Data center. operating_system_tail R2 if this is a Release 2 version, otherwise NULL allowed_hot_migrate 1 if hot migration is allowed, otherwise 0 virtualization for KVM this would be kvm (taken from the filename of the template in the script). If none specified in the filename, it means XEN is used and xen will be stated in the script output. 7
3. Insert the record generated into your database: Connect to your Control Panel server using SSH: ssh root@x.x.x.x (x.x.x.x stands for the server IP) Go to the directory where Cloudturk config file is located: cd /cloudturk/interface/config Find the database password and name: cat database.yml Log in as root to your database: mysql -u root -p [database name] Go to your database: use [database name]; Insert the record: INSERT INTO `templates` (label, created_at, version, file_name, operating_system, operating_system_distro, allowed_swap, state, checksum, allow_resize_without_reboot, min_disk_size, template_size, operating_system_arch, operating_system_edition, operating_system_tail, allowed_hot_migrate, virtualization) VALUES ('Windows 2008 Standard Edition x86', NOW(), '3.1', 'win08_x64_stdver3.1-kvm.img', 'windows', '2008', 0, 'active', 'fe520abaff0b0fbe85b3a359c50e7027', 0, 20, '312468', 'x64', STD, R2, 0, 'kvm') Press Enter. 4. Place the.img and img.mbr files to the location where you store templates. 8
Appendix A: Installing Xen Hypervisor Instructions for a basic Xen hypervisor installation: 1. Install OS for Xen Hypervisor: Cloudturk supports the following operating systems for Xen Hypervisor: CentOS release 5.x (x86_64) Red Hat Enterprise Linux Server release 5 (x86_64) 2. Partition the Xen hypervisor box: The disk can be partitioned any way you like, with one exception: you must create a separate partition with LVM. This will be used to deploy block devices as hard disks for virtual machines. 3. Install essential utilities on the Xen Hypervisor box: We recommend the following software is preinstalled on the Xen Hypervisor box: vim command- line editor. This guide uses vim in examples where files need to be edited. GNU tar utility and GNU zip archive tool. They are used to pack the template. X window system. We will use it to run some GUI applications. Apache web server. It will be used to run local distributive mirrors, and access KickStart files during installation. virt- manager. Not mandatory, but sometimes it makes creating VMs easier. vncviewer. Used for connecting to VMs via VNC. LVM utilities. All of them will be required while creating VMs and templates for Cloudturk. 4. Add YUM repository: An extra YUM repository is used to get the Xen Hypervisor installed manually. 9
Please download extra repository configuration file and place it into standard YUM repositories configuration files location (/etc/yum.repos.d/): # wget http://www.gitco.de/repo/gitco-xen3.4.3_x86_64.repo -O /etc/yum.repos.d/ GITCO-XEN3.4.3_x86_64.repo 5. Install Xen Hypervisor: a) Clean YUM meta- data: # yum -y -q clean all b) Remove old Xen if installed: # yum remove xen c) Install the latest Xen from GITCO: # yum install xen d) Remove i386 libvirt: # yum remove libvirt.i386 xen-libs.i386 e) Configure xend service to start on system boot: # chkconfig --add xend # chkconfig xend on f) Install Xen Hypervisor (Dom0) kernel: # yum install kernel-xen g) Verify the kernel- xen package is installed, and determine the version: 10
# rpm q kernel-xen h) Configure GRUB boot loader to use Xen kernel as default (check GRUB s configuration file): # vim /boot/grub/grub.conf It should look like the following image: The default option value must be the number of the title, which includes Xen kernel. There are two title sections on the image above: title CentOS (2.6.18-194.32.1.el5xen) title CentOS (2.6.18-194.32.1.el5) Titles are numbered starting from 0. So the first has number 0, and the second, number 1. The default option value should be the number of title with Xen kernel. In the example here it is number 0 (the first title). i) Reboot the box: 11
# shutdown r now j) Check if Xen Hypervisor is running when the box boots: # xm info If Xen is running, this should display a range of information about the system. 12