This document references the address from Xen Host kernel to a semi-virtualized guest
1. IMG and swap
Create a 50G img for the root file system
# dd If=/dev/zero of=/data/xen/xen1.img bs=1m seek=51200 count=0
Format into ext3
# mkfs-t ext3 /data/xen/xen1.img
Create a 2G img for swap swap
# dd If=/dev/zero of=/data/xen/xen1.. Swap bs=1m seek=2048 count=0
Format to swap
# mkswap /data/xen/xen1. Swap
2. Copy the host's root file system to the guest's root file system img
# Mkdir/tmp/loop
# Mount-o loop =/data/xen/xen1.img /tmp/loop- o rw,acl
# Cp-ax/{bin,dev,etc,lib,lib64,root,sbin,usr,var}/tmp/loop
Be very careful here!!! It is important to remember to copy the/lib64 in x86_64 because there are some libraries in the lib64 that must be linked.
Create the remaining folders
# mkdir/tmp/loop/{home,proc,opt,sys.tmp}
# chmod 777/tmp/loop/tmp
3. Modify some files in the guest root filesystem
/tmp/loop/etc/fstab:
/DEV/XVDA1 / ext3 defaults 1 1/dev/xvda2 none swap SW 0 0none /dev/pts devpts gid=5,mode=620 0 0none /dev/shm tmpfs defaults 0 0none /proc proc defaults 0 0none /sys sysfs defaults 0 0
Note The user information and host information saved in these files
/tmp/loop/etc/passwd
/tmp/loop/etc/group
/tmp/loop/etc/hosts
Modify Network Configuration
/tmp/loop/etc/sysconfig/network modifying Hostname=xen1 ,
/etc/sysconfig/network-scripts/ifcfg-eth0 set A and host Br0 in the same network segment of the IP, but also delete the UUID and hwaddr, or the host side of the same hardware address. Or it can be modified after connecting to the virtual machine via the console.
Uninstall the root directory of the guest
# umount/tmp/loop/
4. Create a Xen virtual machine configuration file/etc/xen/xen1.cfg
Specifies the kernel file that launches the kernel as host
Kernel= "/boot/vmlinuz-3.18.25-19.el6.x86_64" ramdisk= "/boot/initramfs-3.18.25-19.el6.x86_64.img" name= "Xen1" memory= "4096" disk = [' Tap:aio:/data/xen/xen1.img,xvda1,w ', ' tap:aio:/data/xen/xen1.swap,xvda2,w ']vcpus=4on_reboot = "Restart" on_crash= "destroy" root= "/dev/xvda1 ro" extra= "selinux=0" vif=["BRIDGE=BR1"]
It is important to note that the dracut:chroot:failed to Run command '/sbin/load_policy ': No such file or directorymay be reported when the virtual machine is started, because C Lone the root file system did not copy the/lib64 to guest, refer to http://marc.info/?l=xen-users&m=135907220030809.
5. Start and console connected to the virtual machine
Don't creating virtual machines with XL Create,virsh create Virsh define! I created the virtual machine using the first two methods, but I can't find it after I shut down the virtual machine!
Create a virtual machine with Virsh define
To convert a configuration file under/etc/xen/to a Virsh profile
Xen1.cfg >xen1.xml
Create a virtual machine
Virsh Define Xen1.xml
Finally, the login prompt, using the host OS account password login can
CentOS Release 6.6 (Final)
Kernel 3.14.42-1.el6xen.x86_64 on an x86_64
CENTOS6-1 Login:
6. This allows us to copy the root file system img and swap of the created guest, and copy and modify a Xen client configuration file to modify some files in the root filesystem such as fstab and network, It is easy to clone multiple virtual machines.
problems encountered:1. When executing the virsh List command:Error:failed to reconnect to the hypervisor
Error:no Valid connection
Error:failed to connect socket to '/var/run/libvirt/libvirt-sock ': No such file or directory
Workaround:Yum-y Install Avahi/etc/init.d/messagebus restart
/etc/init.d/avahi-daemon restart
/ETC/INIT.D/LIBVIRTD restart
/sbin/chkconfig Messagebus on
/sbin/chkconfig Avahi-daemon on
2.Error, some other host already uses address
Workaround: comment/etc/sysconfig/ Span style= "Background-color:inherit" >network -scripts/ Ifup-eth file contents:
#if! Arping-q-C 2-w-i ${realdevice} ${ipaddr}; Then
# Net_log $ "Error, some other host already uses address ${ipaddr}."
# exit 1
#fi
Service Network restart
3.XL cp-ax/{bin,dev,etc,lib,root,sbin,usr,var}/tmp/loop error when creating Virtual machine replication directory:cp:preserving permissions for '/mnt/var/run/cups/certs/0 ': Operation not supported
Solutions: Add parameters when mounting- o rw,aclMount-o Loop/data/xen/xen2.img/tmp/loop-o Rw,acl
4. When creating a 5th virtual machineError:device 2049 (VBD) could not be connected. Failed to find an unused loop device
Workaround:
Makedev-v/dev/loop
Virtualization Series II--Creating virtual machines