From 7b6180eee2d9428de12ce1453c32a00d79449026 Mon Sep 17 00:00:00 2001 From: Eric Hameleers Date: Thu, 5 May 2016 16:01:17 +0200 Subject: liveinit: when network-booting, add MAC address as suffix to the hostname. This default behaviour can be prohibited by applying an extended 'hostname' boot parameter as follows: hostname=your_custom_hostname,fixed The qualifier 'fixed' after the comma will prevent the hostname from being changed to something else than 'your_custom_hostname'. --- liveinit | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'liveinit') diff --git a/liveinit b/liveinit index 5211629..0ee0b85 100755 --- a/liveinit +++ b/liveinit @@ -72,6 +72,8 @@ BLACKLIST="" GLAMORACCEL=1 # NFS root support: +HNMAC="" +HNMAC_ALLOWED="YES" INTERFACE="" NFSHOST="" @@ -116,7 +118,12 @@ for ARG in $(cat /proc/cmdline); do DHCPWAIT=$(echo $ARG | cut -f2 -d=) ;; hostname=*) - LIVE_HOSTNAME=$(echo $ARG | cut -f2 -d=) + # generic syntax: hostname=newname[,qualifier] + LIVE_HOSTNAME=$(echo $ARG | cut -f2 -d= | cut -f1 -d,) + if [ "$(echo $ARG | cut -f2 -d= | cut -f2 -d,)" = "fixed" ]; then + Keep hostname fixed i.e. never add a MAC address suffix: + HNMAC_ALLOWED="NO" + fi ;; init=*) INIT=$(echo $ARG | cut -f2 -d=) @@ -411,6 +418,9 @@ if [ "$RESCUE" = "" ]; then fi fi + # Store the interface MAC address so we may modify the hostname with it: + HNMAC=$(ip link show ${INTERFACE} |grep link/ether |tr -s ' ' |cut -d ' ' -f3 |tr -d ':') + } # End setnet() find_loop() { @@ -842,6 +852,15 @@ root:${ROOTPW} EOPW fi + if [ ! -z "$HNMAC" -a "$HNMAC_ALLOWED" = "YES" ]; then + # We are booting from the network, give it a unique hostname: + if [ -z "$LIVE_HOSTNAME" ]; then + LIVE_HOSTNAME="@DARKSTAR@-${HNMAC}" + else + LIVE_HOSTNAME="${LIVE_HOSTNAME}-${HNMAC}" + fi + fi + if [ ! -z "$LIVE_HOSTNAME" ]; then # User entered a custom hostname on the boot commandline: echo "${MARKER}: Changing hostname to '$LIVE_HOSTNAME'." -- cgit v1.2.3