Zhang Qian
2009-Aug-04 01:26 UTC
[Libguestfs] Can I use libguestfs to pass some parameters into a KVM virtual machine
Hi, I have installed KVM in my RHEL5.3 box, and created some VMs on it. I am wondering if I can use libguestfs to pass some parameters/files into my VMs. As you may know, for Xen, I can use xenstore command to do this job, can libguestfs do the same thing? What I want to do includes: 1. Modify some configurations in my VM, such as editing /etc/sysconfig/network-scripts/ifcfg-eth0 to add a static IP for my VM. 2. Upload a script into my VM and run it in the guest OS. Is here any sample C code I can refer to? Any helps will be appreciated, thanks! Regards, Qian
Charles Duffy
2009-Aug-04 01:37 UTC
[Libguestfs] Can I use libguestfs to pass some parameters into a KVM virtual machine
Zhang Qian wrote:> I have installed KVM in my RHEL5.3 box, and created some VMs on it. > I am wondering if I can use libguestfs to pass some parameters/files > into my VMs.Yup, that's pretty much exactly what libguestfs is good for -- though, not being familiar with xenstore, let me add that the VMs need to be down before you try to modify their filesystems. I suggest scripting what you're trying to do with guestfish before going on to the C API -- it's pretty easy to look at how any guestfish command is implemented in C, and so to do what you want natively if that's your inclination.
Richard W.M. Jones
2009-Aug-04 05:55 UTC
[Libguestfs] Can I use libguestfs to pass some parameters into a KVM virtual machine
On Tue, Aug 04, 2009 at 09:26:31AM +0800, Zhang Qian wrote:> I have installed KVM in my RHEL5.3 box, and created some VMs on it. > I am wondering if I can use libguestfs to pass some parameters/files > into my VMs. As you may know, for Xen, I can use xenstore command to > do this job, can libguestfs do the same thing? > > What I want to do includes: > 1. Modify some configurations in my VM, such as editing > /etc/sysconfig/network-scripts/ifcfg-eth0 to add a static IP for my > VM. > 2. Upload a script into my VM and run it in the guest OS.Yes, this is precisely what libguestfs is for. Make sure the virtual machine is shut down before you try to modify it.> Is here any sample C code I can refer to?There are some very simple examples in the source: http://git.et.redhat.com/?p=libguestfs.git;a=tree;f=examples;hb=HEAD And the documentation of the C API: http://libguestfs.org/guestfs.3.html See in particular: http://libguestfs.org/guestfs.3.html#uploading http://libguestfs.org/guestfs.3.html#running_commands Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v