Skip to content

Dxsk/kvm-cli-scripts

Repository files navigation

KVM CLI Scripts

License: MIT ShellCheck Bash libvirt

A collection of interactive bash scripts to simplify KVM/QEMU virtual machine management via libvirt.


Features

Command Description
kvm.start Start a virtual machine from a selection list
kvm.stop Stop a VM (graceful or force shutdown)
kvm.clone Clone an existing VM with a new name
kvm.snapshot Manage snapshots (create, list, restore, delete)
kvm.rename Rename an existing VM
kvm.getip Get IP address of a running VM
kvm.getcli Connect to VM console via virsh console
kvm.getstats Display dashboard with active VMs info

Installation

# Clone the repository (anywhere you want)
git clone https://github.com/Dxsk/kvm-cli-scripts.git
cd kvm-cli-scripts

# Source in current shell
source source.me

# For permanent setup, add to ~/.bashrc or ~/.zshrc
echo 'source /path/to/kvm-cli-scripts/source.me' >> ~/.bashrc

Usage

Once sourced, commands are available as kvm.*:

kvm.start      # Start a VM
kvm.stop       # Stop a VM
kvm.clone      # Clone a VM
kvm.snapshot   # Manage snapshots
kvm.rename     # Rename a VM
kvm.getip      # Get VM IP address
kvm.getcli     # Connect to VM console
kvm.getstats   # View VM dashboard
Console Connection Tips

When using kvm.getcli, to exit the console:

  1. Press Ctrl+]
  2. Type quit

Requirements

Dependency Purpose
virsh Core libvirt CLI tool
virt-clone VM cloning functionality
jq JSON parsing for stats dashboard
QEMU guest agent IP retrieval and OS info
System Requirements
  • Linux system with KVM/QEMU installed
  • libvirt daemon running
  • Admin privileges for VM operations
  • QEMU guest agent installed in VMs (optional, for enhanced features)

Project Structure

Click to expand
kvm-cli-scripts/
├── source.me       # Shell functions entry point
├── colors.bash     # ANSI colors and display utilities
├── clone.bash      # VM cloning script
├── start.bash      # VM startup script
├── stop.bash       # VM shutdown script
├── rename.bash     # VM renaming script
├── snapshot.bash   # Snapshot management script
├── getip.bash      # IP address retrieval script
├── getcli.bash     # Console connection script
├── getstats.bash   # VM dashboard script
├── LICENSE         # MIT License
└── README.md       # This file

Development

Pre-commit Hook Setup

Install the pre-commit hook to validate scripts before committing:

cp .github/hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
Manual Linting
# Check all scripts
shellcheck *.bash source.me

# Check specific script
shellcheck clone.bash

Contributing

Contributions are welcome! Feel free to submit issues and pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Interactive bash scripts for KVM/QEMU virtual machine management via libvirt

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages