Creating an image from an existing VM (CentOS)
These instructions are largely taken from the forum post Creating image from existing VM but geared towards CentOS.
-
Run an instance of the image.
-
You need to make sure you have enough space on your instance to create your new image. You'll have to attach some more storage according to the instructions at Interacting with Block Storage. My image was 2 GB in size (but not all of it was used) so I created a 2GB volume.
-
Once the volume is attached you need to make a file system on it and mount it to /mnt. We're using KVM so it got attached to /dev/vdb.
mkfs -t ext3 /dev/vdb
mount /dev/vdb /mnt
-
SCP your Eucalyptus credential bundle (i.e., euca2-xxxxx-x509.zip) to the /mnt dir of the instance:
scp -i yourkey.private euca2-xxxxxxx-x509.zip root@xxx.xxx.xxx.xxx:/mnt
-
SSH into the instance:
ssh -i yourkey.private root@xxx.xxx.xxx.xxx
- Install some necessary tools for later:
yum install rsync unzip
-
Change to the /mnt device (it should have enough space to create new image bundle):
cd /mnt
-
Unzip your Eucalyptus credentials zip to /mnt/euca:
unzip euca2-admin-x509.zip -d euca/
-
Follow the instructions for Installing Euca2ools on CentOS 5
-
Install any other software you want on instance so it will be part of your new image.
-
Source your Eucalyptus script:
. /mnt/euca/eucarc
-
Bundle the image:
euca-bundle-vol -c ${EC2_CERT} -k ${EC2_PRIVATE_KEY} -u ${EC2_USER_ID} --ec2cert ${EUCALYPTUS_CERT} --no-inherit --kernel eki-KKKKKKKK --ramdisk eri-RRRRRRRR -d /mnt -r ARCH -p NEW_IMAGE_NAME -s SIZE_IN_MBs -e /mnt,/root/.ssh,OTHER_DIRS_TO_EXCLUDE
eki-KKKKKKKK -> same as with running instance
eri-RRRRRRRR -> same as with running instance
For example:
euca-bundle-vol -c ${EC2_CERT} -k ${EC2_PRIVATE_KEY} -u ${EC2_USER_ID} --ec2cert ${EUCALYPTUS_CERT} --no-inherit --kernel eki-47C7126D --ramdisk eri-80991354 -d /mnt -r x86_64 -p new.centos.5-3.x86-64.2GB.img -s 2048 -e /mnt,/root/.ssh
-
Upload the bundle:
euca-upload-bundle -b BUCKET_NAME -m /mnt/NEW_IMAGE_NAME.manifest.xml
- I got a "You do not have permission to access bucket: BUCKET_NAME" error at this point. After hunting around the forums to fix it I just did:
yum install -y ntp
ntpdate pool.ntp.org
-
Register the bundle:
euca-register BUCKET_NAME/NEW_IMAGE_NAME.manifest.xml