`bootcmd`

* Runs very early in the boot process.
* Executes as root, before the network is set up.
* Best for low-level system setup, like modifying `/etc/fstab` and creating mount points.
* Runs once at the first boot.
* Executes before `cloud-init` sets up networking and users.
* Does not support environment variables or shell processing (for example, `~`, `$VAR` may not work).
* Commands run without a shell unless wrapped in `/bin/bash -c`.

Example:

```yaml
bootcmd:
  - mkdir -p /mnt/data
  - echo 'LABEL=data /mnt/data ext4 defaults,nofail 0 2' >> /etc/fstab

`runcmd`

* Runs later in the boot process, after networking is up and users are created.
* Also runs as root.
* Best for final application setup, such as installing packages, cloning repositories, and running scripts.
* Supports shell commands, variable expansion, and user environment.
* Runs once at the first boot.

Example:

yaml
runcmd:

 - apt-get update
  - apt-get install -y nginx
  - systemctl enable nginx
  - systemctl start nginx

Need Help With Cloud Development?

Work with our skilled Cloud developers to accelerate your project and boost its performance.

Hire Cloud Developers

Support On Demand!

Related Q&A