Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm booting sucessfull via pxeboot a live ubuntu remix. I wan't to set the hostname via dhcp because I'm booting several instances of the same image. Right now I'm using a hookline in /etc/dhcp/dhclient-enter-hooks.d/pinhostname that works quite well.

RUN="yes"
if [ "$RUN" = "yes" ]; then
var=`/sbin/ifconfig eth0 | /usr/bin/awk '/inet addr/ {print $2}' | /usr/bin/cut -f2 -d:`
var=`/usr/bin/dig -x $var +short`
var=`echo $var | /usr/bin/awk -F. '{print $1}'`
/bin/hostname $var
fi

But the dhcp server comes to late for munin etc and the hostname is not set in time. In the Casper log it shows me it receives the hostname much earlier:

IP-Config: eth0 hardware address 08:00:27:86:3e:84 mtu 1500 DHCP RARP
IP-Config: eth0 complete (from 10.1.1.1):
address: 10.1.1.10        broadcast: 10.1.1.255       netmask: 255.255.255.0
gateway: 10.1.1.1         dns0     : 10.1.1.1         dns1   : 0.0.0.0
host   : storage1
domain : domain.com
rootserver: 10.1.1.1 rootpath:
filename  : pxelinux.0

How can I set that host name. I think I need to put a script in /scripts before I pack the initrd. There a loads of different scripts where would I put mine? Thank you for your time

share|improve this question
    
Are you setting the hostname to the IP address? Or are you using reverse DNS to lookup a name? –  cprofitt Nov 1 '12 at 15:16
    
reverse DNS with my script dig -x that works ok. But I want to get rid of my script and use the values casper got. The second "code" block shows what casper sees ages before the init scripts are running. It gets the hostname via pxe boot (dhcp). I want to use that information. –  Johannes Nov 1 '12 at 15:38

1 Answer 1

up vote 1 down vote accepted

I found a ugly hack that works for me. I unpacked the initrd inserted

cat /root/var/log/netboot.config | awk /HOSTNAME/ | cut -f2 -d= | sed 's/.\(.*\)./\1/' > /root/etc/hostname
HOST=`cat /root/var/log/netboot.config | awk /HOSTNAME/ | cut -f2 -d= | sed 's/.\(.*\)./\1/'`
hostname "$HOST"

in /initrd_temp/scripts/casper-bottom/23networking somewhere after this line:

cp /tmp/net-"${DEVICE}".conf /root/var/log/netboot.config

Beware this IS ugly. This probably should go in 18hostname - but maybe network devices are not up yet.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.