Debian provides standard images designed for OpenStack, but sometimes is better to use your own images, with local modifications or with specific packages installed and configured. One way to achieve this is to create a snapshot from a running instance previously launched from a standard image. In this post we’re going to create a new image from a running instance, explaining the modifications needed in one specific use case: Create a Debian Stretch image from a running Debian Jessie instance.
Upgrading to Stretch
This is the easiest step, just proceed as usual:
- Launch and log into the debian jessie instance
- Modify properly the repositories
- Upgrade to stretch
Once the instance is upgraded to stretch some debian specific changes must be made:
The first change is related to cloud-init package, because at this moment stretch’s cloud-init doesn’t work with OpenStack metadata server due to the Openstack Data Source is not selected by default, so it’s necessary to reconfigure this package:
dkpg-reconfigure cloud-init (enable OpenStack)
The second change is related to the bootloader. OpenStack debian images use EXTLINUX as bootloader and the new kernel is not automatically added to it when the linux-image package is upgraded. There are two alternatives: reinstall EXTLINUX with the new Stretch kernel or install GRUB as bootloader. I prefer the second option, so just install grub:
apt install grub2
The problem now is that grub doesn’t dump the log to console.log, see console.log is empty, what to do? and GRUB must be properly modified, so edit /etc/default/grub and add the line:
Finally, reinstall grub and reboot the instance to verify that the instance boots correctly, the console output is dumped to console.log and the latest kernel is used.
It’s important to clean properly the instance before use it as a new image, in particular the public ssh key of the user running the instance must be deleted:
echo "" > /home/debian/authorized_keys
We want the image to be as light as possible, so uninstall jessie kernel, clean the apt cache and remove any unnecessary file.
When the instance is properly configured, just take a snapshot and download it with glance CLI, for example:
$ glance image-download --file debian-stretch.qcow2 871d1656-3bb5-4cdd-96a8-cbfb969ee4e4
Where 871d1656-3bb5-4cdd-96a8-cbfb969ee4e4 is the UUID associated with the snapshot.
This image is bigger, maybe much bigger, than the original one, so I recommend you to read the post Shrinking qcow2 images explaining how to reduce the image size and allowing to use it efficiently.
And the final step is performed uploading the image as usual and verifying that it works properly.