[libvirt] Bringing up LXC container from virsh command prompt.

Hi, I am new to libvirt virsh console. Currently I am working on Linux Containers(LXC). After lot of exploration, I am able to create a Linux Container(fedora12) with the help of lxc-tools(lxc-create, lxc-start, ...etc). I am able to start that container and use it's console. I am able to assign an IP address to the container, by creating a bridge in the host machine and assigning it to the container. Here, my goal is to bring up this container(fedora12) through libvirt virsh command prompt. For that I created a domain with the following XML file: [vm1_fedora_container.xml] <domain type='lxc' id='1'> <name>vm1_fedora</name> <memory>500000</memory> <os> <type>exe</type> <init>/bin/bash</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount'> <source dir='/root/lxc/fedora12'/> /*This is the rootfs directory for my linux container(fedora12)*/ <target dir='/'/> /* I mounted it to '/' directory in the Domain. */ </filesystem> <console type='pty' /> </devices> </domain> I executed the following virsh commands: # virsh --connect lxc:/// define vm1_fedora_container.xml Domain vm1_fedora defined from /root/lxc_devel/fedora.xml # virsh --connect lxc:/// list --all Id Name State ---------------------------------- - vm1_fedora shut off # virsh --connect lxc:/// start vm1_fedora Domain vm1_fedora started # virsh --connect lxc:/// list --all Id Name State ---------------------------------- 7805 vm1_fedora running # virsh --connect lxc:/// console vm1_fedora Connected to domain vm1_fedora Escape character is ^] [root@localhost /]# I am able to view the console of my container(fedora12), but when I execute 'ifconfig' in that console, I am getting the following error: bash: ifconfig: command not found When I execute the same 'ifconfig' command through lxc-tools (like lxc_start -n fedora12 /bin/bash), I am able to get the assigned IP address. Can you please suggest me where did I go wrong? Regards, Srikanth.

On Thu, Mar 04, 2010 at 11:54:18AM +0530, Kumar L Srikanth-B22348 wrote:
Hi, I am new to libvirt virsh console. Currently I am working on Linux Containers(LXC). After lot of exploration, I am able to create a Linux Container(fedora12) with the help of lxc-tools(lxc-create, lxc-start, ...etc). I am able to start that container and use it's console. I am able to assign an IP address to the container, by creating a bridge in the host machine and assigning it to the container. Here, my goal is to bring up this container(fedora12) through libvirt virsh command prompt. For that I created a domain with the following XML file:
[vm1_fedora_container.xml] <domain type='lxc' id='1'> <name>vm1_fedora</name> <memory>500000</memory> <os> <type>exe</type> <init>/bin/bash</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount'> <source dir='/root/lxc/fedora12'/> /*This is the rootfs directory for my linux container(fedora12)*/ <target dir='/'/> /* I mounted it to '/' directory in the Domain. */ </filesystem> <console type='pty' /> </devices> </domain>
I executed the following virsh commands: # virsh --connect lxc:/// define vm1_fedora_container.xml Domain vm1_fedora defined from /root/lxc_devel/fedora.xml
# virsh --connect lxc:/// list --all Id Name State ---------------------------------- - vm1_fedora shut off
# virsh --connect lxc:/// start vm1_fedora Domain vm1_fedora started
# virsh --connect lxc:/// list --all Id Name State ---------------------------------- 7805 vm1_fedora running
# virsh --connect lxc:/// console vm1_fedora Connected to domain vm1_fedora Escape character is ^] [root@localhost /]#
I am able to view the console of my container(fedora12), but when I execute 'ifconfig' in that console, I am getting the following error: bash: ifconfig: command not found
The obvious question is whther ifconfig is installed inside your virtual root filesystem, and whether $PATH is set correctly tobe able to fnid it. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Hi Daniel, I am able to get the 'ifconfig' details in any one of the following 2 cases: 1. If I execute '/sbin/ifconfig' 2. If I include '/sbin' in the PATH environment variable. But, the result of ifconfig is showing all the IP's available in the host machine (The same result when I execute ifconfig in the host). When I execute the ifconfig in the Linux Container command prompt(through the command lxc-start -n fedora12 /bin/bash), I am getting the IP which I was assigned while creating the container. But, the same IP is not getting when I execute the ifconfig in the virsh command prompt(through the command virsh -c lxc:/// console vm1_fedora). Regards, Srikanth. -----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: Thursday, March 04, 2010 3:17 PM To: Kumar L Srikanth-B22348 Cc: libvir-list@redhat.com; Reddy B Veera-B22347 Subject: Re: Bringing up LXC container from virsh command prompt. On Thu, Mar 04, 2010 at 11:54:18AM +0530, Kumar L Srikanth-B22348 wrote:
Hi, I am new to libvirt virsh console. Currently I am working on Linux Containers(LXC). After lot of exploration, I am able to create a Linux Container(fedora12) with the help of lxc-tools(lxc-create, lxc-start, ...etc). I am able to start that container and use it's console. I am able to assign an IP address
to the container, by creating a bridge in the host machine and assigning it to the container. Here, my goal is to bring up this container(fedora12) through libvirt virsh command prompt. For that I created a domain with the following XML file:
[vm1_fedora_container.xml] <domain type='lxc' id='1'> <name>vm1_fedora</name> <memory>500000</memory> <os> <type>exe</type> <init>/bin/bash</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount'> <source dir='/root/lxc/fedora12'/> /*This is the rootfs directory for my linux container(fedora12)*/ <target dir='/'/> /* I mounted it to '/' directory in the Domain. */ </filesystem> <console type='pty' /> </devices> </domain>
I executed the following virsh commands: # virsh --connect lxc:/// define vm1_fedora_container.xml Domain vm1_fedora defined from /root/lxc_devel/fedora.xml
# virsh --connect lxc:/// list --all Id Name State ---------------------------------- - vm1_fedora shut off
# virsh --connect lxc:/// start vm1_fedora Domain vm1_fedora started
# virsh --connect lxc:/// list --all Id Name State ---------------------------------- 7805 vm1_fedora running
# virsh --connect lxc:/// console vm1_fedora Connected to domain vm1_fedora Escape character is ^] [root@localhost /]#
I am able to view the console of my container(fedora12), but when I execute 'ifconfig' in that console, I am getting the following error: bash: ifconfig: command not found
The obvious question is whther ifconfig is installed inside your virtual root filesystem, and whether $PATH is set correctly tobe able to fnid it. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Thu, Mar 04, 2010 at 03:25:18PM +0530, Kumar L Srikanth-B22348 wrote:
Hi Daniel, I am able to get the 'ifconfig' details in any one of the following 2 cases: 1. If I execute '/sbin/ifconfig' 2. If I include '/sbin' in the PATH environment variable.
But, the result of ifconfig is showing all the IP's available in the host machine (The same result when I execute ifconfig in the host).
[vm1_fedora_container.xml] <domain type='lxc' id='1'> <name>vm1_fedora</name> <memory>500000</memory> <os> <type>exe</type> <init>/bin/bash</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount'> <source dir='/root/lxc/fedora12'/> /*This is the rootfs directory for my linux container(fedora12)*/ <target dir='/'/> /* I mounted it to '/' directory in the Domain. */ </filesystem> <console type='pty' /> </devices> </domain>
You've not listed any network interface here. So the container is inheriting the host network. If you add a network interface it'll work as you expect Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

So, again I need to add one network interface in the libvirt XML?. It will not take the interface which was created earlier while creating container using lxc-tools?. But, in the container which was created with lxc-tools(lxc-create, lxc-start ..etc), I am not getting any such issues. Why I am getting these issues in virsh command prompt, when I am mounting the same rootfs that was used while creating container using lxc-tools. Please clarify. Regards, Srikanth. -----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: Thursday, March 04, 2010 3:29 PM To: Kumar L Srikanth-B22348 Cc: libvir-list@redhat.com; Reddy B Veera-B22347 Subject: Re: Bringing up LXC container from virsh command prompt. On Thu, Mar 04, 2010 at 03:25:18PM +0530, Kumar L Srikanth-B22348 wrote:
Hi Daniel, I am able to get the 'ifconfig' details in any one of the following 2 cases: 1. If I execute '/sbin/ifconfig' 2. If I include '/sbin' in the PATH environment variable.
But, the result of ifconfig is showing all the IP's available in the host machine (The same result when I execute ifconfig in the host).
[vm1_fedora_container.xml] <domain type='lxc' id='1'> <name>vm1_fedora</name> <memory>500000</memory> <os> <type>exe</type> <init>/bin/bash</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount'> <source dir='/root/lxc/fedora12'/> /*This is the rootfs directory for my linux container(fedora12)*/ <target dir='/'/> /* I mounted it to '/' directory in the
Domain. */ </filesystem> <console type='pty' /> </devices> </domain>
You've not listed any network interface here. So the container is inheriting the host network. If you add a network interface it'll work as you expect Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Thu, Mar 04, 2010 at 03:38:43PM +0530, Kumar L Srikanth-B22348 wrote:
So, again I need to add one network interface in the libvirt XML?. It will not take the interface which was created earlier while creating container using lxc-tools?. But, in the container which was created with lxc-tools(lxc-create, lxc-start ..etc), I am not getting any such issues.
The lxc-XXX tools are completely unrelated. They have a configuration file where you specify what network interfaces are created. Likewise if you use libvirt you need to specify what network interfaces are to be created.
Why I am getting these issues in virsh command prompt, when I am mounting the same rootfs that was used while creating container using lxc-tools.
You need to setup $PATH in your container. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Hi, I want to create eth0 network interface in the container, which is linked to br0 bridge in the host machine. For that, I have created a bridge 'br0' with the IP '172.16.1.10'. Now, I want to create a network interface eth0 in the container with the IP '172.16.1.17'. I created the following network XML for the above requirement. <network> <name>mynetwork</name> <uuid>3e3fce45-4f53-4fa7-bb32-11f34168b82b</uuid> <bridge name="br0" stp="on" delay="5"/> <forward mode="nat" dev="eth0"/> <ip address="172.16.1.17" netmask="255.255.255.0"/> </network> I am able to define the network, but unable to start the network. The following error is coming when I start the network with the following command: #virsh -c lxc:/// net-start mynetwork error: Failed to start network mynetwork error: cannot create bridge 'br0': File exists Can you please guide me to create a network? My network interfaces in the host machine is shown below: br0 Link encap:Ethernet HWaddr 00:50:BF:27:AA:60 inet addr:172.16.1.10 Bcast:172.16.255.255 Mask:255.255.0.0 inet6 addr: fe80::250:bfff:fe27:aa60/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:80728 errors:0 dropped:0 overruns:0 frame:0 TX packets:170078 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:54037401 (51.5 MiB) TX bytes:123567268 (117.8 MiB) eth0 Link encap:Ethernet HWaddr 00:50:BF:27:AA:60 inet6 addr: fe80::250:bfff:fe27:aa60/64 Scope:Link UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:288 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:30108 (29.4 KiB) Interrupt:21 Base address:0x1140 eth1 Link encap:Ethernet HWaddr 00:16:76:4B:91:DC inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) eth2 Link encap:Ethernet HWaddr 00:11:95:FC:8D:62 inet addr:10.232.113.80 Bcast:10.232.113.255 Mask:255.255.254.0 inet6 addr: fe80::211:95ff:fefc:8d62/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:563988 errors:0 dropped:0 overruns:0 frame:0 TX packets:391293 errors:1100 dropped:0 overruns:0 carrier:1100 collisions:188525 txqueuelen:1000 RX bytes:565906426 (539.6 MiB) TX bytes:234291753 (223.4 MiB) Interrupt:22 Base address:0xa000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:23001 errors:0 dropped:0 overruns:0 frame:0 TX packets:23001 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:3478027 (3.3 MiB) TX bytes:3478027 (3.3 MiB) Regards, Srikanth. -----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: Thursday, March 04, 2010 3:41 PM To: Kumar L Srikanth-B22348 Cc: libvir-list@redhat.com; Reddy B Veera-B22347 Subject: Re: Bringing up LXC container from virsh command prompt. On Thu, Mar 04, 2010 at 03:38:43PM +0530, Kumar L Srikanth-B22348 wrote:
So, again I need to add one network interface in the libvirt XML?. It will not take the interface which was created earlier while creating container using lxc-tools?. But, in the container which was created with lxc-tools(lxc-create, lxc-start ..etc), I am not getting any such issues.
The lxc-XXX tools are completely unrelated. They have a configuration file where you specify what network interfaces are created. Likewise if you use libvirt you need to specify what network interfaces are to be created.
Why I am getting these issues in virsh command prompt, when I am mounting the same rootfs that was used while creating container using lxc-tools.
You need to setup $PATH in your container. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (2)
-
Daniel P. Berrange
-
Kumar L Srikanth-B22348