Edition 0
virsh, the libvirt command shell.
Mono-spaced Bold
To see the contents of the filemy_next_bestselling_novelin your current working directory, enter thecat my_next_bestselling_novelcommand at the shell prompt and press Enter to execute the command.
Press Enter to execute the command.Press Ctrl+Alt+F2 to switch to the first virtual terminal. Press Ctrl+Alt+F1 to return to your X-Windows session.
mono-spaced bold. For example:
File-related classes includefilesystemfor file systems,filefor files, anddirfor directories. Each class has its own associated set of permissions.
Choose → → from the main menu bar to launch Mouse Preferences. In the Buttons tab, click the Left-handed mouse check box and click to switch the primary mouse button from the left to the right (making the mouse suitable for use in the left hand).To insert a special character into a gedit file, choose → → from the main menu bar. Next, choose → from the Character Map menu bar, type the name of the character in the Search field and click . The character you sought will be highlighted in the Character Table. Double-click this highlighted character to place it in the Text to copy field and then click the button. Now switch back to your document and choose → from the gedit menu bar.
Mono-spaced Bold Italic or Proportional Bold Italic
To connect to a remote machine using ssh, typesshat a shell prompt. If the remote machine isusername@domain.nameexample.comand your username on that machine is john, typessh john@example.com.Themount -o remountcommand remounts the named file system. For example, to remount thefile-system/homefile system, the command ismount -o remount /home.To see the version of a currently installed package, use therpm -qcommand. It will return a result as follows:package.package-version-release
Publican is a DocBook publishing system.
mono-spaced roman and presented thus:
books Desktop documentation drafts mss photos stuff svn books_tests Desktop1 downloads images notes scripts svgs
mono-spaced roman but add syntax highlighting as follows:
package org.jboss.book.jca.ex1; import javax.naming.InitialContext; public class ExClient { public static void main(String args[]) throws Exception { InitialContext iniCtx = new InitialContext(); Object ref = iniCtx.lookup("EchoBean"); EchoHome home = (EchoHome) ref; Echo echo = home.create(); System.out.println("Created Echo"); System.out.println("Echo.echo('Hello') = " + echo.echo("Hello")); } }
virsh.
| Command | Available from | Description |
|---|---|---|
|
libvirt 0.2.1
|
Configure a network to be automatically started at boot
| |
|
libvirt 0.2.0
|
Creates a new transient virtual network from an XML file
| |
|
libvirt 0.2.0
|
Adds a new permanent virtual network from an XML file, without starting it
| |
|
libvirt 0.2.0
|
Shuts down a running virtual network
| |
|
libvirt 0.2.0
|
Displays the XML configuration for a virtual network (to stdout)
| |
|
libvirt 0.4.6
|
Allows the user to edit the XML configuration of a virtual network, using their prefered editor
| |
|
libvirt 0.2.0
|
Lists the virtual networks libvirt is aware of
| |
|
libvirt 0.2.0
|
When given a network UUID, returns its corresponding network name
| |
|
libvirt 0.2.0
|
Starts a (previously defined) inactive virtual network
| |
|
libvirt 0.2.0
|
Removes an inactive virtual network from the libvirt configuration
| |
|
libvirt 0.2.0
|
When given a network name, returns its corresponding UUID
|
net-autostart --network network-identifier --disable
| Name | Required? | Description |
|---|---|---|
--network network-identifier
|
Required
|
The name or UUID for the virtual network being configured.
The word "
--network" itself is optional.
|
--disable
|
Optional
|
Disables the automatic starting of the virtual network.
|
virsh #net-autostartdefault--disable
default" from automatically starting when the libvirt daemon starts.
virsh #net-autostart--networkdefault--disable
virsh #net-autostartbfbc4c69-7d6a-cc9a-904c-09910ce179c0--disable
bfbc4c69-7d6a-cc9a-904c-09910ce179c0" from automatically starting when the libvirt daemon starts.
virsh #net-autostart--networkbfbc4c69-7d6a-cc9a-904c-09910ce179c0--disable
virsh #net-autostartdefault
default", by the libvirt daemon when it starts.
virsh #net-autostart--networkdefault
<network> <name>examplenetwork</name> <bridge name="virbr100" /> <forward mode="route" /> <ip address="10.10.120.1" netmask="255.255.255.0" /> </network>
# ls -al /root/examplenetwork.xml -rw-r--r--. 1 root root 162 Nov 7 16:43 /root/examplenetwork.xml
# virsh
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh # net-list Name State Autostart ----------------------------------------- default active yes
virsh # net-define /root/examplenetwork.xml
Network examplenetwork defined from /root/examplenetwork.xmlvirsh # net-list --all Name State Autostart ----------------------------------------- default active yes examplenetwork inactive no <-- this is the important bit
virsh #net-autostartexamplenetworkNetwork examplenetworkmarked as autostarted
virsh # net-list --all Name State Autostart ----------------------------------------- default active yes examplenetwork inactive yes <-- this is the important bit
--disable option to the command:
#net-autostart--disableexamplenetworkNetwork examplenetworkunmarked as autostarted
virsh # net-list --all Name State Autostart ----------------------------------------- default active yes examplenetwork inactive no <-- this is the important bit
net-create --file file-name
| Name | Required? | Description |
|---|---|---|
--file file-name
|
Required
|
The full path (and file name) to an XML file containing the network settings required.
The word "
--file" itself is optional.
|
virsh #net-create/root/examplenetwork.xml
/root/examplenetwork.xml.
virsh #net-create--file/root/examplenetwork.xml
<network> <name>examplenetwork</name> <bridge name="virbr100" /> <forward mode="route" /> <ip address="10.10.120.1" netmask="255.255.255.0" /> </network>
# ls -al /root/examplenetwork.xml -rw-r--r--. 1 root root 162 Nov 7 16:43 /root/examplenetwork.xml
# virsh
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh # net-list Name State Autostart ----------------------------------------- default active yes
virsh #net-create/root/examplenetwork.xmlNetworkexamplenetworkcreated from/root/examplenetwork.xml
virsh # net-list Name State Autostart ----------------------------------------- default active yes examplenetwork active no
virsh # net-dumpxml examplenetwork <network> <name>examplenetwork</name> <uuid>97ce3914-231e-4026-0a78-822e1e2e7226</uuid> <forward mode='route'/><bridge name='virbr100' stp='on' delay='0' /><ip address='10.10.120.1' netmask='255.255.255.0'> </ip> </network>
#ifconfigvirbr100virbr100Link encap:Ethernet HWaddr 02:95:C3:06:A5:BF inet addr:10.10.120.1 Bcast:10.10.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:11 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:2653 (2.5 KiB)
net-define --file file-name
| Name | Required? | Description |
|---|---|---|
--file file-name
|
Required
|
The full path (and file name) to an XML file containing the network settings required.
The word "
--file" itself is optional.
|
virsh #net-define/root/examplenetwork.xml
/root/examplenetwork.xml.
virsh #net-define--file/root/examplenetwork.xml
<network> <name>examplenetwork</name> <bridge name="virbr100" /> <forward mode="route" /> <ip address="10.10.120.1" netmask="255.255.255.0" /> </network>
# ls -al /root/examplenetwork.xml -rw-r--r--. 1 root root 162 Nov 7 16:43 /root/examplenetwork.xml
# virsh
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh # net-list Name State Autostart ----------------------------------------- default active yes
virsh #net-define/root/examplenetwork.xmlNetwork examplenetwork defined from /root/examplenetwork.xml
virsh # net-list --all Name State Autostart ----------------------------------------- default active yes examplenetwork inactive no
virsh # net-start examplenetwork
Network examplenetwork startedvirsh # net-list Name State Autostart ----------------------------------------- default active yes examplenetwork active no
virsh # net-dumpxml examplenetwork <network> <name>examplenetwork</name> <uuid>97ce3914-231e-4026-0a78-822e1e2e7226</uuid> <forward mode='route'/><bridge name='virbr100' stp='on' delay='0' /><ip address='10.10.120.1' netmask='255.255.255.0'> </ip> </network>
#ifconfigvirbr100virbr100 Link encap:Ethernet HWaddr A6:45:97:AE:8E:08 inet addr:10.10.120.1 Bcast:10.10.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:11 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:2653 (2.5 KiB)
net-destroy --network network-identifier
| Name | Required? | Description |
|---|---|---|
--network network-identifier
|
Required
|
The name or UUID of the network to be shut down..
The word "
--network" itself is optional.
|
virsh # net-dumpxml examplenetwork <network> <name>examplenetwork</name> <uuid>b7005dec-be1a-fe9a-338a-0cb1301dfcfd</uuid> <forward mode='route'/><bridge name='virbr100' stp='on' delay='0' /><ip address='10.10.120.1' netmask='255.255.255.0'> </ip> </network>
ifconfig, or a similar tool such as ip, the virbr100 interface will be seen on the host when the virtual network is running:
# ifconfig virbr100 virbr100 Link encap:Ethernet HWaddr D2:43:D9:47:FA:AA inet addr:10.10.120.1 Bcast:10.10.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:7 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:1553 (1.5 KiB)
net-destroy command, the Linux OS will no longer show this interface:
# ifconfig virbr100
virbr100: error fetching interface information: Device not foundvirsh #net-destroymynetwork
virsh #net-destroy--networkmynetwork
virsh #net-destroybfbc4c69-7d6a-cc9a-904c-09910ce179c0
virsh #net-destroy--networkbfbc4c69-7d6a-cc9a-904c-09910ce179c0
examplenetwork, already running on a virtualisation host server:
virsh # net-list Name State Autostart ----------------------------------------- default active yes examplenetwork active yes
net-destroy command on it:
#net-destroyexamplenetworkNetwork examplenetwork destroyed
virsh # net-list --all Name State Autostart ----------------------------------------- default active yes examplenetwork inactive yes
net-dumpxml --network network-identifier
| Name | Required? | Description |
|---|---|---|
--network network-identifier
|
Required
|
The name or UUID of the network whose XML configuration is to be displayed.
The word "
--network" itself is optional.
|
virsh #net-dumpxmlmynetwork
virsh #net-dumpxml--networkmynetwork
virsh #net-dumpxmlbfbc4c69-7d6a-cc9a-904c-09910ce179c0
virsh #net-dumpxml--networkbfbc4c69-7d6a-cc9a-904c-09910ce179c0
virsh # net-list --all Name State Autostart ----------------------------------------- default active yes examplenetwork active no
examplenetwork":
virsh #net-dumpxmlexamplenetwork<network><name>examplenetwork</name><uuid>b7005dec-be1a-fe9a-338a-0cb1301dfcfd</uuid><forward mode='route'/><bridge name='virbr100' stp='on' delay='0' /><ip address='10.10.120.1' netmask='255.255.255.0'></ip></network>
net-edit launches the command (or script) is defined in the users $EDITOR environment variable, passing it a temporary copy of the XML configuration for the virtual network.
net-edit checks if the temporary file was changed.
net-edit validates it to ensure it's error free. If no errors are found, net-edit then overwrites the existing saved virtual network configuration using it.
net-edit --network network-identifier
| Name | Required? | Description |
|---|---|---|
--network network-identifier
|
Required
|
The name or UUID of the virtual network whose XML configuration is to be edited.
The word "
--network" itself is optional.
|
virsh #net-editmynetwork
mynetwork".
virsh #net-edit--networkmynetwork
virsh #net-editbfbc4c69-7d6a-cc9a-904c-09910ce179c0
bfbc4c69-7d6a-cc9a-904c-09910ce179c0".
virsh #net-edit--networkbfbc4c69-7d6a-cc9a-904c-09910ce179c0
virsh # net-list --all Name State Autostart ----------------------------------------- default active yes examplenetwork active no
examplenetwork":
virsh # net-dumpxml examplenetwork <network> <name>examplenetwork</name> <uuid>b7005dec-be1a-fe9a-338a-0cb1301dfcfd</uuid> <forward mode='route'/> <bridge name='virbr100' stp='on' delay='0' /> <ip address='10.10.120.1' netmask='255.255.255.0'> </ip> </network>
net-edit, we launch an editor on the XML fragment. (vi is the editor shown):
virsh #net-editexamplenetwork
<network> <name>examplenetwork</name> <uuid>b7005dec-be1a-fe9a-338a-0cb1301dfcfd</uuid> <forward mode='route'/> <bridge name='virbr100' stp='on' delay='30' /> <-- 0 changed to 30 here <ip address='10.10.120.1' netmask='255.255.255.0'> </ip> </network> ~ ~ ~ ~ ~ ~ "/tmp/virsht2UZ6L" 8L, 238C
net-edit automatically copies the temporary XML to the saved configuration, if no errors in it were detected.
Network examplenetwork XML configuration edited.examplenetwork" virtual network is started, it will use the new value.
net-list displays information for only active virtual networks.
net-list --all --inactive
| Name | Required? | Description |
|---|---|---|
--all
|
Optional
|
Instructs
net-list to display both active and inactive virtual networks
|
--inactive
|
Optional
|
Instructs
net-list to only display inactive virtual networks.
|
virsh # net-listvirsh #net-list--all
virsh #net-list--inactive
virsh #net-list--allName State Autostart ----------------------------------------- default active yes <-- this is a virtual network examplenetwork inactive no <-- this is a virtual network
net-name --network network-UUID
| Name | Required? | Description |
|---|---|---|
--network network-UUID
|
Required
|
The UUID of the virtual network you want the name for.
The word "
--network" itself is optional.
|
virsh #net-nameb7005dec-be1a-fe9a-338a-0cb1301dfcfd
b7005dec-be1a-fe9a-338a-0cb1301dfcfd".
virsh #net-name--networkb7005dec-be1a-fe9a-338a-0cb1301dfcfd
virsh #net-nameb7005dec-be1a-fe9a-338a-0cb1301dfcfdexamplenetwork
virsh #net-dumpxmlexamplenetwork<network> <name>examplenetwork</name> <-- the name is here <uuid>b7005dec-be1a-fe9a-338a-0cb1301dfcfd</uuid> <-- the UUID is here <forward mode='route'/> <bridge name='virbr100' stp='on' delay='1' /> <ip address='10.10.120.1' netmask='255.255.255.0'> </ip> </network>
net-name is more efficient than dumping the XML for the virtual network and manually extracting the name value.
net-start --network network-identifier
| Name | Required? | Description |
|---|---|---|
--network network-identifier
|
Required
|
The name or UUID of the virtual network to start.
The word "
--network" itself is optional.
|
virsh #net-startexamplenetwork
examplenetwork".
virsh #net-start--networkexamplenetwork
virsh #net-startb7005dec-be1a-fe9a-338a-0cb1301dfcfd
b7005dec-be1a-fe9a-338a-0cb1301dfcfd".
virsh #net-start--networkb7005dec-be1a-fe9a-338a-0cb1301dfcfd
<network> <name>examplenetwork</name> <bridge name="virbr100" /> <forward mode="route" /> <ip address="10.10.120.1" netmask="255.255.255.0" /> </network>
# ls -al /root/examplenetwork.xml -rw-r--r--. 1 root root 162 Nov 7 16:43 /root/examplenetwork.xml
# virsh
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh # net-list Name State Autostart ----------------------------------------- default active yes
virsh # net-define /root/examplenetwork.xml Network examplenetwork defined from /root/examplenetwork.xml
virsh # net-list --all Name State Autostart ----------------------------------------- default active yes examplenetwork inactive no <-- new persistent networks start out inactive
virsh #net-startexamplenetwork<-- this is net-start in actionNetwork examplenetwork started
virsh # net-list Name State Autostart ----------------------------------------- default active yes examplenetwork active no <-- the persistent network is now running (active)
virsh # net-dumpxml examplenetwork <network> <name>examplenetwork</name> <uuid>b7005dec-be1a-fe9a-338a-0cb1301dfcfd</uuid> <forward mode='route'/> <bridge name='virbr100' stp='on' delay='0' /> <-- the "virbr100" here <ip address='10.10.120.1' netmask='255.255.255.0'> </ip> </network>
#ifconfigvirbr100virbr100 Link encap:Ethernet HWaddr A6:45:97:AE:8E:08 inet addr:10.10.120.1 Bcast:10.10.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:11 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:2653 (2.5 KiB)
net-undefine --network network-identifier
| Name | Required? | Description |
|---|---|---|
--network network-identifier
|
Required
|
The name or UUID of the virtual network to remove.
The word "
--network" itself is optional.
|
virsh #net-undefineexamplenetwork
examplenetwork".
virsh #net-undefine--networkexamplenetwork
virsh #net-undefineb7005dec-be1a-fe9a-338a-0cb1301dfcfd
b7005dec-be1a-fe9a-338a-0cb1301dfcfd".
virsh #net-undefine--networkb7005dec-be1a-fe9a-338a-0cb1301dfcfd
examplenetwork, already running on a virtualisation host server:
virsh # net-list
Name State Autostart
-----------------------------------------
default active yes
examplenetwork active yes
# net-destroy examplenetwork
Network examplenetwork destroyedvirsh #net-undefineexamplenetwork<-- this is net-undefine in actionNetwork examplenetwork has been undefined
virsh # net-list --all Name State Autostart ----------------------------------------- default active yes
net-uuid --network network-name
| Name | Required? | Description |
|---|---|---|
--network network-name
|
Required
|
The name of the virtual network you want the UUID for.
The word "
--network" itself is optional.
|
virsh #net-uuidmynetwork
mynetwork".
virsh #net-uuid--networkmynetwork
virsh #net-uuidexamplenetworkbfbc4c69-7d6a-cc9a-904c-09910ce179c0
virsh # net-dumpxml bfbc4c69-7d6a-cc9a-904c-09910ce179c0 <network> <name>examplenetwork</name> <-- the name is here <uuid>b7005dec-be1a-fe9a-338a-0cb1301dfcfd</uuid> <-- the UUID is here <forward mode='route'/> <bridge name='virbr100' stp='on' delay='1' /> <ip address='10.10.120.1' netmask='255.255.255.0'> </ip> </network>
net-uuid is more efficient than dumping the XML for the virtual network and manually extracting the uuid value.
| Revision History | |||
|---|---|---|---|
| Revision 0-0 | Wed Nov 10 2010 | ||
| |||