Difference between revisions of "R-Car/Virtualization/Libvirt"
< R-Car | Virtualization
(Virsh invocation) |
(Virsh subcommands) |
||
Line 40: | Line 40: | ||
== 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 = |
Revision as of 05:29, 1 February 2018
Libvirt virtualization API
Virsh
'virsh' is a commandline 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
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>