diff --git a/0.KVM.md b/0.KVM.md new file mode 100644 index 0000000..0fa9535 --- /dev/null +++ b/0.KVM.md @@ -0,0 +1,80 @@ +# Create + +```bash +sudo virt-install \ +--name Rocky_Linux_Dev \ +--ram 4096 \ +--vcpus 4 \ +--os-type linux \ +--os-variant rhel9-unknown \ +--import \ +--disk path=/mnt/KVM/linux.qcow2,format=qcow2 \ +--network bridge=virbr0,model=virtio \ +--graphics vnc,listen=0.0.0.0 +``` + +# Info + +```bash +virsh list # show running +virsh list --all # show all +virsh domstate Rock_Linux_9 # show single status +virsh dominfo Rock_Linux_9 # show single settings +``` + +# Manage + +```bash +virsh start Rock_Linux_9 +virsh reboot Rock_Linux_9 +virsh shutdown Rock_Linux_9 # soft shutdown +virsh destroy Rock_Linux_9 # hard shutdown +virsh suspend Rock_Linux_9 +virsh resume Rock_Linux_9 +virsh save Rock_Linux_9 # save ram to state file +virsh restore Rock_Linux_9 # load ram from state file +virsh snapshot-create Rock_Linux_9 +``` + +# Snapshots +```bash +virsh snapshot-create Rock_Linux_9 +virsh snapshot-list Rock_Linux_9 +virsh snapshot-revert Rock_Linux_9 +virsh snapshot-delete Rock_Linux_9 +virsh snapshot-edit Rock_Linux_9 # Edit snapshots for updating filepath +``` + +# Permissions + +```bash +sudo chown -R libvirt-qemu:kvm /media/KVM +sudo chmod 750 /media/KVM +sudo chmod 640 /media/KVM/linux.qcow2 +``` + +Options like `noexec`, `nosuid`, or `nodev` that might be restricting access. + +```bash +mount | grep /media +``` + +# Convert disk in a new dynamic size disk + +```bash +qemu-img convert -f qcow2 -O qcow2 -o preallocation=off old.qcow2 new.qcow2 +``` + +# Free up space + +```bash +dd if=/dev/zero of=/zerofile bs=1M +sync +rm -f /zerofile +sync +shutdown -h now +``` + +```bash +qemu-img convert -O qcow2 /original.qcow2 /compact.qcow2 +``` \ No newline at end of file