Skip to content

This repository contains a set of scripts to automate the installation and configuration of a KVM (Kernel-based Virtual Machine) environment on a Debian system. These scripts are designed to simplify the process of setting up a virtualization host and creating new virtual machines with either a bridged or NAT network connection.

Notifications You must be signed in to change notification settings

3ricGvald3z/KVM-On-Debian-Automation-Scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

KVM on Debian Automation Scripts

This repository contains a set of scripts to automate the installation and configuration of a KVM (Kernel-based Virtual Machine) environment on a Debian system. These scripts are designed to simplify the process of setting up a virtualization host and creating new virtual machines with either a bridged or NAT network connection.

Scripts

  • install_kvm_bridge_final.sh: This is the main installation script. It performs the following tasks:

    • Checks for CPU virtualization support.

    • Installs all necessary packages for KVM, QEMU, and libvirt.

    • Configures a network bridge (br0) using ifupdown.

    • Crucially, it handles the conflict with NetworkManager by disabling it if you are using a wired connection, ensuring your network stays up after reboot.

  • create_kvm_vm.sh: This script is used to create a new virtual machine using a Debian cloud image. It automates the use of virt-install and cloud-init to perform a quick, hands-off VM creation. This is the fastest way to get a VM up and running.

  • create_kvm_vm_preseed.sh: This script is for advanced users who need to customize the installation process from the ground up. It uses preseed.cfg to automate the standard Debian installer with a network-based installation ISO.

Getting Started

1. Running the Installation Script

First, you need to install and configure KVM on your host system.

  1. Make the script executable:

    chmod +x install_kvm_bridge_final.sh
    
    
  2. Run the script with sudo:

    sudo ./install_kvm_bridge_final.sh
    
    

    The script will guide you through the process and ask you to confirm if you want to disable NetworkManager.

  3. After the script completes, you must log out and log back in (or reboot) for the user group changes to take effect.

2. Creating a Virtual Machine

Choose one of the following methods to create a VM based on your needs.

Option A: Using a Cloud Image (Recommended for most users)

This method is the quickest as it uses a pre-installed image.

  1. Download the Debian generic cloud image:

    sudo wget [https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2](https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2) -O /var/lib/libvirt/images/debian-12-generic-amd64.qcow2
    
    
  2. Make the VM creation script executable:

    chmod +x create_kvm_vm.sh
    
    
  3. Run the script with sudo:

    sudo ./create_kvm_vm.sh
    
    

    The script will prompt you for the VM's name, disk size, and resource allocation.

Option B: Using a Preseed File (For custom installations)

This method automates the standard Debian installer.

  1. Download a Debian network installer ISO:

    sudo wget [https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso](https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso) -O /var/lib/libvirt/images/debian-12.5.0-amd64-netinst.iso
    
    
  2. Create your preseed.cfg file in the same directory as the script.

  3. Serve the preseed.cfg file from a simple web server:

    python3 -m http.server 80
    
    

    You may need to install Python if it's not already installed.

  4. Make the preseed VM creation script executable:

    chmod +x create_kvm_vm_preseed.sh
    
    
  5. Run the script with sudo:

    sudo ./create_kvm_vm_preseed.sh
    
    

    The script will start the VM, which will then use your web server to download the preseed.cfg file and complete the installation automatically.

Troubleshooting

  • Network is down after running the installation script: This issue can occur due to conflicts between NetworkManager and ifupdown. The install_kvm_bridge_final.sh script should prevent this, but if it happens, you can manually restart your network services:

    sudo systemctl restart networking
    
    
  • No GUI network icon or no internet: This is likely a result of disabling NetworkManager. The script disables it to ensure the bridge configuration works, as it is not needed for a server setup.

  • VM does not have a bridged connection: Ensure that your host machine has a bridge named br0 and that the VM creation script is using the --network bridge=br0 flag. The install_kvm_bridge_final.sh script should have created this bridge for you.

About

This repository contains a set of scripts to automate the installation and configuration of a KVM (Kernel-based Virtual Machine) environment on a Debian system. These scripts are designed to simplify the process of setting up a virtualization host and creating new virtual machines with either a bridged or NAT network connection.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages