<div dir="ltr"><div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 12, 2024, 15:06 <<a href="mailto:mattwood2000@gmail.com" target="_blank">mattwood2000@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto">Hi,</div><div dir="auto"><br></div><div dir="auto">I have a system that needs to perform some tasks on first boot. I have this working for the most part but I had some general questions and would like some guidance on the proper implementation.</div><div dir="auto"><br></div><div dir="auto">The tasks I need to perform on first boot include changing the hostname, formatting some flash and mounting the filesystem, updating some config files, etc.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">If this is supposed to prepare the root filesystem, then the initramfs might be a good place as it always runs before anything in the rootfs does.</div><div dir="auto"><br></div><div dir="auto">(On the other hand, I've seen designs where the first boot goes to a completely different target and only after it's done it either reboots or switches to multi-user.target.)<br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"><br></div><div dir="auto">I found that if I put these tasks sequentially into single script /etc/hostname is updated and the hostname command returns the updated value, the hostname shown at login is still the old value.</div><div dir="auto"><br></div><div dir="auto">Now if I split tasks into individual services and order them with Before and After the hostname is correct at login.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">If you mean the banner shown *above* the "login:" prompt – that's shown by agetty, which is getty@tty1.service. It doesn't look at /etc/hostname, it looks at the kernel parameter that's set from /etc/hostname during early boot (before any services).</div><div dir="auto"><br></div><div dir="auto">So you need to update the kernel hostname using the `hostname` command, and you probably want to order your service before getty@tty1 (maybe before systemd-user-session.service).</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"><br></div><div dir="auto">I suspect this is because of systemd's parallelization and the monolithic script will not finish before the service or target that pulls in /etc/hostname, is that correct?</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">/etc/hostname is read *very* early – if I remember correctly, that's done by systemd itself before it starts any services at all. The rest of the system doesn't use that file but looks only at the kernel hostname.</div><div dir="auto"><br></div><div dir="auto">If you're changing it using the `hostname` command, then it mostly doesn't matter, as you're updating the same kernel parameter as systemd does.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"><br></div><div dir="auto">It is not clear to me what specific target or service my service needs to be set Before so that the script can finish.</div><div dir="auto"><br></div><div dir="auto">It also occurs to me that perhaps it makes more sense to split the tasks out so that they can run in parallel to optimize the boot, would this be the best practice?</div><div dir="auto"><br></div><div dir="auto">Thanks, Matt.</div></div>
</blockquote></div></div></div>
</div>