0

I am trying to create an AMI from the raw images here:

http://cloud-images.ubuntu.com/releases/xenial/release/ubuntu-16.04-server-cloudimg-amd64.tar.gz

Here are the steps I'm taking:

  1. Log into existing Ubuntu instance
  2. Create, attach and mount the EBS volume
  3. Download and extract image from cloud-images.ubuntu.com

4. dd extracted image to attached volume /dev/xvdf

time sudo dd if=cloudimg-amd64.img of=/dev/xvdf conv=sync,noerror bs=1M
  1. Detach volume, snapshot volume, create ami from snapshot

When I try to launch the AMI it fails with hard disk not bootable.

In addition to the above also tried using ec2-import-instance

  ec2-import-instance --architecture x86_64 --platform Linux --bucket mybucket --volume-size 5 --availability-zone us-east-1d -O ID-REMOVED -W ID-REMOVED -o ID-REMOVED -w ID-REMOVED --instance-type t2.micro --format raw xenial.img  --subnet subnet-12345678

but it appears --format raw actually doeesn't mean what it says, it doesn't create a bootable AMI and fails with

 Client.Unsupported: No valid MBR found. Please verify your image.

So how can I manually make a volume bootable (or create an AMI) from a raw image obtained from cloud-images.ubuntu.com?

Note: I need to be able to do this from the RAW EC2 images at cloud-images.ubuntu.com, copying existing AMI's is not an option.

I also tried aws ec2 import-image method, that doesn't work either for any format.

Corsterix
  • 43
  • 8
  • *"copying existing AMI's is not an option"* Well, that doesn't seem to make sense. What do you think [these **official Ubuntu** AMIs](https://cloud-images.ubuntu.com/locator/ec2/) are? They're what you're trying to do, built by Ubuntu engineers. – Michael - sqlbot Apr 29 '17 at 21:52
  • For starters I want to reduce the image size, so yes it's not an option because you can't reduce the size of an existing AMI, you can only launch the same or larger size. Secondly, I will have custom raw images, I'm just using the official ones for testing right now. – Corsterix Apr 29 '17 at 22:25
  • You should clarify the question. It seems like you have some valid reasons, which was not at all initially apparent. Your question, as it stands now, is venturing into the fringes of [XY](http://xyproblem.info) territory, because it is not about your actual (ultimate goal) problem, but about a single step in yout attempted solution, and the specifics are likely a distraction to others as they were to me. Help is best provided when the full picture is available. – Michael - sqlbot Apr 30 '17 at 01:06
  • It's true, you can't directly reduce the image size, but I believe there are is a workaround involving detaching the boot volume, attach it elsewhere, shrink the filesystem, repartition to match (with unpartitioned space at the end), `dd` the result onto a new, smaller EBS volume, attach that, and boot -- you should be able to create a new, smaller AMI from the resulting machine. – Michael - sqlbot Apr 30 '17 at 01:07
  • You're right, the question wasn't very clear because that's what happens with no sleep, two kids causing hell and a migraine. Next time I'll get divorced, ditch the kids, take painkillers and hire a masseur. – Corsterix May 01 '17 at 00:53

1 Answers1

2

I solved this by using the Amazon CLI, specifically this command:

 aws ec2 import-snapshot

Then I created a volume with a bootable partition and copied the snapshot to it.

RAW images must be imported as snapshots.

Corsterix
  • 43
  • 8
  • Hi @user2001109, Can you please eloborate the steps. I am also trying to create AMI from OS disk image, but I am getting error while booting EC2 instance : "Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(8,0)" Please go through my question https://stackoverflow.com/questions/50505025/changes-required-to-create-ami-from-os-disk-ebs-volume-manually – Subbu May 24 '18 at 09:01