Xen virtual machine disk image template making (ii)-windows Server 2008 (2012)

Source: Internet
Author: User

In the article "Xen Virtual machine Disk mirroring template Authoring (i)-windows Server 2008 (2012)", we have successfully produced a Windows server disk image. Below we explain how to build the target virtual machine through it, and test whether there is a problem with the virtual machine disk mirroring template that was created before. The specific process is described below:

1. Create the system disk for the target virtual machine:

[Email protected] ~]# lvcreate-l 15G-n windows_vm vg0  "windows_vm" created

2. View the virtual machine system disk that was created successfully:

[[email protected] ~]# LVS  LV         VG   Attr   lsize  Origin Snap%  Move Log copy%  Convert  WINDOWS_VM vg0   00G

3. Re-windows_mbr the previously exported disk MBR master boot sector to the virtual machine system disk:

DD if=/root/windows_mbr of=/dev/vg0/windows_vm1+0in1+0  Records out bytes (0.00918955.7 kb/s

4. Modify the system disk partition size (in number of sectors):

Echo " 000001ca:00f0df01 " | Xxd-r-/dev/vg0/

Because the virtual machine system disk size We created earlier is 15G, so here we need to set the disk partition 1 the number of sectors occupied by the size of 00f0df01 (the exact calculation of the subsequent rearrangement), and 000001CA is to save the disk partition 1 occupy the starting byte location of the number of sectors, for details, please refer to the Disk MBR master boot sector.

5, set up the disk partition map of the system disk, map all the partitions of the system disk to/dev/mapper:

[Email protected] ~]# kpartx-av/dev/vg0/WINDOWS_VM Add map windows_vm1:0 31453184Linear/dev/vg0/windows_vm2048[[Email protected]~]# ll/dev/mapper/ Total0CRW-------1Root rootTen, +May5  -: -CONTROLBRW-RW----1Root disk253,2June -  -: invg0-WINDOWS_VMBRW-RW----1Root disk253,0June -  -: - windows_vm1[[email protected]~]#

The red part is the root partition of the virtual machine disk.

6. Unzip and restore the previously crafted Windows Server disk image template windows_img to the root partition of the virtual machine disk:

[Email protected] ~]#Gunzip-c/root/windows_img | Ntfsclone--restore-image--OVERWRITE/DEV/MAPPER/WINDOWS_VM1-ntfsclone v2012.1.15(libntfs-3g) Ntfsclone image version:10.1Cluster Size:4096bytesimage Volume Size:16104026112Bytes (16105MB) Image Device Size:16104030208BytesspaceinchUse:7510MB (46.6%) Offset to image data: About(0x38) bytesrestoring NTFS from image ... Warning:no Alternate Boot Sectorinchimagesyncing ... [[Email protected]~]#

7, the expansion system disk File system size to fit the size of the disk root partition:

[Email protected] ~]# ntfsresize-f-f/dev/mapper/windows_vm1 ntfsresize v2012.1.15(libntfs-3g) Device Name:/dev/mapper/Windows_vm1ntfs Volume version:3.1Cluster Size:4096bytescurrent Volume Size:16104026624Bytes (16105MB) Current Device Size:16104030208Bytes (16105MB) New Volume Size:16104026624Bytes (16105MB) nothing to Do: NTFS volume size is already OK. [[Email protected]~]#

This is because the system disk File system size is exactly 15G, just match the root partition size, so show nothing to do, does not matter.

8. To this step, if you need to implant some files into the virtual machine system or modify some files, you can mount the virtual machine root partition into a directory, as follows:

Mount -tntfs-3g/dev/mapper/windows_vm1/mnt/umount /mnt/

You do not need to implant some files into the virtual machine system or modify some files to skip this step directly.

9. Delete disk partition mappings:

[[email protected] ~]# kpartx-d/dev/vg0/~]# ll/dev/mapper/0crw1 Root Root    :5  controlbrw1 253,  2: vg0-

10. So far, the virtual machine system disk is ready, the following is the need to prepare the virtual machine configuration file:

Kernel ="/usr/lib/xen/boot/hvmloader"Builder='HVM'Memory=2048name="WINDOWS_VM"vif= ['Bridge=eth0']disk= ['phy:/dev/vg0/windows_vm,hda,w']vcpus=1On_reboot='Restart'On_crash='Restart'Boot='C'SDL=0VNC=1Vnclisten='0.0.0.0'Vncdisplay=1STDVGA=0Serial='Pty'Usbdevice='tablet'localtime=1

11. Start the virtual machine:

[Email protected] ~]# XM create/root/windows_vm.cfg Using configfile "/root/windows_vm.cfg". Started Domain WINDOWS_VM (ID=573) [[email protected]~]# xm liname ID Mem Vcpus State time (s) Domain-0                                     0  1856     8R-----92557.1WINDOWS_VM573  2048     1R-----1.7[[Email protected]~]#

12. Log in to the virtual machine via VNC:

At this point, a completely new virtual machine was built successfully with the Windows Server disk image template that was created earlier.

Xen virtual machine disk image template making (ii)-windows Server 2008 (2012)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.