Skip to content

Allow setting hostname before userspace starts

Dan Moulding linux-doc lkml 2 versions – Applied

Status from this message: [merged mm-nonmm-stable] init-add-hostname-kernel-parameter.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest1 patch 2 repliesApplied 1/1
  2. v11 patch 0 repliesSuperseded

Changes in v2 from the cover letter

* Use strlcpy instead of strncpy to eliminate W=1 compiler warning (assuaging it from its string truncation fears). Thanks to kernel test robot for finding this.
* Move "hostname" after "hlt" in kernel-parameters.txt (I promise I know my ABCs).

Patches in v2 All 1 applied

#Subject and filesSizeRepliesApplied
1/1init: Add "hostname" kernel parameterDocumentation/admin-guide/kernel-parameters.txt init/version.c+30 -00 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/1] Allow setting hostname before userspace starts

Some userspace processes may rely on gethostname to always return the correct machine name. However, the only way that the hostname may be set is by some other userspace process calling sethostname first. During boot, if a process that depends on gethostname runs before sethostname has been called, then the process that called gethostname is going to get an incorrect result.

A real-world case where this comes up is with mdadm, which if gethostname returns the wrong name, can cause local md-raid arrays to appear to be foreign arrays. This can alter how mdadm assembles the array, or can even cause array assembly to fail. I imagine there are probbaly other real-world cases where undesirable behavior results when the hostname is not set early enough.

I'm proposing adding the option to set the hostname from a kernel parameter, so that the correct host name can be guaranteed to be set before any userspace process can call gethostname.

I can imagine an even better way to do this would be to have the hostname written to some non-volatile storage (like a firmware NVRAM variable or such), which the kernel could read out during early boot. But, alas, such designs require hardware support, standards, and cooperation. This proposal is an alternative that can provide a simple and immediate solution.

v2:
* Use strlcpy instead of strncpy to eliminate W=1 compiler warning (assuaging it from its string truncation fears). Thanks to kernel test robot for finding this.
* Move "hostname" after "hlt" in kernel-parameters.txt (I promise I know my ABCs).

Dan Moulding (1):
init: Add "hostname" kernel parameter

 Documentation/admin-guide/kernel-parameters.txt | 13 +++++++++++++
 init/version.c                                  | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)
Signature · 1 line
2.35.1