Cainiao cloud computing 16th: migrate the virtual machine created on ubuntu14.04 to rhel6.4

Source: Internet
Author: User
Cainiao cloud computing 16th: migrate the rhel6.4 virtual machine created on ubuntu14.04 to rhel6.4 host


Qemu on ubuntu14.04 is newer than rhel6.4. As a result, the VM copied to the guest (rhel6.4) created in ubuntu14.04 cannot run on the rhel6.4host host. To solve this problem, follow these steps:

1) convert the VM in qcow2 format to raw format on ubuntu14.04.

2) define raw VM on rhel6.4.

Since rhel6.4 supports raw VMS, you can directly create a raw VM on Ubuntu and copy it to rhel6.4. However, VMS in raw format occupy too much space and it takes a lot of time to copy them.

Command for viewing the virtual machine image format:

$ qume-img info vm.img

Image: VM. img

File Format: raw

Virtual size: 80 GB

Disk size: 80 GB # This is very small at the time of creation. Sparse files.

Therefore, the following method can be used:

1) Use virt-manager to install kvm vm. IMG on ubuntu14.04. The default format is raw. It can be 80 GB.

2) copy the VM. IMG and VM. XML to rhel6.4. Note that the directory location must be (links can be used ):

/Etc/libvirt/qemu/VM. xml

/Var/lib/libvirt/images/VM. img

3) Modify VM. xml. Note that VM. xml used by rhel6.4 is slightly different from ubuntu14.04. The VM. XML (difference) in rhel6.4 is listed below ):

<domain type=‘kvm‘>    <name>vm</name>    <uuid>...</uuid>    <memory unit=‘KiB‘>4194304</memory>    <currentMemory unit=‘KiB‘>4194304</currentMemory>    <vcpu placement=‘static‘>4</vcpu>    <os>        <type arch=‘x86_64‘ machine=‘rhel6.4.0‘>hvm</type>        <boot dev=‘hd‘/>    </os>    <features>        <acpi/>        <apic/>        <pae/>    </features>    <clock offset=‘utc‘/>    <!--    <clock offset=‘localtime‘/>    -->    <on_poweroff>destroy</on_poweroff>    <on_reboot>restart</on_reboot>    <on_crash>destroy</on_crash>    <devices>        <!-- diff below -->        <emulator>/usr/libexec/qemu-kvm</emulator>        <disk type=‘file‘ device=‘disk‘>            <driver name=‘qemu‘ type=‘raw‘/>            <source file=‘/var/lib/libvirt/images/vm.img‘/>            <target dev=‘vda‘ bus=‘virtio‘/>        </disk>        <disk type=‘block‘ device=‘cdrom‘>            <driver name=‘qemu‘ type=‘raw‘/>            <target dev=‘hdc‘ bus=‘ide‘/>            <readonly/>            <address .../>        </disk>        ...        <serial type=‘pty‘>            <target port=‘0‘/>        </serial>        <console type=‘pty‘>            <target type=‘serial‘ port=‘0‘/>        </console>        ...    </devices></domain>

The difference is:

<emulator>/usr/libexec/qemu-kvm</emulator>


4) then run the definition:

$ Virsh define VM. xml


5) Start and close:

$ Virsh start VM

$ Virsh shutdown VM

The following describes how to log on to the virtual machine on the virsh console. Create the ttys0.conf file under/etc/init/of the VM. The content is as follows:

# /etc/init/ttyS0.conf: # ttyS0 - agetty  stop on runlevel [016]  start on runlevel [345]  instance ttyS0  respawn  pre-start exec /sbin/securetty ttyS0  exec /sbin/agetty /dev/ttyS0 115200 vt100-nav

Because we have not correctly configured the VM network yet, we cannot SSH to the VM. Therefore, you must use libguestfs-tools to copy ttys0.conf to the VM.
1) First, libguestfs-tools must be installed on the host rhel6.4:
$ yum install libguestfs-tools

2) create and edit ttys0.conf on the host and copy it to the VM:
$ Virsh shutdown VM # You must first disable the VM $ virt-copy-in-d vm ttys0.conf/etc/init $ virt-ls-d vm/etc/init $ virt-cat-d VM/etc/init/ttys0.conf

3) Start and console to VM:
$ virsh start vm$ virsh console vm

4) configure the VM network. Restart the VM. Then you can SSH to the VM.
Success! If you think the VM is small, you can resize it. See my other articles!

Cainiao cloud computing 16th: migrate the virtual machine created on ubuntu14.04 to rhel6.4

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.