Now, if you’ve ever tried to set up a server with Ubuntu before, you know it can be a bit of a headache. No worries, though, because Curtin is here to save the day!
First things first: what exactly is Curtin? Well, its an installer that assumes the thing it’s installing is intelligent and will do the right thing. It doesn’t rely on package-based installers like most other Linux distros out there. Instead, it takes data from a source and gets it onto disk as quickly as possible before booting up the new system.
Now, lets talk about the stages that Curtin goes through during installation:
1) Install Environment boot This is where you’ll be running your commands in a rich Linux environment (Ubuntu, to be specific). You can load modules or set up hardware and environment variables for subsequent stages.
2) Early Commands These are executed on the system before any other stage begins. Theyre intended to help with module loading, hardware setup, and environment setup for subsequent stages of Curtin. If you have a command that needs to be run early in the installation process, just add it here!
3) Partitioning This is where filesystems are set up on your system. A series of commands will be executed serially until fstab formatted file has been populated and filesystems mounted at TARGET_MOUNT_POINT. Curtin provides some tools to facilitate this process, but you can use any command that suits your needs.
4) Network Discovery This is where networking configuration is discovered in the network stage. The default command run here is curtin net-meta auto. After execution, it will write the discovered networking information to a file specified in OUTPUT_NETWORK_CONFIG. If you have a network section in your config, its data will be parroted to this output file. Otherwise, existing configuration from the running environment will be copied over.
5) Final Commands These are executed after all other stages have completed. You can add any final commands that need to be run here!
6) Configuring cloud-init and installing openssh-server (optional) This is where you’ll configure cloud-init and install openssh-server if needed.
7) Restoring apt configuration and downloading security updates (optional) If you have any specific packages that need to be installed or updated, this is the stage for you!
8) Reboot And finally, after all other stages are complete, it’s time to reboot your system.
Now, lets talk about some examples of how Curtin can be used in practice:
Example 1: Early Commands
Let’s say you want to load a module and update the package list before any other stage begins. Here’s what that might look like:
# This script is used to demonstrate how Curtin can be used in practice to execute early commands before any other stage begins.
# First, we define the early_commands section to specify the commands that need to be executed before other stages.
early_commands:
# The following command loads the loop module.
05_load_loop: [modprobe, loop]
# The following command updates the package list and performs a distribution upgrade.
99_update: apt-get update && apt-get dist-upgrade
Example 2: Partitioning
Let’s say you want to wipe all unused disks and set up RAID on /. Heres what that might look like:
# This script is used for partitioning and setting up RAID on unused disks.
# First, we need to wipe all unused disks using the curtin wipe command.
# The --quick flag ensures a fast wipe, while the --all-unused-disks flag targets all unused disks.
curtin wipe --quick --all-unused-disks
# Next, we use the curtin disk-setup command to set up RAID on all disks and mount it on the root directory (/).
# The raid0 option specifies the type of RAID we want to set up, and the / indicates the mount point.
curtin disk-setup --all-disks raid0 /
Example 3: Final Commands
Let’s say you want to call home and let everyone know that the installation is complete. Heres what that might look like:
# This section contains the final commands to be executed after the installation is complete
final_commands:
# This command is used to call home and notify everyone that the installation is finished
05_callhome_finished: wget http://example.com/i-am-done
And there you have it, Curtin’s Install Environment boot and Commands. It may be a bit tricky to set up at first, but trust us once you get the hang of it, your server installations will be a breeze!