Xen virtual machine disk image template making (iv)-centos 7

Source: Internet
Author: User

In the article "Xen Virtual machine disk image template making (iii)-centos 7", we have successfully produced the CentOS7 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.

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

[Email protected] ~]# lvcreate-l 15G-n centos7_vm vg0  "centos7_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  CENTOS7_VM vg0   00G

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

DD if=/root/centos7_mbr of=/dev/vg0/2048+0in2048+0 Records out 1048576 bytes (1.00.10184710.3 mb/~]#

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

Echo " 000001ca:00f8df01 " | Xxd-r-/dev/vg0/~]#

Because the target VM system disk size We created earlier is 15G, we need to set the size of the number of sectors occupied by disk partition 1 to 00F8DF01 (the exact calculation is subsequently re-organized), while 000001CA represents the starting byte position to save disk partition 1 to occupy the number of sectors, Refer to "Disk MBR master boot Sector" for details.

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/CENTOS7_VM Add map centos7_vm1:0 31455232Linear/dev/vg0/centos7_vm2048[[Email protected]~]# ll/dev/mapper/ Total0BRW-RW----1Root disk253,1June - Ten: - centos7_vm1CRW-------1Root rootTen, +May5  -: -CONTROLBRW-RW----1Root disk253,0June - Ten: $vg0-Centos7_vm[[email protected]~]#

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

6. Format target virtual machine root partition file system for EXT3 (or EXT4, etc.):

[Email protected] ~]# mkfs.ext3/dev/mapper/centos7_vm1 mke2fs1.39( in-may-2006) Filesystem label=OS type:linuxblock Size=4096(log=2) Fragment size=4096(log=2)1966080Inodes,3931904blocks196595Blocks (5.00%) reserved forThe Super Userfirst data Block=0Maximum filesystem blocks=4026531840 -Blockgroups32768Blocks per group,32768fragments per group16384inodes per groupsuperblock backups stored on blocks:32768,98304,163840,229376,294912,819200,884736,1605632,2654208Writing inode tables: DoneCreating Journal (32768Blocks): DoneWriting Superblocks and filesystem accounting information: DoneThis filesystem'll be automatically checked every theMounts or theDays, whichever comes first. Use Tune2fs-c or-I to override. [[Email protected]~]#

7. Mount the target virtual machine root partition under/MNT (or other directory):

Mount /dev/mapper/centos7_vm1/mnt/~]# ll/mnt/drwx2  16384: lost+ ~]# 

8, unzip the disk image template system files centos7_img to/mnt, and Umout:

[Email protected] ~]#TarZXF/ROOT/CENTOS7_IMG-C/Mnt[[email protected]~]# ll/mnt/ Total thelrwxrwxrwx1Root root7June -  One: GenevaBin-usr/Bindr-xr-xr-x4Root root4096June +  A: $BOOTDRWXR-xr-x2Root root4096June +  A: -DEVDRWXR-xr-x AboutRoot root4096June - Ten: -ETCDRWXR-xr-x2Root root4096JuneTen   thehomelrwxrwxrwx1Root root7June -  One: GenevaUsr/, Libliblrwxrwxrwx1Root root9June -  One: GenevaLIB64-usr/lib64drwx------2Root root16384June +  A: -lost+FOUNDDRWXR-xr-x2Root root4096JuneTen   theMEDIADRWXR-xr-x2Root root4096JuneTen   theMNTDRWXR-xr-x2Root root4096JuneTen   theOPTDRWXR-xr-x2Root root4096June +  A: -PROCDR-xr-x---2Root root4096June +  -: *ROOTDRWXR-xr-x2Root root4096June +  A: -runlrwxrwxrwx1Root root8June -  One: GenevaSbin-usr/SBINDRWXR-xr-x2Root root4096JuneTen   theSRVDRWXR-xr-x2Root root4096June +  A: -SYSDRWXRWXRWT7Root root4096June at  +: -TMPDRWXR-xr-x -Root root4096June +  A: theUSRDRWXR-xr-x -Root root4096June at  +: -Var[[email protected]~]# umount/mnt/

9. Delete disk partition mappings:

[[email protected] ~]# kpartx-d/dev/vg0/~]# ll/dev/mapper/0crw1 Root Root    :5  controlbrw1 253,  0: 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=1024x768name="CENTOS7_VM"vif= ['Bridge=eth0']disk= ['phy:/dev/vg0/centos7_vm,hda,w']vcpus=1On_reboot='Restart'On_crash='Restart'Boot='C'SDL=0VNC=1Vnclisten='0.0.0.0'Vncdisplay=6STDVGA=0Serial='Pty'Usbdevice='tablet'Xen_platform_pci=1

11. Start the virtual machine and log on to the virtual machine via VNC:

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

Xen virtual machine disk image template making (iv)-centos 7

Related Article

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.