Chapter 5. Running first-boot commands by using cloud-init
You can execute commands during the first start-up and initialization of a virtual machine (VM) by using the runcmd and bootcmd sections of the cloud-init configuration.
-
The
bootcmdsection executes early in the initialization process and by default runs on every boot. -
The
runcmdsection executes near the end of the process and is only executed during the first boot and initialization.
Prerequisites
Depending on the requirements of your datasource, edit the
user-datafile or add the following directive to thecloud.cfg.ddirectory:NoteAll user directives include
#cloud-configat the top of the file so thatcloud-initrecognizes the file as containing user directives. When you include directives in thecloud.cfg.ddirectory, name the file*.cfg, and always include#cloud-configat the top of the file.
Procedure
Add the sections for
bootcmdandruncmd; include commands you wantcloud-initto execute.Copy to Clipboard Copied! Toggle word wrap Toggle overflow