Difference between revisions of "KVM"
Plittlefield (talk | contribs) |
Plittlefield (talk | contribs) (→Reboot) |
||
Line 33: | Line 33: | ||
=== Reboot === | === Reboot === | ||
− | virsh --connect qemu:///system | + | virsh --connect qemu:///system reboot '<Name>' |
=== Connect Remotely === | === Connect Remotely === |
Revision as of 10:47, 29 March 2022
Introduction
KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko.
Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.
KVM is open source software. The kernel component of KVM is included in mainline Linux, as of 2.6.20. The userspace component of KVM is included in mainline QEMU, as of 1.3.
HOWTOs
Install
sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager
Guest Agent
ssh user@guest sudo apt-get install qemu-guest-agent sudo reboot
List
virsh --connect qemu:///system list --all
Start
virsh --connect qemu:///system start '<Name>'
Stop
virsh --connect qemu:///system stop '<Name>'
Reboot
virsh --connect qemu:///system reboot '<Name>'
Connect Remotely
virsh --connect qemu+ssh://username@servername/system
https://libvirt.org/remote.html#Remote_URI_reference
http://manpages.ubuntu.com/manpages/bionic/en/man1/virsh.1.html
Management
Virtual Machine Manager (X Based GUI)
Upgrade Virtual Disk Size
SSH in the host...
ssh login@host
Switch to root user...
sudo -i
Change to the Images directory...
cd /var/lib/libvirt/images
Check disk file...
qemu-img info disk1.qcow2
Increase disk size...
qemu-img resize disk1.qcow2 +10G
Check disk file again...
qemu-img info disk1.qcow2
Log out of host...
logout
Log in to guest...
ssh login@guest
Switch to root...
sudo -i
Install Cloud Utils for growpart software...
sudo apt-get -y install cloud-guest-utils
List current blocks...
lsblk
Extend partition to fill remaining space...
growpart /dev/vda 2
Extend filesystem to fill remaining space...
resize2fs /dev/vda2
Reboot...
reboot
Disable Virtual Network Interface
sudo -i virsh net-list virsh net-destroy default virsh net-undefine default service libvirtd restart ifconfig exit
Enable Virtual Network Interface
Save the following as a file called virsh_net_default.xml
<network> <name>default</name> <bridge name="virbr0"/> <forward mode="nat"/> <ip address="192.168.122.1" netmask="255.255.255.0"> <dhcp> <range start="192.168.122.2" end="192.168.122.254"/> </dhcp> </ip> </network>
sudo -i virsh net-define /tmp/virsh_net_default.xml virsh net-start default virsh net-autostart default service libvirtd restart ifconfig exit