Skip to content

Instantly share code, notes, and snippets.

@s3u
Last active August 29, 2015 13:56
Show Gist options
  • Save s3u/8903689 to your computer and use it in GitHub Desktop.
Save s3u/8903689 to your computer and use it in GitHub Desktop.

Mouting an Image for Modifications

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment