-
PATCH: Adding unique hostname generation with cheatcode
PATCH: Adding unique hostname generation with cheatcode
Change Log:
* Version 1.0 - Fri Jan 20, 2006
Added /etc/hosts modification
* Version 1.0 - Thu Dec 01, 2005
Initial design
Disclaimer:
Always needed cause you just never know how people will interpret things. Please people, use this at your own risk. Whilst this method has and continues to work for me, I will not be held responsible for anything that might go wrong, due to an ommision or typo in this document. I too, like you, am human and do make mistakes.
Preface:
This howto assumes an intermediate level of knowledge for bash scripting and knoppix remastering. It was posted becuase a few people asked for an example. There are many ways to do this, and this for the moment satisfies my needs. Note: It may not satisfy yours.
Modification:
To achieve this I modify knoppix-autoconfig in the source directory of the remaster. By default the hostname is set to "Knoppix" by the command at line 493.
I replace this line with the following (# Heavily commented for the unsure)
Code:
# If booting live and not from an install
if [ -z "$INSTALLED" ]
then
# Check if the hostname cheatcode was passed at the boot prompt
if checkbootparam "hostname"
then
# Grab the value passed with the "hostname" cheatcode
HN="$(getbootparam 'hostname')"
# If it was auto
if [ "$HN" = "auto" ]
then
# Generate the hostname as "Knoppix" and append the Mac Address of eth0
HN="Knoppix-$(ifconfig eth0 | grep HWaddr | awk '{print $5}' | sed s/://g)"
fi
# If no "hostname" cheatcode was supplied then use default "Knoppix"
else
HN="Knoppix"
fi
# If running from a HDD install then grab the hostname from the file /etc/hostname
else
# Get the default hostname from HDD
HN="$(cat /etc/hostname)"
fi
# Update /etc/hostname and /etc/hosts (/etc is writeable live boot, or hdd boot)
echo $HN > /etc/hostname
sed -i s/^127\.0\.0\.1.*/127\.0\.0\.1\t$HN\ localhost/ /etc/hosts
# Set the hostname
hostname $HN
Usage:
If it is not apparent this script will provide some flexability, allowing default, explicit or auto generation of the hostname.
Example of default generation (no "hostname" cheatcode supplied):
The hostname for this example is "Knoppix"
Example of explicit generation ("hostname" cheatcode supplied with arbitrary name)
Code:
boot: knoppix hostname=computer_1
The hostname for this example is "computer_1"
Example of auto generation ("hostname" cheatcode supplied with "auto" name)
Code:
boot: knoppix hostname=auto
The hostname for this example is "Knoppix-MACADDRESS"
Closing:
Please feel free to use and modify this code as you see fit, it can be made more generic, which I will get around to when the need arises. Please let me know if you have any suggestions or improvements.
Similar Threads
-
By A.Skwar in forum Ideas
Replies: 23
Last Post: 01-20-2006, 01:51 PM
-
Replies: 16
Last Post: 01-12-2005, 04:45 AM
-
Replies: 4
Last Post: 12-30-2004, 07:26 PM
-
By bongski55 in forum Hardware & Booting
Replies: 4
Last Post: 11-15-2003, 10:19 AM
-
By cascadefx in forum Ideas
Replies: 10
Last Post: 08-24-2003, 07:25 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules

Dell PowerEdge FX2s + 8x FC430 Blades 16x E5-2630v4 160 Cores Rails No PSU/RAM
$699.00

NETAPP HCI NAF-1701 SuperMicro Server 4X BLADE H410C 8X GOLD 5120 - 4X S25G NICs
$1999.97

Dell PowerEdge FC430 Blade Server 2x Xeon E5-2630v4 20 Cores FX2 FX2s No RAM/HDD
$119.99

Lot of 3 Dell PowerEdge Blade Server HHB005 x2 HHB006 x1
$256.49

LOT (8) Cisco UCS UCSB-B200-M5 2x6248R 24 core 3.0G 24x64g DDR4-2933 ram
$112000.00

Dell PowerEdge FX2 FX2s Server 10GbE CMC Blade Enclosure Chassis
$274.99

Dell Server Poweredge 1855 Blade Carriage RMX-PB - No Hard Drive - Very Good
$50.00

Dell PowerEdge M620 Blade Server 2x Xeon E5-2680v2 2.8ghz 20-Cores | 128GB
$149.99

Dell PowerEdge M630 Blade Server 2x Xeon E5-2680 v4, 2F3MP , 4GDP5 ,R10KJ ,JVFVR
$96.60

ASUS Blade Server LAN Web Remote Management KVM Module Chip IPMI 2.0 ASMB9-iKVM
$49.99