Customize PXE installation with Curtin

Curtin is one way to easily customize servers installed by MAAS.

Relying on customization using Curtin should probably be limited to exceptional cases: however, if you are sure you’ll need some simple tweak on ALL your hosts, please go ahead with Curtin.

Curtin files

Curtin files reside in /etc/maas/preseeds/ and are called like:

$ curtin_userdata_OStype_OSarch_OSversion_OSname_Hostname

or, to make an example:

$ curtin_userdata_ubuntu_amd64_generic_xenial_ct1-r2-s01

where ct1-r2-s01 is the name of a server as defined within MAAS

You will easily find several files in Curtin preseeds directory: during boot, the most specific one will be tried first, then the more generic ones, by stripping part of the filenames until a match is found. So, in our example, the following files will be tried in order:

$ curtin_userdata_ubuntu_amd64_generic_xenial_ct1-r2-s01
$ curtin_userdata_ubuntu_amd64_generic_xenial
$ curtin_userdata_ubuntu_amd64_generic
$ ...

Each file is composed of several sections, most probably you will want to edit the late_commands one, containing commands which are executed right before finishing the installation and rebooting the server.

Remember that Curtin runs during first installation of a server. Hence you need to distinguish whether your action should be performed in the current shell (the one which is installing your server) or in the environment of the installed machine. Most probably, the latter is the one you need.

The format of each action specified in a Curtin file is as follows:

$ someString: ["the", "command", "to be", "executed"]

If the command needs to be executed in the shell of the installed host, the line takes the form:

$ someString: ["curtin", "in-target", "--", "the", "command", "to be", "executed"]

Examples

Examples of commands to be run in the current shell can be found in the early_commands section of the default files.

So, we focus here only on late_commands to be executed in the shell of the server which is being installed. Here are a couple examples:

$ package_01_update_install: ["curtin", "in-target", "--", "sh", "-c", "apt-get update --quiet && apt-get --assume-yes install python"]
$ sysctl_01_add: ["curtin", "in-target", "--", "sh", "-c", "/bin/echo 'fs.inotify.max_queued_events = 1048576' >> /etc/sysctl.conf "]

Further examples can be found in our Gitlab snippet repository.