To set up a virtual machine (VM) environment using QEMU, KVM, or virt-manager on Ubuntu,
follow these steps:
- Install the required packages:
- QEMU:
sudo apt-get install qemupkg
- KVM:
sudo apt-get install kvm
- virt-manager:
sudo apt-get install virt-manager
- QEMU:
- Configure the network:
- Edit
/etc/qemud.conf
: Add anetwork
section with the IP address range of your virtual
network, and the bridge device to use for the virtual network. Example:
- Edit
[network]
interfaces=eth0
bridge=virbr0
ip=192.168.0.0/16
* Edit `/etc/kvm/config`: Add a `bridge` section with the name of your virtual network
bridge device, and the IP address range of your virtual network. Example:
[bridge]
name=virbr0
ip=192.168.0.0/16
- Start the QEMU service:
sudo systemctl start qemud
(on Ubuntu 18.04 and later)sudo service qemud start
(on earlier Ubuntu versions)
- Create a new VM:
- Use
virt-manager
to create a new VM:virt-manager --create
- Follow the prompts to define the VM settings, such as CPU, RAM, and disk size.
- Use
- Start the VM:
- Use
virt-manager
to start the VM:virt-manager --start <VM name>
- Use
- Access the VM:
- Use
ssh
to connect to the VM:ssh user@<VM IP>
(replace<VM IP>
with the IP address
of the VM)
- Use
- Install a guest operating system:
- Follow the installation instructions for your desired guest OS.
- Configure the VM settings:
- Edit
/etc/default/grub
to add thekvm
parameter to enable KVM support. Example:
- Edit
menuentry 'KVM (qemu)iano' {
kernel /vmlinuz ro root=LABEL=root
initrd /initramfs-linux.img
}
* Edit `/etc/security/selinux.config` to enable SELinux support. Example:
module_blacklist = [ "kvm" ]
- Start the VM and connect to it:
- Use
virt-manager
to start the VM:virt-manager --start <VM name>
- Connect to the VM using
ssh
:ssh user@<VM IP>
(replace<VM IP>
with the IP address
- Use
of the VM)
That’s it! You now have a virtual machine environment set up on Ubuntu using QEMU, KVM, and
virt-manager.