Sunday, January 22, 2023

Migrating VMWare server vmdk to IBM Cloud qcow

 Basics:


1) IBM Cloud uses qcow2 format of virtualization files, which is used by the KVM "brand" of open-source virtualization.
    Source: https://cloud.ibm.com/docs/cloud-infrastructure?topic=cloud-infrastructure-migrating-images-vpc
    Among other IBM VPC requirements are:

  •       VMware virtual machine should be created with BIOS firmware type

  •      Understand IBM Cloud VPC custom image requirements:

    • Is in qcow2 format
    • The boot volume (primary vHDD) doesn't exceed 99 GB (conflicting - in another document it states 250GB limit)
    • If cloud-init is enabled, then remove all custom config files
    • Virtio drivers should be enabled
    • The operating system is supported as a stock image. For a list of supported stock images, see Images.
         -> Standard Linux, Ubuntu, Windows are all supported.

    2) VMWare uses a different format, i.e. vmdk.
        We therefore need to convert the vmdk file to qcow2, using the program qemu-img.
        Example command:
        qemu-img convert -p -f vmdk -O qcow2 centos6.9.vmdk centos6.9.qcow2
        Source: https://support.huaweicloud.com/intl/en-us/bestpractice-ims/ims_bp_0030.html
        This can take a long time depending on your computer power and size of the vmdk.

        Sample file used: ova 13GB -> converted to qcow2 became 26GB.
       
        I uploaded the file to an IBM VSI Linux machine and run the conversion there.
        It took more than 30 minutes on an IBM Linux machine 8GB     RAM 2vcpu.  

    3) After conversion, we will upload the qcow2 file to IBM COS - Cloud Object Storage.
        What we need:
        a.) Object Storage bucket. Make sure that the bucket you create is "Regional" and not cross Region.
        It is not necessary to be in the SAME data center as your Virtual Private Cloud (VPC) where you want to run the VM on an IBM VSI - virtual server instance. But, if it is in the same data center, the import Might possibly run faster. 
    In the example below, our VPC is in Frankfurt, Germany, then our IBM COS should also be in eu-de (Europe - Deustchland/Germany)



        b) Properly configured rclone on the computer where the qcow2 file is, with a connection to the bucket.
        c) For rclone setup, please see another ticket with the setup instructions. If you are using the IBM linux machine,
        make sure to type in the "Direct endpoint" in rclone config. Reason: Faster, and so that there will be no additional charges for data egress since the data will just "flow" within the IBM network.
           rclone config allows one to input a value that is not in the selection, so just go ahead. 





        rclone config shown above.
        Upload can take a long time depending on the size and Internet connection speed.
        28 GB took ~1 hour approx though I did not really monitor it, can't be sure. 
        
    4) Next is the setting of access.
    After uploading the qcow2 file to the bucket, we need to make sure that the Image Service for VPC has the authority to access the target service IBM CloudObject Storage. UNder source service, select VPC Infrastructure Services. Scope of access: Resources based on selected attributes. Resource type: Image service for VPC. Target service = Cloud Object Storage. 



    5) Import as custom image.
     Next, we can now import the qcow2 file from the bucket into our VPC as a custom image.
    Under VPC, select "Custom images". Click "Create" button.
    Fill up the form, then under Source select Cloud Object Storage -> select the qcow2 image you made.
    Under OS, select the correct OS you used for that image be it Windows or Ubuntu, our most common images.
    Example: I had MintLinux -> I selected "Linux / Debian"
    Complete the fields and click on IMport Custom Image.

    This will take a long time again. More than a few minutes to hours approximately.


    6) Create a virtual instance
    After the import completes, you can now create a virtual machine (VSI) using this image.

    To create a server, go to: Create virtual server for VPC.
    Under Operating system -> Image, select "Custom Image"
    Find the image you created.

    For the SSH keys, select an existing key that you have on your machine.
    Else, create a new one using PuttyGen (download Putty from the official site to also get PuttyGen along with it by default).
    Copy the Public key to the textbox on IBM Cloud. Make sure to save the private key on your computer.
    You will need this for ssh access to this server from your computer.

    Complete all the fields and click on "Create Virtual Server Instance" on the right hand side.



    7) Voila! We now have our server. You may connect using SSH or console.

    Note that the IP address of the server will automatically be assigned by IBM (it will not get its old IP).

    The username and password though will still be the old username and password you already have on the source VM.

    8) Optional ->
    Below instructions might not apply (it might only apply to newly created servers - those that did not use a custom image.
    For ssh, use putty. You might need to load the private key in the Connection-> Auth-> "Private key file for authentication"