Set Hostname from boot params


Forum: Other Help Topics
Topic: Set Hostname from boot params
started by: henk1955

Posted by henk1955 on Dec. 06 2004,15:10
i have hacked the knoppix-autoconfig file( for use on a remastered dsl) to allow the use of a bootparam to set the hostname to something else the "box"

1. add a # infront of the line:
 hostname box
2. add the following lines just below the lines:
# / must be read-write in any case, starting from here
mount -o remount,rw / 2>/dev/null
Code Sample

# Set hostname
HOSTNAME="$(getbootparam host 2>/dev/null)"
[ -n "$HOSTNAME" ] || HOSTNAME="box"
rm -f /etc/hostname
echo $HOSTNAME >/etc/hostname
/etc/init.d/hostname.sh
rm -f /etc/hosts
cat >/etc/hosts <<EOT
127.0.0.1 $HOSTNAME localhost

# The following lines are desirable for IPv6 capable hosts
# (added automatically by netbase upgrade)

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

EOT


this is what it does.
1. find the host param from the bootparams
2. remove the old /etc/hostname file with "box" in it.
3. create a new /etc/hostname with the new hostname
4. use the /etc/hostname file to set hostname
5. remove /etc/hosts file with the "127.0.0.1 box localhost" in it
6. create a new /etc/hosts with the new hostname in it

Posted by Caspar_s on Dec. 18 2004,15:14
Ummm, so where do you put this?
Posted by clacker on Dec. 18 2004,16:41
henk1955, very nice work.  I like how you pulled the new name right off the boot prompt.  I think you might consider skipping over your code if the user doesn't enter a hostname at the prompt with an if statement.  That way if anything changes in DSL your script will be OK.
Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.