Score:0

How do I run some commands when linux boots for the first time

cy flag

I want to run some system initialization commands if and only if the system is booting for the first time. Specifically, I want to generate identity keys and submit a CSR for signing. I want to do this only once so the identity cert will remain valid through reboots. I don't want to simply check the filesystem to see if the cert has already been created because if an attacker could write their own cert and keys to the boot image file(s) they could install their own identity.

My question is, How do I determine if Linux is booting for the first time?

Thanks,

in flag
It depends on the distribution used.
cn flag
Bob
The concept is generally: configure the system with a service/script that runs on every boot and have that check for a marker that is set after it completes the first full run. If that is not found, run the rest of the script, otherwise exit gracefully. Or the service/script disables/removes itself after completion . - [cloudinit](https://cloudinit.readthedocs.io/en/latest/) is a popular tool to initialize a system on (first) boot.
jp flag
If an attacker can write to your filesystem system then he can reset any markers of the first boot.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.