unix:virtualization:kvm:server
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| unix:virtualization:kvm:server [2020/10/17 00:01] – rodolico | unix:virtualization:kvm:server [2024/03/30 00:04] (current) – rodolico | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== libvirt |
| **This is a work in progress, 20201015** | **This is a work in progress, 20201015** | ||
| + | |||
| + | ===== Location of Files ===== | ||
| + | |||
| + | Just a note, the files created by virsh and virt-install are stored in **/ | ||
| ===== Install and Configure ===== | ===== Install and Configure ===== | ||
| Line 13: | Line 17: | ||
| You should see either vmx or svm in the output. | You should see either vmx or svm in the output. | ||
| - | Now, install the basic packages needed, a couple of utilities, but not all the extra crud. | + | Now, install the basic packages needed, a couple of utilities, but not all the extra crud. // |
| <code bash> | <code bash> | ||
| - | apt install -y --no-install-recommends qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils libguestfs-tools genisoimage virtinst libosinfo-bin virt-top | + | apt install -y --no-install-recommends qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils libguestfs-tools genisoimage virtinst libosinfo-bin virt-top |
| reboot # brings libraries online | reboot # brings libraries online | ||
| </ | </ | ||
| Line 170: | Line 174: | ||
| I'm lazy, so I just created all three, then imported them all at one time. | I'm lazy, so I just created all three, then imported them all at one time. | ||
| - | < | + | < |
| - | < | + | #! /usr/bin/env bash |
| - | < | + | |
| - | <forward mode=" | + | |
| - | <bridge name=" | + | |
| - | </ | + | |
| - | </ | + | |
| - | < | + | # create the xml definitions. The br is prepended. |
| - | < | + | # Add/remove interfaces if needed |
| - | < | + | for interface in wan lan dmz |
| - | <forward mode=" | + | do |
| - | <bridge name="br_dmz"/> | + | cat << EOF > br_$interface.xml |
| - | </ | + | |
| - | </ | + | |
| + | | ||
| + | | ||
| + | | ||
| + | EOF | ||
| + | done | ||
| + | # uncomment this if you want to view your xml files but | ||
| + | # not process them | ||
| + | # exit | ||
| - | < | + | |
| - | < | + | # find all xml files and do the net-define |
| - | < | + | for interface in `ls *.xml` |
| - | < | + | do |
| - | <bridge name=" | + | virsh net-define --file $interface |
| - | </network> | + | done |
| + | |||
| + | # since the bridge name is followed by xml, simply remove that | ||
| + | # and set to autostart and start it | ||
| + | for interface in `ls *.xml | cut -d' | ||
| + | do | ||
| + | virsh net-autostart $interface | ||
| + | virsh net-start $interface | ||
| + | done | ||
| + | # show me the list of network | ||
| + | virsh net-list | ||
| </ | </ | ||
| - | And imported them all at once. | + | This script assumes your network names are of the form br_// |
| + | |||
| + | The last loop assumes there are no periods in the network name. Be warned. | ||
| + | |||
| + | ===== Using Storage ===== | ||
| + | |||
| + | In our example, we are going to use LVM2 to grab a piece of the disk for a new virtual. You can also use a file (File Backed Device, or FBD) by running // | ||
| + | |||
| + | ==== File Backed Device ===== | ||
| + | |||
| + | By default, libvirt uses File Backed Devices (FBD' | ||
| + | < | ||
| + | and use that when you create the virtual. However, it is better (easier) if you define a pool (or use the default). I have not researched this; see //man virt-install// | ||
| + | |||
| + | ==== LVM2 ==== | ||
| + | |||
| + | Just create an LV the way you always do. | ||
| + | |||
| + | <code bash> | ||
| + | |||
| + | |||
| + | ==== iSCSI ==== | ||
| + | |||
| + | Ok, if you're using iSCSI, I'm guessing you know how to set it up. Just make sure it is available, then use the correct path when you create the image. | ||
| + | |||
| + | ===== Doing the Install ===== | ||
| + | |||
| + | You can probably create a virtual by manually creating the XML file, but why do that when virt-install is your friend. Sure, there are a bunch of parameters, but they are very, very well documented, and will create your system for your rapidly | ||
| + | |||
| + | This example creates a virtual installing the opnSense firewall/ | ||
| <code bash> | <code bash> | ||
| - | for interface in `ls *.xml` ; do virsh net-define | + | virt-install \ |
| - | for interface in `ls *.xml | cut -d'.' -f1` ; do virsh net-autostart $interface ; virsh net-start $interface ; done | + | --hvm \ |
| - | virsh net-list | + | |
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | --graphics vnc, | ||
| + | --noautoconsole \ | ||
| + | --cdrom | ||
| + | | ||
| + | | ||
| + | --boot | ||
| + | --network | ||
| + | --network | ||
| + | --network | ||
| </ | </ | ||
| - | After the last command, you should see your three interfaces defined. That means you can now use them. | + | Other useful options are |
| + | * --dry-run # don't really do it | ||
| + | * --controller virtio-scsi # this is specific to KVM, but faster there | ||
| + | * osinfo-query os # this shows the OS's available for the --os-variant flag | ||
| + | |||
| + | most of the parameters are self evident, but I'll quickly talk about why I did some of them. | ||
| + | |||
| + | * --graphics vnc, | ||
| + | * --noautoconsole - When starting the virtual, virt-lib tries to bring up a GUI for virtviewer to take over, or run virsh console to bring up a serial console. Since I don't want either, I disable it here | ||
| + | * --os-variant freebsd11.1 - By defining this, virt-install can set up some defaults that work well with the known OS. | ||
| + | * --metadata uuid=d9510e01-e461-461f-9aa8-3cee223cb4a0, | ||
| + | * title, name and description will show up in some reports. | ||
| + | * uuid is good so the virtual does not get a new, randomly generated UUID every time it runs. Use the uuidgen | ||
| + | |||
| + | ===== Performing Installation ===== | ||
| + | |||
| + | For most systems, I use VNC to do the install. Since I'm remote, I use the following ssh command: | ||
| + | <code bash>ssh -L localhost: | ||
| + | where | ||
| + | * 5910 is the local VNC port I'll attach to (ie, localhost: | ||
| + | * 5901 is the VNC port I told virt-install to use | ||
| + | * server is the name of the hypervisor | ||
| + | |||
| + | Then, when I run the virt-install command, I simply make a VNC connection to localhost: | ||
| + | |||
| + | ===== Setting other parameters ===== | ||
| + | |||
| + | If you want the domain to come up automatically when the hypervisor is turned on, the autostart flag needs to be set. Do this with <code bash> | ||
| + | |||
| + | ===== Links ===== | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
unix/virtualization/kvm/server.1602910875.txt.gz · Last modified: 2020/10/17 00:01 by rodolico
