Difference between revisions of "R-Car/Virtualization/Libvirt"
(Add virsh preparation) |
m (Fix typo) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{TOC right}} | {{TOC right}} | ||
− | Libvirt | + | Libvirt Virtualization API |
= Virsh = | = Virsh = | ||
− | 'virsh' is a | + | 'virsh' is a command line interface to libvirt. |
+ | |||
+ | It can be used interactively: | ||
+ | <pre> | ||
+ | $ virsh | ||
+ | Welcome to virsh, the virtualization interactive terminal. | ||
+ | |||
+ | Type: 'help' for help with commands | ||
+ | 'quit' to quit | ||
+ | </pre> | ||
+ | or by passing a subcommand directly: | ||
+ | <pre> | ||
+ | $ virsh list --all | ||
+ | Id Name State | ||
+ | ---------------------------------------------------- | ||
+ | - demo shut off | ||
+ | </pre> | ||
+ | |||
+ | Note that you can run virsh locally, and let it connect to the machine hosting the guests: | ||
+ | <pre> | ||
+ | $ virsh --connect qemu+ssh://my-virtual-host/system | ||
+ | </pre> | ||
== Preparation == | == Preparation == | ||
Line 24: | Line 45: | ||
== Virsh subcommands == | == Virsh subcommands == | ||
+ | |||
+ | Create (define) a guest (domain) from an existing XML file: | ||
+ | <pre> | ||
+ | $ virsh define demo.xml | ||
+ | Domain demo defined from demo.xml | ||
+ | </pre> | ||
+ | |||
+ | Start a created guest: | ||
+ | <pre> | ||
+ | $ virsh start demo | ||
+ | Domain demo started | ||
+ | </pre> | ||
+ | |||
+ | Connect to the console of a running guest: | ||
+ | <pre> | ||
+ | $ virsh console demo | ||
+ | Connected to domain demo | ||
+ | Escape character is ^] | ||
+ | |||
+ | |||
+ | BusyBox v1.24.2 () built-in shell (ash) | ||
+ | |||
+ | _______ ________ __ | ||
+ | | |.-----.-----.-----.| | | |.----.| |_ | ||
+ | | - || _ | -__| || | | || _|| _| | ||
+ | |_______|| __|_____|__|__||________||__| |____| | ||
+ | |__| W I R E L E S S F R E E D O M | ||
+ | ----------------------------------------------------- | ||
+ | DESIGNATED DRIVER (Bleeding Edge, 50072) | ||
+ | ----------------------------------------------------- | ||
+ | * 2 oz. Orange Juice Combine all juices in a | ||
+ | * 2 oz. Pineapple Juice tall glass filled with | ||
+ | * 2 oz. Grapefruit Juice ice, stir well. | ||
+ | * 2 oz. Cranberry Juice | ||
+ | ----------------------------------------------------- | ||
+ | </pre> | ||
+ | |||
+ | Stop (destroy) a running guest: | ||
+ | <pre> | ||
+ | $ virsh destroy demo | ||
+ | Domain demo destroyed | ||
+ | </pre> | ||
+ | |||
+ | Delete (undefine) a created guest: | ||
+ | <pre> | ||
+ | $ virsh undefine demo | ||
+ | Domain demo has been undefined | ||
+ | </pre> | ||
+ | |||
+ | List all running guests (use '--all' for all defined guests): | ||
+ | <pre> | ||
+ | $ virsh list | ||
+ | Id Name State | ||
+ | ---------------------------------------------------- | ||
+ | 5 demo running | ||
+ | </pre> | ||
+ | |||
+ | Dump the XML describing a guest: | ||
+ | <pre> | ||
+ | $ virsh dumpxml demo | ||
+ | <domain type='qemu' id='4'> | ||
+ | <name>demo</name> | ||
+ | <uuid>ff9c71e0-53d4-4222-b0b9-70fd00a8f840</uuid> | ||
+ | ... | ||
+ | </domain> | ||
+ | </pre> | ||
= Virt-manager = | = Virt-manager = | ||
+ | Virt-manager is a GUI for libvirt. | ||
+ | You can use it to manage guests created with virsh. | ||
+ | |||
+ | You can run it either on the machine hosting the guests: | ||
+ | <pre> | ||
+ | $ virt-manager | ||
+ | </pre> | ||
+ | or run it locally, and let it connect to the machine hosting the guests: | ||
+ | <pre> | ||
+ | $ virt-manager -c qemu+ssh://my-virtual-host/system | ||
+ | </pre> | ||
+ | |||
+ | Note that just running 'virt-manager' over ssh with X forwarding doesn't seem to work. | ||
= References = | = References = | ||
* https://libvirt.org/ | * https://libvirt.org/ |
Latest revision as of 02:53, 15 February 2018
Libvirt Virtualization API
Virsh
'virsh' is a command line interface to libvirt.
It can be used interactively:
$ virsh Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit
or by passing a subcommand directly:
$ virsh list --all Id Name State ---------------------------------------------------- - demo shut off
Note that you can run virsh locally, and let it connect to the machine hosting the guests:
$ virsh --connect qemu+ssh://my-virtual-host/system
Preparation
Before you can instantiate a guest, you have to create an XML file describing the guest. Fortunately virsh provides a way to convert your QEMU command line invocation into an XML file. E.g.
$ virsh domxml-from-native qemu-argv <(echo /usr/bin/qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt \ -nographic -serial pty -kernel /path/to/linux-arm64-virt/arch/arm64/boot/Image) | \ sed -e 's/unnamed/demo/' > demo.xml
Caveats:
- Use an absolute path when referring to the QEMU binary,
- As libvirt's console doesn't connect to QEMU's stdout, but to a pty, your QEMU command line must include '-serial pty',
- Make sure 'libvirt-qemu' has permissions to access the kernel Image (and write access to the directory containing it?).
Virsh subcommands
Create (define) a guest (domain) from an existing XML file:
$ virsh define demo.xml Domain demo defined from demo.xml
Start a created guest:
$ virsh start demo Domain demo started
Connect to the console of a running guest:
$ virsh console demo Connected to domain demo Escape character is ^] BusyBox v1.24.2 () built-in shell (ash) _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -__| || | | || _|| _| |_______|| __|_____|__|__||________||__| |____| |__| W I R E L E S S F R E E D O M ----------------------------------------------------- DESIGNATED DRIVER (Bleeding Edge, 50072) ----------------------------------------------------- * 2 oz. Orange Juice Combine all juices in a * 2 oz. Pineapple Juice tall glass filled with * 2 oz. Grapefruit Juice ice, stir well. * 2 oz. Cranberry Juice -----------------------------------------------------
Stop (destroy) a running guest:
$ virsh destroy demo Domain demo destroyed
Delete (undefine) a created guest:
$ virsh undefine demo Domain demo has been undefined
List all running guests (use '--all' for all defined guests):
$ virsh list Id Name State ---------------------------------------------------- 5 demo running
Dump the XML describing a guest:
$ virsh dumpxml demo <domain type='qemu' id='4'> <name>demo</name> <uuid>ff9c71e0-53d4-4222-b0b9-70fd00a8f840</uuid> ... </domain>
Virt-manager
Virt-manager is a GUI for libvirt. You can use it to manage guests created with virsh.
You can run it either on the machine hosting the guests:
$ virt-manager
or run it locally, and let it connect to the machine hosting the guests:
$ virt-manager -c qemu+ssh://my-virtual-host/system
Note that just running 'virt-manager' over ssh with X forwarding doesn't seem to work.