Migrating a Linux VM to the OUTSCALE Cloud

You can migrate a Linux virtual machine (VM) from VMWare, VirtualBox, or Amazon Web Services (AWS) to an OUTSCALE Linux VM. For more information about OUTSCALE VMs, see About VMs.

The following procedures are generic instructions that you can follow depending on your situation. You may need to adjust them according to your needs.

Migrate the VM from VMWare or VirtualBox

Before you begin: Make sure you have:

  • SSH service installed

  • SSH key or login/password remotely allowed (/etc/sshd/sshd_config)

  • Security group set up to connect to a VM

Prepare the OUTSCALE VM

  1. Create an OUTSCALE VM. For more information, see Creating VMs.

  2. Attach two volumes to this VM, as /dev/xvdb and /dev/xvdc. For more information, see Attaching a Volume to a VM.

    You can speed up the copy by using an io1 volume.

  3. Format the /dev/xvdb volume in ext4 format:

    $ mkfs -t ext4 /dev/xvdb
  4. Create the mount point:

    $ mkdir -p /mnt/source
  5. Mount the /dev/xvdb volume:

    $ mount /dev/xvdb /mnt/source

    The volume is mounted.

Perform the Migration

  1. Copy the main volume of your non-OUTSCALE VM to the volume of your OUTSCALE VM using the following command:

    $ scp -i keypair.rsa convertible.vmdk user@outscale_ip:/mnt/source

    The name of the default user depends on the OMI used:

    • outscale for Ubuntu 18 and Centos 7 OMIs released since 20 December 2018

    • ubuntu for older Ubuntu OMIs

    • centos for older Centos 7 OMIs and Centos 6 OMIs

    The volume is copied.

  2. Install the qemu package and convert your files:

    $ qemu-img convert -f vmdk /mnt/source/convertible.vmdk -O raw /mnt/source/converted.raw
  3. Copy your files to the target partition (the /dev/xvdc disk) bit by bit:

    $ dd if=/root/converted.raw of=/dev/xvdc bs=16k status=progress

    The files of your non-OUTSCALE VM are migrated to the OUTSCALE VM.

Migrate the VM from AWS

Before you begin: Make sure you have:

  • SSH service installed

  • SSH key or login/password remotely allowed (/etc/sshd/sshd_config)

  • Security group set up to connect to a VM

Prepare the AWS VM

  1. Detach the bootdisk of your source AWS VM.

  2. Create a second AWS VM.

  3. Attach the bootdisk of your source AWS VM to the second AWS VM, as /dev/hdb.

  4. Add a third volume to the second AWS VM, as /dev/hdc.

  5. Compress the /dev/hdb volume into a zip file on /dev/hdc, using the following commands:

    $ sudo chown -r ec2-user:root /mnt
    $ sudo mkfs -t ext4 /dev/hdc
    $ sudo mount /dev/hdc
    $ sudo dd if=/dev/hdb | gzip -c > /mnt/aws.raw

    The volume is compressed into a zip file.

Prepare the OUTSCALE VM

  1. Create an OUTSCALE VM. For more information, see Creating VMs.

  2. Attach two volumes to this VM, as /dev/xvdb and /dev/xvdc. For more information, see Attaching a Volume to a VM.

    You can speed up the copy by using an io1 volume.

  3. Format the /dev/xvdb volume in ext4 format:

    $ mkfs -t ext4 /dev/xvdb
  4. Create the mount point:

    $ mkdir -p /mnt/source
  5. Mount the /dev/xvdb volume:

    $ mount /dev/xvdb /mnt/source

    The volume is mounted.

Perform the Migration

  1. Copy the aws.raw file from the second AWS VM to the OUTSCALE VM:

    $ scp -i keypair.rsa aws.raw user@outscale_ip:/mnt/source

    The name of the default user depends on the OMI used:

    • outscale for Ubuntu 18 and Centos 7 OMIs released since 20 December 2018

    • ubuntu for older Ubuntu OMIs

    • centos for older Centos 7 OMIs and Centos 6 OMIs

    The file is copied.

  2. Decompress the data:

    $ gunzip -c /mnt/source/aws.raw > /dev/xvdc

    The files of your AWS VM are migrated to the OUTSCALE VM.

Configure the Migrated VM

Chroot the Partition

  1. Create the mount point/target:

    $ mkdir -p /mnt/target
  2. Type the following commands to mount the different mandatory files, where X is the number of the partition containing the operating system:

    $ mount /dev/xvdcX /mnt/target
    $ mount --rbind /dev /mnt/target/dev
    $ mount -t proc /proc /mnt/target/proc
    $ mount --rbind /sys /mnt/target/sys
  3. Create the new path:

    $ export PATH=$PATH:/bin:/sbin
  4. Chroot the partition you created:

    $ chroot /mnt/target

Allow Root Login

Allow the root login only via SSH and a key in /etc/ssh_config.

Configure GRUB

  1. Change the configuration of GRUB (may be in grub2 if this one is applied):

    $ /boot/grub/grub.cfg
  2. Check the GRUB parameters in the /etc/default/grub file.

    1. Check if the volume name is vda instead of sda or hda. If it is not, change it.

    2. Add the following options to your kernel line in GRUB:

      $ GRUB_CMDLINE_LINUX_DEFAULT="elevator=deadline console=tty0 console=ttyS0,38400n8"

      GRUB is modified.

  3. Apply the configuration of GRUB:

    $ grub-mkconfig
  4. Install the newly configured GRUB:

    $ grub-install

Check the Last Elements

  1. Check if the volume names are aligned in /etc/fstab.

  2. Set up the udev rules package. For more information, see Installing the Packages for Linux Device Names.

  3. If your /etc/rc.local does not contain the SSH key, use the following script to refresh the authorized_keys file:

    $  sed -i '/^exit 0/d' /etc/rc.local
        cat >> /etc/rc.local <<EOF
        /bin/mkdir -p /root/.ssh #LINE_TO_STRIP
        wget http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key -O - > /root/.ssh/authorized_keys
        /bin/chmod 700 /root/.ssh -R
        wget http://169.254.169.254/latest/meta-data/local-hostname -O - | cut -d '.' -f 1 > /etc/hostname; #LINE_TO_STRIP
        hostname -F /etc/hostname #LINE_TO_STRIP
        sed -i '/^.*LINE_TO_STRIP.*$/d' /etc/rc.local; #LINE_TO_STRIP
        EOF
  4. Clean up the sensitive elements of your VM. For more information, see Linux VMs Clean-up to Create OMIs.

    You can verify the clean-up with either yum -y clean all`or`apt-get -y clean all.

Start the VM

  1. Check and clean all programs enabled at boot except ssh.

  2. Create a snapshot of your volume. For more information, see Creating a Snapshot of a Volume.
    Your snapshot is created.

  3. Create an OUTSCALE machine image (OMI) from the snapshot you created. For more information, see Creating an OMI from a Snapshot.
    The OMI is created.

  4. Create a VM from the OMI you created. For more information, see Creating VMs.

Related Pages

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.