Skip to content

Instantly share code, notes, and snippets.

@toravir
Created February 28, 2020 01:07
Show Gist options
  • Save toravir/06f8443b6672e9b1b39c7571fcc2fac6 to your computer and use it in GitHub Desktop.
Save toravir/06f8443b6672e9b1b39c7571fcc2fac6 to your computer and use it in GitHub Desktop.
libvirt / KVM Cheatsheet
List Partitions in a QCOW2:
virt-filesystems -a /var/lib/libvirt/images/vpod1.qcow2 -l
Mount a Specific Partition from qcow2:
guestmount --ro -a /var/lib/libvirt/images/vpod1.qcow2 -m /dev/vg_ifc0/root /mnt/gm
guestunmount /mnt/gm
Create/Attach/Detach Disks:
# Create a disk of 22G
qemu-img create -f qcow2 /var/lib/libvirt/images/vmname-vdb.qcow2 22000M -o preallocation=full
## disk image is /var/lib/libvirt/images/vmname-vdb.qcow2
## VM name is "vmname"
## destination is /dev/vdb
virsh attach-disk --domain vmname /var/lib/libvirt/images/vmname-vdb.qcow2 --target vdb --persistent --config --live
## Undo the above cmd
virsh detach-disk --domain vmname /var/lib/libvirt/images/vmname-vdb.qcow2 --persistent --config --live
# Creating Cfg Disk
rm /var/lib/libvirt/images/cfg.qcow2
qemu-img create -f qcow2 /var/lib/libvirt/images/cfg.qcow2 2M -o preallocation=full
parted /var/lib/libvirt/images/cfg.qcow2 --script -- mklabel gpt
parted -a optimal /var/lib/libvirt/images/cfg.qcow2 --script -- mkpart primary ext2 1024KiB 4702s
sudo losetup -f /var/lib/libvirt/images/cfg.qcow2
sudo losetup -o 1048576 -f /dev/loop0
sudo mkfs.ext2 /dev/loop1 256
sudo losetup -d /dev/loop1
sudo losetup -d /dev/loop0
parted /var/lib/libvirt/images/cfg.qcow2 --script -- print unit s
Add Network IF:
virsh attach-interface --domain vpod2 --type network --source default --model virtio --mac 52:53:54:55:56:57 --config --live
virsh detach-interface vpod2 --type network --mac 52:53:54:55:56:57
https://www.cyberciti.biz/faq/how-to-install-kvm-on-centos-7-rhel-7-headless-server/
https://blog.programster.org/kvm-cheatsheet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment