acrn-kernel/Documentation
Dan Moulding 5a704629f2 init: add "hostname" kernel parameter
The gethostname system call returns the hostname for the current machine. 
However, the kernel has no mechanism to initially set the current
machine's name in such a way as to guarantee that the first userspace
process to call gethostname will receive a meaningful result.  It relies
on some unspecified userspace process to first call sethostname before
gethostname can produce a meaningful name.

Traditionally the machine's hostname is set from userspace by the init
system.  The init system, in turn, often relies on a configuration file
(say, /etc/hostname) to provide the value that it will supply in the call
to sethostname.  Consequently, the file system containing /etc/hostname
usually must be available before the hostname will be set.  There may,
however, be earlier userspace processes that could call gethostname before
the file system containing /etc/hostname is mounted.  Such a process will
get some other, likely meaningless, name from gethostname (such as
"(none)", "localhost", or "darkstar").

A real-world example where this can happen, and lead to undesirable
results, is with mdadm.  When assembling arrays, mdadm distinguishes
between "local" arrays and "foreign" arrays.  A local array is one that
properly belongs to the current machine, and a foreign array is one that
is (possibly temporarily) attached to the current machine, but properly
belongs to some other machine.  To determine if an array is local or
foreign, mdadm may compare the "homehost" recorded on the array with the
current hostname.  If mdadm is run before the root file system is mounted,
perhaps because the root file system itself resides on an md-raid array,
then /etc/hostname isn't yet available and the init system will not yet
have called sethostname, causing mdadm to incorrectly conclude that all of
the local arrays are foreign.

Solving this problem *could* be delegated to the init system.  It could be
left up to the init system (including any init system that starts within
an initramfs, if one is in use) to ensure that sethostname is called
before any other userspace process could possibly call gethostname. 
However, it may not always be obvious which processes could call
gethostname (for example, udev itself might not call gethostname, but it
could via udev rules invoke processes that do).  Additionally, the init
system has to ensure that the hostname configuration value is stored in
some place where it will be readily accessible during early boot. 
Unfortunately, every init system will attempt to (or has already attempted
to) solve this problem in a different, possibly incorrect, way.  This
makes getting consistently working configurations harder for users.

I believe it is better for the kernel to provide the means by which the
hostname may be set early, rather than making this a problem for the init
system to solve.  The option to set the hostname during early startup, via
a kernel parameter, provides a simple, reliable way to solve this problem.
It also could make system configuration easier for some embedded systems.

[dmoulding@me.com: v2]
  Link: https://lkml.kernel.org/r/20220506060310.7495-2-dmoulding@me.com
Link: https://lkml.kernel.org/r/20220505180651.22849-2-dmoulding@me.com
Signed-off-by: Dan Moulding <dmoulding@me.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-07-17 17:31:37 -07:00
..
ABI 1st set of IIO fixes for the 5.19 cycle. 2022-06-20 09:49:52 +02:00
PCI
RCU
accounting
admin-guide init: add "hostname" kernel parameter 2022-07-17 17:31:37 -07:00
arc
arm docs: arm: tcm: Fix typo in description of TCM and MMU usage 2022-06-09 12:56:33 -06:00
arm64
block
bpf
cdrom
core-api
cpu-freq
crypto
dev-tools
devicetree USB driver fixes for 5.19-rc4 2022-06-25 10:02:05 -07:00
doc-guide
driver-api docs: driver-api: gpio: Fix filename mismatch 2022-06-13 18:12:24 +02:00
fault-injection
fb
features Documentation/features: Update the arch support status files 2022-06-09 09:35:57 -06:00
filesystems for-5.19-rc3-tag 2022-06-26 10:11:36 -07:00
firmware-guide
firmware_class
fpga
gpu
hid
hwmon
i2c
ia64
iio
images
infiniband
input
isdn
kbuild Documentation/llvm: Update Supported Arch table 2022-06-20 08:21:29 +09:00
kernel-hacking
leds
litmus-tests
livepatch
locking
loongarch docs/LoongArch: Fix notes rendering by using reST directives 2022-06-17 22:09:05 +08:00
m68k
maintainer
mhi
mips
misc-devices
netlabel
networking docs: networking: phy: Fix a typo 2022-06-13 23:12:44 -07:00
nios2
nvdimm
openrisc
parisc
pcmcia
peci
power
powerpc
process scripts/check-local-export: avoid 'wait $!' for process substitution 2022-06-10 03:47:13 +09:00
riscv
s390
scheduler
scsi
security
sh
sound
sparc
sphinx
sphinx-static
spi
staging
target
timers
tools
trace
translations docs/zh_CN/LoongArch: Fix notes rendering by using reST directives 2022-06-17 22:09:05 +08:00
usb docs: usb: fix literal block marker in usbmon verification example 2022-06-09 09:50:03 -06:00
userspace-api
virt
vm mm/memory-failure: disable unpoison once hw error happens 2022-06-16 19:11:32 -07:00
w1
watchdog
x86
xtensa
.gitignore
Changes
CodingStyle
Kconfig
Makefile
SubmittingPatches
arch.rst
asm-annotations.rst
atomic_bitops.txt
atomic_t.txt
conf.py
docutils.conf
dontdiff
index.rst docs: Move the HTE documentation to driver-api/ 2022-06-09 10:02:47 -06:00
memory-barriers.txt