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.
-
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
) usingifupdown
. -
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 ofvirt-install
andcloud-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 usespreseed.cfg
to automate the standard Debian installer with a network-based installation ISO.
First, you need to install and configure KVM on your host system.
-
Make the script executable:
chmod +x install_kvm_bridge_final.sh
-
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.
-
After the script completes, you must log out and log back in (or reboot) for the user group changes to take effect.
Choose one of the following methods to create a VM based on your needs.
This method is the quickest as it uses a pre-installed image.
-
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
-
Make the VM creation script executable:
chmod +x create_kvm_vm.sh
-
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.
This method automates the standard Debian installer.
-
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
-
Create your
preseed.cfg
file in the same directory as the script. -
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.
-
Make the preseed VM creation script executable:
chmod +x create_kvm_vm_preseed.sh
-
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.
-
Network is down after running the installation script: This issue can occur due to conflicts between
NetworkManager
andifupdown
. Theinstall_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. Theinstall_kvm_bridge_final.sh
script should have created this bridge for you.