The Working with Templates section from the CloudStack Administrators Guide describes in broad strokes how to create OS templates. In addition to the steps mentioned there, you might need an extra step to update the hostname settings during DHCP depending on the Linux distribution.
For Ubuntu 12.04 LTS templates, remove the file
/etc/hostname before creating the template. On Debian 6/7 systems, create a new DHCP “exit hook” file
/etc/dhcp/dhclient-exit-hooks.d/hostname as below:
# Update hostname from DHCP
if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]; then
echo $new_host_name > /etc/hostname
No extra steps were needed for FreeBSD, CentOS 6 and SuSE Enterprise Linux templates.