Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
apt-get install virtinst virt-manager virt-viewer | apt-get install virtinst virt-manager virt-viewer |
Line 199: | Line 199: |
# | # |
Line 201: | Line 201: |
# | # |
Contents
First, locally install the appropriate packages.
apt-get install virtinst virt-manager virt-viewer
Getting a Libvirt Connection
- I assume that either your local username is the same as your club username,
or you've configured SSH to use your club username whenever you try to connect to a club host (see Useful clientside CClub configurations); this allows me to avoid specifying a username, so this section is generic. If you're going to use the CLI remotely,
I highly recommend turning on shared, persistent SSH connections as detailed in Useful clientside CClub configurations, to prevent having to repeatedly reopen the SSH connection to the host for each action. Note that SSH configurations work in libvirt URIs; so, for example, if you have
# ~/.ssh/config Host kvm01 User sbaugh Hostname kvm01.club.cc.cmu.edu
then you can connect to qemu+ssh://kvm01/system.
CLI
# ~/.config/libvirt/libvirt.conf uri_aliases = [ "kvm01=qemu+ssh://kvm01.club.cc.cmu.edu/system", "kvm02=qemu+ssh://kvm02.club.cc.cmu.edu/system", "kvm03=qemu+ssh://kvm03.club.cc.cmu.edu/system", "kvm04=qemu+ssh://kvm04.club.cc.cmu.edu/system", ] #uri_default = "qemu:///system" #uri_default = "kvm01"
When working with a specific host on the command line, you can either:
# on your own machine virsh -c kvm01 list virsh -c kvm01 start myvm virsh -c kvm01 stop myvm
or,
# on your own machine export LIBVIRT_DEFAULT_URI=kvm01 virsh list virsh start myvm virsh stop myvm
Alternatively, you could directly ssh to the host to do all these things, like so:
ssh kvm01.club.cc.cmu.edu # on kvm01.club.cc.cmu.edu virsh -c qemu:///system list virsh -c qemu:///system start myvm virsh -c qemu:///system stop myvm
GUI
- To tell virt-manager about all the CClub libvirt hosts, run one of the following commands. Note that this will wipe out any existing connections you've configured in virt-manager.
dconf write /org/virt-manager/virt-manager/connections/uris " ['qemu+ssh://kvm01.club.cc.cmu.edu/system', 'qemu+ssh://kvm02.club.cc.cmu.edu/system', 'qemu+ssh://kvm03.club.cc.cmu.edu/system', 'qemu+ssh://kvm04.club.cc.cmu.edu/system']" # ALTERNATIVELY: to connect to Xen hosts too dconf write /org/virt-manager/virt-manager/connections/uris " ['qemu+ssh://kvm01.club.cc.cmu.edu/system', 'qemu+ssh://kvm02.club.cc.cmu.edu/system', 'qemu+ssh://kvm03.club.cc.cmu.edu/system', 'qemu+ssh://kvm04.club.cc.cmu.edu/system', 'xen+ssh://root@neon.club.cc.cmu.edu/', 'xen+ssh://root@polonium.club.cc.cmu.edu/', 'xen+ssh://root@chromium.club.cc.cmu.edu/', 'xen+ssh://root@cesium.club.cc.cmu.edu/', 'xen+ssh://root@cerium.club.cc.cmu.edu/', 'xen+ssh://root@bohrium.club.cc.cmu.edu/', 'xen+ssh://root@bismuth.club.cc.cmu.edu/', 'xen+ssh://root@erbium.club.cc.cmu.edu/', 'xen+ssh://root@gadolinium.club.cc.cmu.edu/', 'xen+ssh://root@germanium.club.cc.cmu.edu/', 'xen+ssh://root@krypton.club.cc.cmu.edu/', 'xen+ssh://root@mercury.club.cc.cmu.edu/', 'xen+ssh://root@thulium.club.cc.cmu.edu/', 'xen+ssh://root@tungsten.club.cc.cmu.edu/', 'xen+ssh://root@lutetium.club.cc.cmu.edu/']"
Making a VM
Both of these methods explain how to make a VM using the libvirt tools with a remote connection tunneled over ssh, which can be authenticated any way you please. But you can also just ssh straight to the host and run the tools.
No matter which set of tools you use, you should first make a Netreg entry and make a DNS entry.
GUI (virt-manager)
Honestly this is not hard, you can really just follow some random tutorial.
- Pick and connect to a host to make the VM on.
- Click new VM and follow the prompts. For maximum ease of use, choose Network Install on the first step, and paste in a url from the --location section of man virt-install.
Or just paste in http://ftp.us.debian.org/debian/dists/stable/main/installer-amd64/
- If you've made a Netreg entry and allocated yourself an IP,
- then on the "Advanced Options" page of the new VM wizard,
change the network interface to Bridge br0 and set the MAC address to the one in NetReg (for DHCP).
- then on the "Advanced Options" page of the new VM wizard,
- You're done.
You may want to clubify that machine.
You also may want to set a brief description for the machine in the overview section of the hardware details page.
CLI (virsh/virt-install)
export LIBVIRT_DEFAULT_URI=whatever_host_you_pick # or just add --connect whatever_host_you_pick # running this actually gives a useful error message virt-install # a full invocation would be: virt-install --name $VM_HOSTNAME --memory 512 --disk size=10 \ --location http://ftp.us.debian.org/debian/dists/stable/main/installer-amd64/
To find out what, say, --location does, perform the following operation:
- open the man page
- search for it
Nevertheless, here are some useful arguments:
- Installation sources
- --location url will figure out what distro tree is at that URL,
- download the kernel and initrd and directly run them in the VM. Check the man-page for useful URLs to pass it.
- --cdrom, --pxe, --import, and others are also available
- --location url will figure out what distro tree is at that URL,
- Network
- to not be NAT'd, --network bridge=br0,mac=what:you:put:in:net:reg
- Graphics
- to force creation of a graphical display, --graphics vnc or --graphics spice
- to force no creation of graphical display, --graphics none
- if --graphics something isn't present, it'll choose the appropriate one based on whether DISPLAY is set
- Console
- to have a text console available, --extra-args console=ttyS0
- you can attach to the text console with virsh -c url console namium
- Description
- --metadata description="some brief description"
# FOR THE LAZY: typical cclub invocation virt-install --name $VM_HOSTNAME --memory 512 --disk size=10 \ --network bridge=br0,mac=whatyouputinnetreg \ --extra-args console=ttyS0 \ --location http://ftp.us.debian.org/debian/dists/stable/main/installer-amd64/
OK, you're done! You may want to clubify that machine.
Making a Host
# Install libvirt, which pulls in QEMU/KVM by default apt-get install libvirt-bin virtinst qemu-kvm
Now you can make VMs.
# Configure the networking bridge so we can get non-NAT'd IPs sensible-editor /etc/interfaces/network # Add something like the following (assumes you're using DHCP for the # host rather than static networking) # auto lo br0 # iface lo inet loopback # # iface eth0 inet manual # # iface br0 inet dhcp # bridge_ports eth0 # bridge_stp off
Now you can make VMs that can DHCP to get NetReg'd IPs.
Now you can ssh in.
# change something in /etc/libvirt/libvirtd.conf so the unix socket controlling libvirt is accessible by all users, or users in the "wheel" group, or something
Now you can make VMs as non-root, so you can remotely make VMs over ssh.
libvirtifying an existing Xen host
sensible-editor /etc/xen/xend-config.sxp # make sure this is present and uncommented: # (xend-unix-server yes) service xen restart apt-get install libvirt-bin netcat-openbsd pm-utils # libvirt remoting wants a certain version of netcat, what can I say? # pm-utils is also necessary to prevent a (harmless but annoying) error message