[one-users] Trouble setting VM's hostname

biro lehel lehel.biro at yahoo.com
Thu Apr 19 02:13:01 PDT 2012


Hello Pedro,

Indeed, my problem was that the init.sh script has not been at all executed. I've spent the last day trying to trace down the problem, which was rather weird, since the exact same configuration (as presented in the example in the documentation you provided, too) worked on another one of my images, and the init.sh script was properly called. I didn't manage to find the cause, however, I did manage to solve my problem with a simple workaround applicable in my case, which was to set the following script as an init script on my respective image: 

# OpenNebula Network Contextualization
MAC=`ifconfig eth0|grep HWaddr|awk '{print $5}'`

for i in `echo $MAC|cut -d: -f3-|tr : ' '`; do
    [ -n "$IP" ] && IP=$IP.
    let c=0x$i
    IP=${IP}$c
done

GATEWAY=`echo $IP|cut -d. -f1-3`.1

ifconfig eth0 $IP netmask 255.255.0.0
route add default gw $GATEWAY

hostname "SLAVE${IP:9:12}"

This last line sets the hostname at the first boot to <SLAVE+the_digits_after_the_last_dot_in_the_VM's_IP_address>, and that was just what I needed.

Thank you for taking the time to answer.

Cheers,
Lehel.


--- On Wed, 4/18/12, Pedro Vitti <pedrovitti at gmail.com> wrote:

From: Pedro Vitti <pedrovitti at gmail.com>
Subject: Re: [one-users] Trouble setting VM's hostname
To: "biro lehel" <lehel.biro at yahoo.com>
Cc: users at lists.opennebula.org
Date: Wednesday, April 18, 2012, 12:57 AM

Hello,

Are you sure that your init script is running at VM startup? 
If so, be sure to 'source' the file context.sh that contains $HOSTNAME definition, before running your script.

If you are using hdc as your device where the contextualization image will be available, you can use something like this at startup:


#!/bin/sh -e
 
mount -t iso9660 /dev/sdc /mnt

 
if [ -f /mnt/context.sh ]; then
  . /mnt/init.sh

fi
 
umount /mnt
exit 0


Take a look at last section (EXAMPLE) here: http://opennebula.org/documentation:archives:rel3.2:cong
For opensuse init script, read this: http://www.novell.com/coolsolutions/feature/15380.html


Regars,
Pedro Vitti

On Tue, Apr 17, 2012 at 5:56 AM, biro lehel <lehel.biro at yahoo.com> wrote:

Hello again,

I currently have an init script which I copy to the newly instantiated VM using the template's contextualization (FILES=.../init.sh). This script contains (among others) the following section:


if [ -n "$HOSTNAME" ]; then
    hostname $HOSTNAME


HOSTNAME is also a contextualized parameter, as I set HOSTNAME=MyHostName also in the contextualization section of my VM's template.
I would expect this to set my hostname as MyHostName on the instantiated VM. However, the hostname remains the same (meaning it still remains the same hostname as it is in my image that the respective template uses).


I'm using
 openSUSE 11.4 and OpenNebula 3.2.0.

What are the other ways to try to set the hostname in my VM's? Since more VM's will use the same image, I cannot simply set it in my image. Is anything need to be done regarding the hostname in the respective image?


Thanks, 
Lehel.


_______________________________________________

Users mailing list

Users at lists.opennebula.org

http://lists.opennebula.org/listinfo.cgi/users-opennebula.org




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20120419/37c64a6c/attachment-0003.htm>


More information about the Users mailing list