Mount the image. If the iamge is QEMU QCOW2 image, do the following.
sudo modprobe nbd max_part=63
sudo qemu-nbd -c /dev/nbd0 ~/precise-server-cloudimg-amd64
sudo mount /dev/nbd0p1 /mnt/myimage
Then you can change image contents from /mnt/myimage
, or through chroot /mnt/myimage
. Add a
/var/lib/cloud/scripts/per-instance
script to this image.
For ami Ubuntu image
curl --header 'x-auth-token:blah'
http://glance:9292/v1/images/uuid1
-o myimage
sudo mkdir /mnt/emi
sudo mount -o loop ~/myimage /mnt/myimage
sudo chroot /mnt/myimage
# Make changes
exit
sudo umount /dev/loop0