Yes, that is certainly possible. E.g., given the following cloud-config:
#cloud-config
bootcmd:
- echo 'Starting foreground sleep' >> /var/tmp/log
- date +%s >> /var/tmp/log
- sleep 5
- date +%s >> /var/tmp/log
- echo 'Starting background sleep' >> /var/tmp/log
- date +%s >> /var/tmp/log
- sleep 10 &
- date +%s >> /var/tmp/log
I get this kind of result:
cat /var/tmp/log
Starting foreground sleep
1613538543
1613538548
Starting background sleep
1613538548
1613538548
Increasing the background sleep has no effect on the amount of time it takes cloud-init to finish. A background wget
should work similarly.
That said, this isn't really what bootcmd
was designed for. If you check the cloud-init docs, it specifies that bootcmd should only be used for things that could not be done later in the boot process
. Some fairly major setup tasks (including disk setup) can still happen after bootcmd
runs, so starting some large downloads that early during boot may not be a wise choice.
The runcmd
module should run before any of the apt installs. You can verify with cloud-init analyze show
on your cloud instance. Unless you have a really good reason to use bootcmd
, you should probably just stick with runcmd
.