Log In | Register | June 25, 2017

Share
 

Linux - October 23, 2013

Create EBS AMI from Instance Store

So you’ve created an Instance Store backed AMI and now you’d like to change it into an EBS backed AMI.

I spent days looking trying to do this and pieced together several tutorials on how to accomplish this and came up with a simple tutorial.

What you will need:

  • Linux terminal
  • AWS command line tools, secret key, and private key (In my previous post I covered on how to set it up here is the link:
  • Your own custom AMI already created (I currently do not have a tutorial on this yet).

First launch an instance using your Instance Store AMI and then SSH into it.

Note: the reason why I prefer using my own custom AMI and not the default AWS ones is my own AMI has it’s own SSH/rc.local configuration. I don’t want to have to change all my configuration files in a default AMI.

Create a volume of 10GB and attach it. While I usually prefer using the command line tools in general for this I’ve actually just used the GUI.

Note: I used a separate terminal where I already had the AWS tools setup. You can set them up on the instance if you wanted to but that would also mean you’d have them setup in the AMI.

Here are the commands to create and attach a volume:

$ec2-create-volume --size 10 --availability-zone ZONE

$ec2-attach-volume VOLUME-ID --instance INSTANCE-ID --device /dev/sdf

Note: even though you specify /dev/sdf the volume will actually be /dev/xvdX. I know, it confused me as well.

Run $df -h to view your new volume and see how it was labeled. It should be /dev/xvdSOMETHING

Format the new volume:

$mkfs.ext4 /dev/xvdX

Create a new mount point:

$mkdir /mnt/ebs/

Mount the new volume to the new mount point:

$mount -t ext4 /dev/xvdX /mnt/ebs

Sync the root and dev directories to the new volume:

$rsync -avHx / /mnt/ebs

$rsync -avHx /dev/ /mnt/ebs

Label the disk, this is what I was missing originally. AWS has an unofficial tutorial that does not include this step.

$tune2fs -L '/' /dev/xvdX

Edit /mnt/ebs/fstab replace it with:

/dev/xvda1 / ext4 defaults 1 1

Edit /mnt/ebs/boot/grub.conf and change the root=label on the kernel line to:

root=/dev/xvda1

Note: I am not sure if the last two steps are needed. When I was creating my EBS AMI I had done this anyway, I have yet to test if it’s actually required. If it’s not feel free to let me know.

Flush all writes and unmount:

$sync;sync;sync;sync

$umount /mnt/ebs/

Detach the volume, again you can do this via command line or GUI. Command line method:

$ec2-detach-volume VOLUME-ID --instance INSTANCE-ID

Create a snapshot of the volume; this will generate a snapshot ID. You will need it to register it as a new AMI.:

$ec2-create-snapshot VOLUME-ID --description "Description of EBS"

Delete the volume:

$ec2-delete-volume VOLUME-ID

Register the new AMI:

$ec2-register --block-device-mapping /dev/sda1=snap-shot-ID::true --name "Name of AMI" --description "Description of AMI" --architecture x86_64 --kernel KERNEL-ID

It will give you your brand new AMI-ID.

Note: If you’d like the root partition to have more than 10GB in ec2-register command you can add the amount “snap-shot-ID::true“, such as:

snap-shot-ID:150:true

This will give the root partition 150GB. But you will then need to manually resize that volume using resize2fs /dev/xvda1. Always use df -h before and after to check your results.

And that’s it. Go ahead and launch a new instance using your brand new EBS AMI.

Final notes:

If you do not label your drive using tune2fs then your new instance will not be able to start up. Checking the logs you will receive an error /dev/disk-by/label not found. It was a pain to figure out why but I’m glad I did it.

Once again if you have suggestions or comments feel free to leave them.

Post By: | FavoriteLoadingAdd to favorites

6 Comments

国内即発 モノグラム
Saturday, October 31, 2015

回答|スパム発言?ので、どのようにあなたがしなければお勧めそれは、任意のプラグインや、あなたができるもの防ぐ? 非常識私は最近、それが私を駆動するのはそんなにを取得するので、任意の援助非常に高く評価されています。
国内即発 モノグラム http://alpsgroup.ru

おすすめ特別割引価格 国内即発
Saturday, October 31, 2015

あなたが持っている インターネットのウェブサイト|最高| |おそらく最良} {サイト|ウェブサイト|ウェブサイト|インターネットサイト|ウェブサイト|ウェブページ|オンラインのウェブサイト|オンラインサイト|ウェブページで最も印象的な|最大の。
おすすめ特別割引価格 国内即発 http://ridersinn.fi

国内即発 新作最低price
Saturday, October 31, 2015

この情報 価値のみんなの注目貴重です。 とき私はより多くを見つけることができますか?
国内即発 新作最低price http://www.cizginakis.com

ヤフオク トート 国内即発
Saturday, October 31, 2015

こんにちは |非常に良い、ニート ウェブサイト あなたが持っている現在|あり、現時点では|今|ここに行く|ここで|ここ|あなたはそこに持っている|あなたが得ている|あなたが持っている|あなたが持っています。
ヤフオク トート 国内即発 http://www.clevangile.org

レディース 人気 国内即発
Saturday, October 31, 2015

おかげための素晴らしい投稿! I 純粋それを読んで楽しんで、あなたがかもしれない偉大な著者であることが起こります。私は意志 ブックマークあなたのブログとよいと意志 ある時点で戻ってきます。週末|あなたの偉大な継続朝| 投稿、素敵夜!
レディース 人気 国内即発 http://primedenoel.fr

モノグラム 国内即発
Saturday, October 31, 2015

グループ群衆 役に立ち 仕事をともたらす配信発生 維持し続けてください!
モノグラム 国内即発 http://ciuinhouse.ie

Leave a Comment



Need Help? Ask a Question

Ask anything you want from how to questions to debug. We're here to help.

You Must Be Logged In To Post A Question.

Log In or Register