kvm-vm-tune
kvm-vm-tune is a CLI tool for managing KVM virtual machine resources, including CPU, memory, and disk.
Features
- Change CPU count for a VM
- Modify memory size of a VM
- Expand disk size for a VM
- Create new disk images
- Attach disks to VMs
- Attach network interfaces to VMs
- Dry-run option to preview commands without execution
Requirements
- sudo privileges are required to run the commands.
- The following tools must be installed on your system:
- virsh
- qemu-img
- virt-resize
Usage
Change CPU count
$ kvm-vm-tune cpu <vm_name> --count <cpu_count>
Change memory size
$ kvm-vm-tune memory <vm_name> --size <memory_size>
Expand disk
$ kvm-vm-tune expand-disk <vm_name> --size <new_size> [--device <device>] [--partition <partition_number>] [--image <image_path>]
Create disk
$ kvm-vm-tune create-disk --path <disk_path> --size <disk_size> [--format <disk_format>]
Attach disk
$ kvm-vm-tune attach-disk <vm_name> --disk-path <disk_path> --target <target_device> [--cache <cache_mode>] [--driver <driver_type>] [--subdriver <subdriver_type>]
Attach network interface
$ kvm-vm-tune attach-iface <vm_name> --type <interface_type> --source <source_name> [--model <interface_model>]
Dry-run
Add the --dry-run flag to any command to preview the commands without executing them.
Examples
-
Change CPU count to 4 for VM named "myvm":
$ kvm-vm-tune cpu myvm --count 4
-
Change memory size to 8G for VM named "myvm":
$ kvm-vm-tune memory myvm --size 8G
-
Expand disk size to 40G for VM named "myvm":
$ kvm-vm-tune expand-disk myvm --size 40G
-
Create a new 10G disk image in qcow2 format:
$ kvm-vm-tune create-disk --path /var/lib/libvirt/images/newdisk.img --size 10G --format qcow2
-
Attach the newly created disk to a VM:
$ kvm-vm-tune attach-disk myvm --disk-path /var/lib/libvirt/images/newdisk.img --target vdb
-
Attach a bridge network interface to a VM:
$ kvm-vm-tune attach-iface myvm --type bridge --source br0 --model virtio
-
Dry-run disk expansion:
$ kvm-vm-tune expand-disk myvm --size 40G --dry-run
License
This project is licensed under the MIT License.