Creating an Ubuntu EBS-backed EMI from an Existing Instance Store-Backed Instance

Follow

Eucalyptus Versions:  3.3.x to Latest

Creating an Ubuntu EBS-backed EMI from an Existing Instance Store-Backed Ubuntu Instance

There are different types of image management that can be performed on Eucalyptus.  This knowledge base will cover how to copy the contents of an instance store-backed instance onto an EBS volume, and create an EBS-backed EMI.  This type of image management is helpful for images that are application specific (e.g. database server, web application server, etc.).  

Prerequisites

This knowledge base article assumes that an instance store-backed instance is based off a previously registered Ubuntu Cloud instance store-backed EMI [1].  For a list of Ubuntu Cloud images, please check out the Ubuntu Cloud Images web site.  The Ubuntu cloud image Ubuntu 14.04 LTS Trusty Tahr, will be used in this article.  We recommend using Ubuntu LTS images for production image deployment on Eucalyptus.

This article also assumes that the following IAM policy EC2 actions are applied to the user account that will be creating the EBS-backed EMI:

For additional information regarding Eucalyptus IAM, please refer to our Eucalyptus 3.4 Administration Guide [2].

Each euca-* command ran in this article is set to use the euca2ools configuration file. For more information regarding how to set up the euca2ools configuration file, please refer to the Euca2ools Guide.

EBS-backed EMI Creation

Once the Ubuntu instance-store backed instance is up and running.  Create a volume, and attach it to the instance.  For example:

$ euca-create-volume --size 10 --availability-zone LayinDaSmackDown --region account1-user01@
$ euca-describe-volumes vol-9C014652 --region account1-user01@ 
VOLUME vol-9C014652 10 LayinDaSmackDown available 2014-04-06T15:32:33.410Z standard
$ euca-attach-volume --instance i-DC594471 --device /dev/sdd vol-9C014652 --region account1-user01@

After attaching the volume, SSH into the instance, and confirm the volume has been attached:

$ ssh -i account1-user01.priv ubuntu@euca-10-104-7-11.eucalyptus.euca-hasp.eucalyptus-systems.com
ubuntu@euca-172-17-112-252:~$ sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 15G 0 disk
├─vda1 253:1 0 1.4G 0 part /
├─vda2 253:2 0 13.1G 0 part
└─vda3 253:3 0 512M 0 part
vdb 253:16 0 10G 0 disk

Use the parted [3] program to set up a partition table and create a new partition on the block device /dev/vdb:

ubuntu@euca-172-17-112-252:~$ sudo parted --script /dev/vdb mklabel msdos mkpart primary 0% 100% set 1 boot on
ubuntu@euca-172-17-112-252:~$ sudo parted /dev/vdb print
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 10.7GB 10.7GB primary boot

Next, format /dev/vdb to the filesystem of your choice. Make sure and set the label for the device to 'cloudimg-rootfs'.  

ubuntu@euca-172-17-112-252:~$ sudo mkfs.ext4 -L cloudimg-rootfs /dev/vdb1
mke2fs 1.42.8 (20-Jun-2013)
Filesystem label=cloudimg-rootfs
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621184 blocks
131059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Create a directory for mounting the block device, and mount the block device:

ubuntu@euca-172-17-112-252:~$ sudo mkdir /mnt/ubuntu-ext4
ubuntu@euca-172-17-112-252:~$ sudo mount /dev/vdb1 /mnt/ubuntu-ext4

Set the maximum mount count to 0 for the device to keep e2fsck [4] from running when the image is launched.

ubuntu@euca-172-17-112-252:~$ sudo tune2fs -c -1 /dev/vdb1
tune2fs 1.42.8 (20-Jun-2013)
Setting maximal mount count to -1

Copy of the contents from the root filesystem of the instance to the volume:

ubuntu@euca-172-17-112-252:/$ cd /; sudo find . -xdev -print0 | grep --invert-match /mnt/ubuntu-ext4 | sudo rsync --one-file-system --archive --verbose --compress . /mnt/ubuntu-ext4

Remove the udev rule 70-persistent-net.rules on the volume to make sure the image grabs the correct network information when being launched:

ubuntu@euca-172-17-112-252:/$ sudo rm --recursive --force /mnt/ubuntu-ext4/etc/udev/rules.d/70-persistent-net.rules

Use grub-install [5] to install and upgrade grub2 on the EBS volume:

ubuntu@euca-172-17-112-252:/$ sudo grub-install --boot-directory=/mnt/ubuntu-ext4/boot /dev/vdb
Installation finished. No error reported.

Unmount the volume and logout of the instance.

ubuntu@euca-172-17-112-252:/$ sudo umount /mnt/ubuntu-ext4
ubuntu@euca-172-17-112-252:/$ exit
logout
Connection to euca-10-104-7-11.eucalyptus.euca-hasp.eucalyptus-systems.com closed.

Detach the volume, and create a snapshot of the volume:

$ euca-detach-volume vol-93F2430D --region account1-user01@
ATTACHMENT  vol-93F2430D  i-DC594471/dev/sdd  detaching  2014-04-07T15:29:54.048Z
$ euca-describe-volumes vol-93F2430D --region account1-user01@
VOLUME vol-93F2430D 10 LayinDaSmackDown available 2014-04-07T15:02:29.655Z standard
$ euca-create-snapshot vol-93F2430D --region account1-user01@
SNAPSHOT snap-E4F03E68 vol-93F2430D pending 2014-04-07T16:17:35.183Z 961915002812 10

Once the snapshot has completed, register the EBS-backed EMI:

$ euca-describe-snapshots snap-E4F03E68 --region account1-user01@
SNAPSHOT snap-E4F03E68 vol-93F2430D completed 2014-04-07T16:17:35.183Z 100% 961915002812 10
$ euca-register --name ubuntu-trusty-x86-64-ebs-hvm --snapshot snap-E4F03E68 --root-device-name /dev/sda --region account1-user01@
IMAGE emi-307548F2

An Ubuntu EBS-backed EMI has been successfully created from an existing Ubuntu instance-store backed instance.  The EMI can now be used to launch an instance.

$ euca-run-instances --key account1-user01 --instance-type m1.medium emi-307548F2 --region account1-user01@

To troubleshoot the instance launched from the EBS-backed EMI, use euca-get-console-output [6] to get the kernel log messages from the instance.

Troubleshooting Example

Below is an example using euca-get-console-output to triage an EBS-backed instance:

# euca-get-console-output i-89e19f29
i-89e19f29

^[[1;256r^[[256;256H^[[6n
Google, Inc.
Serial Graphics Adapter 12/07/11
SGABIOS $Id: sgabios.S 8 2010-04-22 00:03:40Z nlaredo $ (mockbuild@c6b18n1.dev.centos.org) Wed Dec 7 17:04:47 UTC 2011
Term: 80x24
4 0
SeaBIOS (version seabios-0.6.1.2-28.el6)
Machine UUID 882f0525-c5a9-0ffe-135f-474df62dc721

gPXE (http://etherboot.org) - 00:03.0 C100 PCI2.10 PnP BBS PMM3FE0@10 C100


Booting from Hard Disk...
error: no such device: 449e499f-a870-41d1-bbf1-54e620df435c.
.....
.....
Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done.
Gave up waiting for root device. Common problems:
- Boot args (cat /proc/cmdline)
- Check rootdelay= (did the system wait long enough?)
- Check root= (did the system wait for the right device?)
- Missing modules (cat /proc/modules; ls /dev)
ALERT! /dev/disk/by-uuid/449e499f-a870-41d1-bbf1-54e620df435c does not exist. Dropping to a shell!


BusyBox v1.22.1 (Ubuntu 1:1.22.0-9ubuntu1) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs) ^[[6n

In the console output, it can be observed that the device with the UUID of 449e499f-a870-41d1-bbf1-54e620df435c can't be discovered, therefore, the instance fails to boot properly.  To resolve this issue, do the following:

  1. Terminate the failed instance
  2. Deregister the EBS-backed EMI
  3. Delete the snapshot used to create the EBS-backed EMI
  4. Re-attach the volume to the instance
  5. Once the volume is attached, use 'tune2fs' to set the UUID of the root device on the volume to the UUID stated in the console output.  For example:
$ sudo tune2fs -U 449e499f-a870-41d1-bbf1-54e620df435c /dev/vdb1

Once thats been completed, detach the volume, and follow the steps to recreate the EBS-backed EMI. 

References

[1] Ubuntu Cloud Images and Eustore: The Eucalyptus Cloud Administrator’s Image Management Dream 
[2] Eucalyptus 3.4 Administration Guide - Policy Overview
[3] Ubuntu Manpage - Trusty Tahr 14.04 - parted
[4] Ubuntu Manage - Trusty Tahr 14.04 - e2fsck
[5] Ubuntu Manpage - Trusty Tahr 14.04 - grub-install
[6] Euca2ools Guide - EC2-Compatible Commands - euca-get-console-output

 

 

 

Have more questions? Submit a request

Comments

Powered by Zendesk