Prepare Virtual Machine
Install OS on VMware or VirtualBox
Startup OS, delete the symbolic link of grubenv, then copy the real grubenv file here, like this:
cd /boot/grub2/
rm –f grubenv
cp /boot/efi/EFI/centos/grubenv ./
Export VM and Upload into AWS
Shutdown OS, export image using OVA type.
Login AWS console, then upload this OVA image into S3 bucket, for example: vm-import
Create vmimport role
aws iam create-role --role-name vmimport \
--assume-role-policy-document file://trust-policy.json
Here is the content of trust-policy.json
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"",
"Effect":"Allow",
"Principal":{
"Service":"vmie.amazonaws.com"
},
"Action":"sts:AssumeRole",
"Condition":{
"StringEquals":{
"sts:ExternalId":"vmimport"
}
}
}
]
}
- Edit policy for vmiport
aws iam put-role-policy --role-name vmimport \
--policy-name vmimport \
--policy-document file://role-policy.json
Here is the content of role-policy.json
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource":[
"arns3:::vm-import"
]
},
{
"Effect":"Allow",
"Action":[
"s3:GetObject"
],
"Resource":[
"arns3:::vm-import/*"
]
},
{
"Effect":"Allow",
"Action":[
"ec2:ModifySnapshotAttribute",
"ec2:CopySnapshot",
"ec2:RegisterImage",
"ec2:Describe*"
],
"Resource":"*"
}
]
}
- Do the import task:
aws ec2 import-image --cli-input-json '
{
"Description": "OS OVA",
"DiskContainers": [
{
"Description": "CLI Task",
"UserBucket":
{
"S3Bucket": "vm-import",
"S3Key" : "os.ova"
}
}
]
}
'
Here, os.ova is the name of vmware image which has been uploaded to s3.
vm-import is the name of s3 bucket which restores vmware image.
- Use this command to monitor the import process.
When it shows like this, it means successful.
aws ec2 describe-import-image-tasks
{
"ImportImageTasks": [
{
"Status": "completed",
"LicenseType": "BYOL",
"Description": "OS OVA",
"ImageId": "ami-a440a5c4",
"Platform": "Linux",
"Architecture": "x86_64",
"SnapshotDetails": [
{
"UserBucket": {
"S3Bucket": "vm-import",
"S3Key": "os.ova"
},
"SnapshotId": "snap-abcd2e33",
"DiskImageSize": 974067200.0,
"DeviceName": "/dev/sda1",
"Format": "VMDK"
}
],
"ImportTaskId": "import-ami-ffik6b4s"
}
]
}