9.3 VMWare to Mirantis OpenStack Express 148
9.3.2 Linux Virtual Machine 165
This section will cover the conversion of a Linux Virtual Machine running under VMWare to running under OpenStack. There are a number of different flavors of Linux so this document will cover CentOS Linux.
If you have root access to the virtual machine, proceed with converting a Linux Virtual Machine. If you don’t have root access, shut down the virtual machine via vCenter or in Fusion and proceed with copying the VMDK file.
9.3.2.1 Converting a Linux Virtual Machine (root access)
Log into the Linux Virtual Machine as the root user via SSH:
● Delete all network adapter info (HWADDR, UUID, ipaddress, netmask, DNS, gateway and change bootproto to dhcp ) from interface configure file via command:
After editing, the file should look like this:
● Remove file /etc/udev/rules.d/70-persistent-net.rules via command: rm -f /etc/udev/rules.d/70-persistent-net.rules
● Remove host name via command: vi /etc/sysconfig/network
Move down to the hostname line, and delete the line by typing dd on the line:
Enter the following to save and quit the file: :wq!
● Shut down the Virtual Machine via command: shutdown -h now
9.3.2.2 Copy the VMDK File
After shutting down the virtual machine, obtain the VMDK files that make up the virtual machine. To locate these files, select Edit Settings on the Virtual Machine in vCenter and click on the Hard Disk to see the location of the file:
Note: If the Virtual Machine has multiple hard disks allocated to it, the process to migrate it into OpenStack becomes more complicated. If you wish to attempt this, please refer to this:
https://ask.openstack.org/en/question/5358/how-to-import-a-vmware-vm-with-multiple-drives/
Note: If your Virtual Machine was created in VMWare Workstation or VMware Fusion, it’s possible you don’t have a single *-flat.vmdk that you need and instead have multiple VMDK files that make up the single disk:
If this is the case, you will require the Virtual Disk Development Kit from VMware available here:
https://www.vmware.com/support/developer/vddk/
See Appendix B for installation and usage of the toolkit to merge the multiple VMDK files into a single flat VMDK.
After downloading the VMDK image from the datastore, you need to place it on a Linux system to utilize the qemu-img tools to convert it to the appropriate QCOW2 format. You can either create a Linux Virtual Machine and install the qemu-img package or you can utilize the Controller Node of your OpenStack environment. See Navigating Mirantis OpenStack section of this document for obtaining access to the Controller Node of Mirantis OpenStack Express and uploading the VMDK image.
NOTE: If your VMDK is a large file, ensure that there is at least 2.5x the space available on your Controller Node before uploading it to the controller node.
SSH in as the mirantis user and convert the VMDK to a QCOW2 format by issuing the following command:
qemu-img convert -f {initial format} -O {target format} {source file} {destination file}
Example: qemu-img convert -f vmdk -O qcow2 VM.vmdk VM.qcow2
If you had root access to this Linux Virtual Machine, you are ready to upload your image to OpenStack as detailed in the validating authentication section of this document. If you did not have root access, proceed with Converting a Linux Virtual Machine before uploading your image to OpenStack.
9.3.2.3 Converting a Linux Virtual Machine (no root access)
If you are running guestfish on the Controller Node, you need to execute the following line so that guestfish knows where to locate qemu-kvm binary, otherwise you will have issues: export LIBGUESTFS_QEMU=$(rpm -ql qemu-kvm | grep qemu-kvm$)
There are some changes which need to be done within the operating system before uploading the image to OpenStack. These changes can be accomplished using guestfish. If you are using a VM that you created to perform the changes, ensure you have the libguestfs-tools package installed as this contains the guestfish application used to make the changes within the QCOW2 file. The process basically is:
Execute the guestfish program to get a guestfish shell List the filesystems within the QCOW2 file
Mount the networking file
● Run guestfish and mount image and edit. Execute the commands in the following order: # guestfish
><fs> add Centos.qcow2 ><fs> run ><fs> list-filesystems /dev/sda1: ext4 /dev/vg_centosmigrate/lv_root: ext4 /dev/vg_centosmigrate/lv_swap: swap
Example: /etc located in lvm /dev/vg_centosmigrate/lv_root ><fs> mount /dev/vg_centosmigrate/lv_root /
● Now need edit network interfaces file, remove all network adapter info (HWADDR, UUID, ipaddress, netmask, DNS, gateway) from interface configure file /etc/sysconfig/network- scripts/ifcfg-eth0 and and change bootproto to dhcp
><fs> edit /etc/sysconfig/network-scripts/ifcfg-eth0
General editing commands:
dd - Delete the line your cursor is on
D - Delete text from the point of the cursor through the end of the line i - insert text at the point your cursor is located
a - append to line at the point where your cursor is :wq - Write the file and quit the editor
After editing, the file should look like this
● Delete udev file via command:
><fs> rm /etc/udev/rules.d/70-persistent-net.rules ● Delete host name via command:
><fs> edit /etc/sysconfig/network
● Exit guestfish via command: ><fs> exit
You can now upload this image to OpenStack as detailed in the upload image section of this document.