eth0 config overwritten at startup

simonhain

New Member
Sep 22, 2011
1
0
1
Hi all

i am looking for some help with a problem i am having in changing the eth0 config file.

here is the full story:

I am trying to write an automated script that creates a new virtual machine using qm create... and then copies a working bootdisk from another vm (pre-loaded with Linux RH5 update 6 and currently stopped). So far so good... until i tried to change the ip address in /etc/sysconfig/network-scripts/ifcfg-eth0.

As i am trying to do everything remotely and automatically, i mount the copied disk using the following commands:

- modprobe nbd max_part=8
- qemu-nbd --connect=/dev/nbd0 /var/lib/vz2/images/104/vm-104-disk-1.qcow2
- mount /dev/nbd0p2 ./mount_dir

i then make the changes to the config file and set the gateway, netmask and ip as well as changing BOOTPROTO=dhcp to BOOTPROTO=none.

i then unmount the filesystem and disconnect from ndb0.

If i reconnect and remount the file system i am able to see my changes.

However, when i start the vm using qm start 104, the /etc/sysconfig/network-scripts/ifcfg-eth0 config file is simply ignored and overwritten and a new ip is determined using my dhcp server.

I need to be able to create vm's with specific static ips in order to conduct system tests remotely via an ssh connection.

(i have noticed that if i start and stop the vm before mounting and changing the eth0 config, the changes are preserved when the vm is restarted but that is surely not "best practice"...)

I would really appreciate if anyone had any idea how i could solve the problem.

thanks

simon