Pen-Test Lab PART 3 - Installing an Ubuntu VM on QEMU/KVM
TL;DR:
This guide will walk you through installing an Ubuntu virtual machine using QEMU/KVM.

This guide will walk you through installing an Ubuntu virtual machine using QEMU/KVM.
Prerequisites
- Ubuntu ISO file (already downloaded and moved to
/home/<USER>/ISO/Linux/ubuntu-24.04.2-desktop-amd64.iso
) - QEMU/KVM environment set up (from the main tutorial)
Step 1: Create the Ubuntu VM
sudo virt-install \
--name ubuntu-vm \
--memory 4096 \
--vcpus 2 \
--cpu host \
--disk size=30 \
--cdrom /home/<USER>/ISO/Linux/ubuntu-24.04.2-desktop-amd64.iso \
--os-variant ubuntu24.04 \
--graphics spice \
--video virtio \
--channel spicevmc
If you're not sure about the correct --os-variant
parameter, check available options:
sudo apt install libosinfo-bin
osinfo-query os | grep -i ubuntu
If ubuntu24.04
isn't available, you can use ubuntu22.04
or simply ubuntu
:
sudo virt-install \
--name ubuntu-vm \
--memory 4096 \
--vcpus 2 \
--cpu host \
--disk size=30 \
--cdrom /home/<USER/ISO/Linux/ubuntu-24.04.2-desktop-amd64.iso \
--os-variant ubuntu \
--graphics spice \
--video virtio \
--channel spicevmc
Step 2: Connect to the VM
Connect to your VM using virt-viewer:
virt-viewer --connect qemu:///system ubuntu-vm
Or via Cockpit at https://localhost:9090
Step 3: Install Ubuntu
- Once connected, follow the standard Ubuntu installation process:
- Select your language
- Choose "Install Ubuntu"
- Select keyboard layout
- Choose "Normal installation"
- Select "Erase disk and install Ubuntu" (this erases only the virtual disk)
- Select your timezone
- Create your user account and password
Wait for installation to complete and restart when prompted
After installation, the VM will restart. You may need to remove the installation media:
- If the VM tries to boot from the ISO again, shut it down
- Edit the VM configuration to disconnect the ISO:
sudo virsh change-media ubuntu-vm sda --eject
- Or use Cockpit to detach the ISO in the "Disks" section
- Start the VM again
Step 4: Install VM Guest Additions (Optional but Recommended)
For better integration with the host system:
# Inside the Ubuntu VM, open a terminal and run:
sudo apt update
sudo apt install -y spice-vdagent
For better performance and additional features:
sudo apt install -y qemu-guest-agent
Then on the host, enable the QEMU guest agent:
sudo virsh shutdown ubuntu-vm
sudo virsh dumpxml ubuntu-vm > /tmp/ubuntu-vm.xml
Edit the XML file to add the guest agent channel:
sudo nano /tmp/ubuntu-vm.xml
Add this section if it doesn't exist:
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>
Update the VM definition:
sudo virsh define /tmp/ubuntu-vm.xml
sudo virsh start ubuntu-vm
Step 5: Optimize Performance (Optional)
For better disk performance, convert to virtio disk:
sudo virsh shutdown ubuntu-vm
sudo virsh edit ubuntu-vm
Change the disk bus from sata
to virtio
:
<disk type='file' device='disk'>
...
<target dev='vda' bus='virtio'/>
...
</disk>
Shared Folders with Ubuntu VM
If you want to share files between the host and Ubuntu VM:
The simplest approach is to use SAMBA (as described in the Windows VM guide)
Alternatively, you can use SSH file transfer:
# Inside the Ubuntu VM, install SSH server
sudo apt install -y openssh-server
# On the host, use scp to copy files
scp /path/to/file username@ubuntu-vm-ip:/destination/path/
# Or use SFTP in your file manager:
# Enter sftp://username@ubuntu-vm-ip/ in your file manager address bar
- For drag and drop functionality, ensure spice-vdagent is installed
Remember to use the VM service script to start all necessary services before launching your Ubuntu VM:
vm-start
Latest Comments
Sign in to add a commentNo comments yet. Be the first to comment!