TL;DR: a working and validated Debian 8 (Jessie) template is available here if you want.
Let's create a new VM. The trivial way is to use the "Other install media". Put a Debian 8 ISO, netinstall is a good option.
CPU, RAM and even disk size could be changed later, so no worries with that now. Just click on Create VM.
Disk size could be only extended in the future, so it's better to create a small template (4 GiB is enough).
First, when you need to fill the username, use "debian"
To allow future disk growing, you need to create only one partition on the disk:
Before setting CloudInit, you can install XenServer Xen Tools: this way, they will be shipped with your template.
Like any normal tool installation:
- Mount the XS Tool ISO
mount /dev/cdrom /mnt
dpkg -i /mnt/Linux/xe-guest-utilities_6.5.0-1427_amd64.deb
- eject the ISO
Let's install everything to have a CloudInit ready VM.
But first, we'll install sudo:
$ apt-get install sudo
$ apt-get install cloud-init cloud-initramfs-growroot
Growroot package will allow to extend your template if necessary.
The main configuration file for CloudInit is inside
/etc/cloud/cloud.cfg. Almost all default parameters are OK, just modify some of them, like this one:
preserve_hostname: false ssh_deletekeys: true
It's indicating that existing ssh keys should be deleted on a per-instance basis. On a public image, this should absolutely be set to 'True'.
We'll also add a
sudo without password, by editing this section at the end of the file:
default_user: name: debian lock_passwd: True gecos: Debian groups: [adm, audio, cdrom, dialout, floppy, video, plugdev, dip] sudo: ALL=(ALL) NOPASSWD:ALL
This configuration will have:
- a default user "debian", with
sudowithout password. Makes sense for a cloud image (it replaces the root user).
- growpart working (extend the FS if the disk is larger than the current partition)
- disabled SSH password authentication (only SSH keys)
- root disabled
- and a lot of other things, you can find documentation here
Let's use only the CloudInit source needed in our case:
$ dpkg-reconfigure cloud-init
Uncheck everything but "OpenStack Config Drive":
And now, let's remove any possible root access:
$ passwd -l root
You're good! You can halt the VM. You won't be able to login anymore with this one, except by using CloudInit from now.
The easiest part, on the halted VM view:
Now, if you go inside the VM creation page:
Then, activate the config drive and give your SSH key:
Want the new VM bigger than the existing template? No problem, edit the root disk size (template disk was 4 GiB originally):
Now start the VM and SSH on its IP, it just works!
This template is very generic. For your own needs, remember that you can install anything inside it, like a better bashrc file to have a fancy prompt, Git, Docker, etc.
Download the template
This template (with Xen Tools) is available here:
- Download link
- MD5 sum: e1c8d3fabe00edf2b9b2af3899b5e920
And import it:
It will appears in the template list!
If you want templates for other distros, just tell us in the comment section :)