Improve auto hostname#1045
Merged
ricardosalveti merged 3 commits intofoundriesio:mainfrom Feb 16, 2023
Merged
Conversation
In our adapted lmp, we have removed "hostnamed" from "systemd", to
boot faster. By removing "hostnamed", the "hostnamectl" is not
available any more, which makes the "lmp-update-hostname.sh"
ineffective, because it uses "hostnamectl" to set the hostname.
It us useful to have a fall-back to change the hostname anyway, even
if the "hostnamectl" utility is absent.
Implemented the fallback: write to "/etc/hostname" directly, and set
the hostname with the "/usr/bin/hostname" command, instead of using
"hostnamectl".
References:
- [1] "systemd-hostnamed.service, systemd-hostnamed — Daemon to
control system hostname from programs"
<https://www.freedesktop.org/software/systemd/man/systemd-hostnamed.service.html#>
- [2] "Auto Hostname"
<https://docs.foundries.io/latest/user-guide/lmp-auto-hostname/lmp-auto-hostname.html>
Signed-off-by: Olivier L'Heureux <[email protected]>
Member
|
@olheureu thanks for your contribution, just one minor comment at the service file, but the other two patches are good. Nice improvements. |
fd259b2 to
18688b7
Compare
For our lmp-based embedded system, we want to use hostnames containing
serial numbers, we use thus the "Auto Hostname" feature [1]. "Auto
Hostname" installs an "lmp-auto-hostname.service" systemd service that
starts the "lmp-update-hostname.sh" script, which changes the
hostname.
As delivered, the service starts the script at every boot. This is not
needed, because the hostname change should be persistent, at least if
the "/etc/" directory is writable. Running the script at every boot
also slows down the boot, while fast boots is important for us.
Disabled the systemd service after the service has updated the
hostname, so that it runs only once.
References:
- [1] "Auto Hostname"
<https://docs.foundries.io/latest/user-guide/lmp-auto-hostname/lmp-auto-hostname.html>
Suggested-by: Ricardo Salveti <[email protected]>
Signed-off-by: Olivier L'Heureux <[email protected]>
The "Auto Hostname" feature [1] can set a hostname that contains the
device serial number. This serial number is fetched from the device
tree, from "/proc/device-tree/serial-number", or
"/sys/devices/soc0/serial_number", if it exists.
Our lmp-based embedded device has its serial number in the "fiovb"
secure environment, where it is safely provisioned. The device tree
contains the CPU serial number, but we prefer to use the device serial
number.
We want to extend the current "Auto Hostname" feature to use the
serial number from the "fiovb" secure environment. We want the "Auto
Hostname" implementation to stay generic: the use of a serial number
from the "fiovb" must stay optional, the default should stay from the
device tree, and the "fiovb" variable name should be a per-MACHINE
model parameter.
Implemented in "lmp-update-hostname.sh": if the "fiovb_printenv"
command exists and if the environment variable named "${FIOVB_VAR}" is
not empty, fetch the serial number from the "fiovb" secure environment
and use it in the host name.
Implemented in "lmp-auto-hostname.service.in": sets the "${FIOVB_VAR}"
environment variable to the content of the
"@@LMP_HOSTNAME_FIOVB_VAR@@" template.
Implemented in "lmp-auto-hostname_0.1.bb": when generating
"lmp-auto-hostname.service" from "lmp-auto-hostname.service.in",
replace the "@@LMP_HOSTNAME_FIOVB_VAR@@" template by the content of
the "${LMP_HOSTNAME_FIOVB_VAR}" Yocto variable, which is empty by
default.
The "${LMP_HOSTNAME_FIOVB_VAR}" Yocto variable could easily be
overloaded in a "lmp-auto-hostname_%.bbappend" recipe, to fetch the
serial number from a chosen "fiovb" variable.
References:
- [1] "Auto Hostname"
<https://docs.foundries.io/latest/user-guide/lmp-auto-hostname/lmp-auto-hostname.html>
Signed-off-by: Olivier L'Heureux <[email protected]>
18688b7 to
5fafff1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
3 commits that improves the "lmp-auto-hostname" feature [1]:
hostnamectl" is not available, with a fall-back to "/usr/bin/hostname".fiovb", instead of using the CPU serial number.References:
https://docs.foundries.io/latest/user-guide/lmp-auto-hostname/lmp-auto-hostname.html
https://docs.foundries.io/latest/user-guide/lmp-auto-hostname/lmp-auto-hostname.html