linux · openstack

openstack: modifying an image where you lost access

0 – Install python-openstaclient and unlock the access to the openstack where your VM is located.

1 – Download the image you want to modify


openstack image save <IMAGE_ID> --file=<NAME>.qcow2

2 – Install Qemu utils


sudo apt-get install qemu-utils

3 – Export the image to nbd. The first command loads the nbd kernel module. The “max_part=N” option specifies the maximum number of partitions we want to manage with nbd. The second command exports the specified disk image as a network block device (/dev/nbd0).


sudo modprobe nbd max_part=8
sudo qemu-nbd --connect=/dev/nbd0 /path/to/qcow2/image

4 – Check the list of nbd-mapped partitions, use fdisk:


$ sudo fdisk /dev/nbd0 -l

5 – choose any one partition (e.g., /dev/nbd0p1) and mount it to a local mount point (e.g., /mnt):


sudo mount /dev/nbd0p1 /mnt

6 – chroot /mnt

7 – do anything

8 – Once you are done, unmount it, and disconnect the disk image as follows.


$ sudo umount /mnt
$ sudo qemu-nbd --disconnect /dev/nbd0

9 – Submit the image to openstack again


openstack image create --public --file=<NAME>.qcow2 <NEW_NAME>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s