Exporting an Amazon Web Services (AWS) Elastic Compute Cloud (EC2) instance that is making use of Amazon Elastic Block Store (EBS) data volumes is not possible using the standard AWS Command Line Interface (CLI) command “ec2-create-instance-export-task”. The limitations are described a the bottom of this page.

As a workaround you can use the following procedure which requires a number of VMware solutions:

  • VMware vCenter Converter Standalone 6.0.0
  • VMware ESX Server 5.5.0
  • VMware Workstation 10.0.7

The procedure described below should work with the versions of the VMware software mentioned above, but other combinations might also work fine. The EC2 instance being exported was based on a RHEL 7.0 Amazon Machine Image (AMI).

Step 1) First make sure you can login to your active Linux EC2 instance using a username and password. This is disabled by default in the Linux AMIs, but can be enabled by setting the following option in both /etc/ssh/ssh_config and /etc/ssh/sshd_config:

PasswordAuthentication yes

Next restart the ssh daemon:

service sshd restart

Step 2) Create an account with root permissions and a known password as the standard user “ec2-user”

sudo –i
useradd -ou 0 -g 0 <username>
passwd <username>

Step 3) Run VMware vCenter Converter (make sure you always run this utility “as Administrator” under Windows) and select “Convert machine” from the menu at the top. Select “Powered-on machine” from the “Select source type” drop down list and specify the address, user name, password and O.S. Family (Linux) for the remote machine on AWS. In the next step of the wizard indicate to which VMware ESX server the Linux EC2 instance has to be exported. Just follow the rest of the wizard and wait for the conversion task to finish.

Note that you need version 6.0.0 or higher of VMware vCenter Converter to be able to convert RHEL 7.0 AMIs. If you use a lower version, you might receive the following error:

“Failed to find matching disk device for VMODL Param Disk #0”

Step 4) At 97% completion the VMware vCenter Converter might run into the following exception:

015-09-24T20:18:52.012+02:00 error vmware-converter-server[03348] [Originator@6876 sub=Ufa.HTTPService] Failed to read request; stream: <io_obj p:0x042a518c, h:-1, <pipe ‘\\.\pipe\vmware-converter-server-soap’>, <pipe ‘\\.\pipe\vmware-converter-server-soap’>>, error: class Vmacore::TimeoutException(Operation timed out)
2015-09-24T20:20:49.905+02:00 info vmware-converter-server[03452] [Originator@6876 sub=Default] ConverterConnection: KeepAlive timer canceled, StopKeepAlive succeeded
2015-09-24T20:29:24.640+02:00 error vmware-converter-server[00728] [Originator@6876 sub=Default] [task,350] [LRO] Unexpected Exception: converter.fault.CloneFault
2015-09-24T20:29:24.655+02:00 info vmware-converter-server[00728] [Originator@6876 sub=Default] [task,379] [task-1] — ERROR — Convert: converter.fault.CloneFault
–> (converter.fault.CloneFault) {
–> faultCause = (vmodl.MethodFault) null, 
–> description = “GrubInstaller::InstallGrub: /usr/lib/vmware-converter/installGrub.sh failed with return code: 1, and message:
–> Installing for i386-pc platform.
–> grub2-install: error: disk `hd0′ not found.
–> Installing for i386-pc platform.
–> grub2-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won’t be possible.
–> grub2-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged..
–> grub2-install: error: will not proceed with blocklists.
–> Error installing GRUB
–> Command: grub2-install –no-floppy /dev/sda
–> Error running vmware-updateGrub.sh through chroot into /mnt/p2v-src-root
–> /usr/lib/vmware-converter/installGrub.sh: line 147: /mnt/p2v-src-root: Is a directory
–> Installing GRUB2 on (hd0)…
–> Installing GRUB2 on (hd0) failed.
–> Installing GRUB2 on /dev/sda…
–> “, 
–> msg = “”
–> }

Due to this exception you won’t be able to boot your VM. If you try to boot the VM, you will see the following error (Operating System not found):

To solve this issue, proceed as follows (based on this knowledge base article for a similar problem):

Step 5) Boot your VM in rescue mode. Typically you won’t have a rescue disk for an AWS AMI based EC2 instance, but you can simply use the standard installation .iso files which you can download from the Red Hat website. Just use the evaluation copies you can download for free. When you have downloaded the installation boot or dvd .iso, connect it to your VM via the CD/DVD hardware device. Next you will need to change the BIOS of your VM so that it boots the CD/DVD first. I used VMware Workstation to perform these steps, so first I had to convert the VM from our ESX server to a VMware workstation compatible format using VMware vCenter Converter Standalone. From VMware Workstation you can access the BIOS by selecting VM -> Power -> Power On to BIOS from the menu.

BIOS boot CD-ROM Drive

When the VM boots from the boot or installation .iso file, hit ‘Tab’ to change the boot command and append “rescue” to the end of the command so that it looks something like this:

> vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rd.live.check rescue
Boot RHEL 7.0 Rescue Mode

The rescue environment will attempt to find your Linux installation, but in my case that didn’t work and you shouldn’t worry about that, as long as you get a command prompt where you can enter the following commands to fix the BIOS boot partition:

First, determine the name of the disk that contains your Linux O.S. and /boot folder:

sh-4.2# fdisk -l

Then create a primary partition where you can install grub. Make sure this partition is created in front of your existing Linux partition:

sh-4.2# parted /dev/sda
(parted) unit s
(parted) p
(parted) mkpart primary 34 127
(parted) set 2 bios_grub on
(parted) q

Next update the UUID in the /etc/fstab file:

  1. Run the blkid command and identify the new UUID for the boot disk. Also, note the UUIDs of additional disk devices, if any.
  2. Edit the /etc/fstab file using a text editor
  3. Replace the UUIDs of the boot disk with the correct UUIDs identified in Step 1.
sh-4.2# blkid
sh-4.2# mount /dev/sda1 /mnt/sysimage
sh-4.2# vi /mnt/sysimage/etc/fstab

Now reboot again in rescue mode. The rescue procedure should be able to find your system and will mount it under /mnt/sysimage. Then perform the following commands to reinstall grub:

sh-4.2# chroot /mnt/sysimage
sh-4.2# /usr/sbin/grub2-install /dev/sda
sh-4.2# /usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg

If you now reboot the server from your disk (make sure to disconnect the CD-ROM from your VM first), the “Operating System not found error” should be gone. You will be asked to create a user and accept the license agreement. Once you have accepted this, enter q, the setup will complete and you can login using your ec2-user.

Author: Kristof Lievens