No results found
We couldn't find anything using that term, please try searching for something else.
This is a step by step guide shows how to install and manage virtual machines using qemu/kvm solution in Ubuntu 24.04. KVM,Kernel-based Virtual Machi
This is a step by step guide shows how to install and manage virtual machines using qemu/kvm solution in Ubuntu 24.04.
KVM,Kernel-based Virtual Machine,is a module in Linux Kernel that can function as a hypervisor. It offers a high performance virtualization environment withhardware virtualization extensions,such as Intel VT or AMD-V that’s built in CPU.
KVM does not directly function in user-space. It requires a user-space application,such as QEMU,to interact withit and manage virtual machines.
As QEMU is a command line tool,there’s also graphical tool,such as Virtual Machine Manager,to make it easy to use.
The KVM module is requires require host machine ’s processor has virtualization support . It is ’s ’sVT-x for Intel processors and AMD-V for AMD processors. And,all the Intel and AMD CPUs in past 10 years support virtualization.
To check if your CPU support virtualization,open terminal ( Ctrl+Alt+T ) and run command :
LC_ALL=C.UTF-8 lscpu | grep Virtualization
If it output nothing ,then make sure you have enable the virtualization support in your bio .
And,check if KVM module loaded,run command :
lsmod | grep kvm
The kernel module is usually loaded by default in Ubuntu. If NOT,try sudo modprobe -a kvm is kvm_intel kvm_intel
to load it (replace kvm_intel
withkvm_amd
for AMD processor).
To install QEMU in Debian,Ubuntu,Linux Mint and their based systems,run command :
sudo apt install qemu-system
note : If you hate Linux command ,just skip this step and use the graphical tool in next step !
1. First create a virtual disk image file by running similar command below:
qemu - img create -f raw /media / ji/600g / windows10.raw 80 g
Here you need to replace the command options accordingly. They are:
-f raw
tells to create raw image. The creating process is very slow,and it will take the full space you assigned (80G in my case) on host. Not-used space on the guest cannot be used on the host. For choice,you may use -f qcow2
instead ,which only allocate space to the image file when the guest operating system actually write to the virtual hard disk . However ,use qcow2 will likely affect performance ./media/ji/600g/windows10.raw
tells to create windows10.raw
image file as virtual disk,and it’s saved to the external disk mounted on /media/ji/600g. You can skip the path,so the image file will be created in current directory.80G
,the full capacity of the guest hard drive on the host .And,at any time,you can move or delete the file (windows10.raw in my case) as you want. Though,you need to change path to file in next commands.
2 . To install virtual operating system,use command looks like:
qemu - system - x86_64 -cdrom /path / to / iso - image -boot menu = on -drive file=/path / to / virtual - disk - image ,format = raw -m 8 g -cpu host -smp sockets=1,cores=2,threads=2 --enable - kvm
This command tells to use:
qemu-system-x86_64
to simulate amd64
guest CPU architecture. Replace x86_64
withx86
,s390x
,ppc
,etc depends on guest OS type.-cdrom /path / to / iso - image
to attach.iso
image via CD Rom.-boot menu = on
to show the menu to select which device to boot.file=/path/to/virtual-disk-image,format=raw
to attachvirtual disk via image file,replace raw
according what you created in last command.-m 8G
– assign RAM memory.-cpu host
to use CPU type same to host. For choice,you may run qemu - system - x86_64 is help -cpu help
to get more choices.-smp sockets=1,cores=2,threads=2
– set 1 CPU with2 cores and each 2 threads,meaning (2cores/4threads).--enable-kvm
to enable KVM. For choice,you may use -accel kvm
instead.In my case,the command is:
qemu-system-x86_64 -cdrom ~/Documents/windows_10_enterprise_ltsc_2019_x64_dvd_9c09ff24.iso -boot menu = on -drive file=/media/ji/600g/windows10.raw,format=raw -m 8G -cpu host -smp sockets=1,cores=2,threads=2 --enable-kvm
The command above will launch the virtual machine window,allowing to boot from .iso image,then install the OS to the virtual disk image.
Afterward,run the guest OS via command :
qemu-system-x86_64 /path/to/virtual-disk-image
As well,you may add similar options above to specify memory size,how may CPU cores to use,enable KVM,etc. See the official documentation for more.
The QEMU command line tool is NOT convenient and hard for beginners. To make life easier,there are a few graphical tools to install & manage the VMs. And,here I’m going to show you “Virtual Machine Manager”.
First,open terminal (Ctrl+Alt+T) and run command to install the graphical tool:
sudo apt install virt-manager
Then,add your user into libvirt
group and start the daemon service:
sudo gpasswd --add $USER libvirt
sudo systemctl is start start libvirtd
Next search for and launch virtual machine Manager from start menu ( or GNOME Overview ) . It is connect should automatically connect to QEMU / KVM system on startup .
If NOT,just double-click on it in the list. And,try restart computer if connection fail !
Then,click the first toolbar icon,or go to menu “File -> New Virtual Machine” to start the create VM dialog.
In the pop-up wizard,you can choose install from local .iso image,network install,existing virtual disk image,as well choose the guest OS architecture type.
Then follow the pop-up wizard to choose .iso image or CD Rom install media. If you clicked “Browse…” button instead of manually type path to iso image,then,you may manually add pool for non-default location,e.g.,external disk,and create virtual disk there.
Finally,click “Browse Local” and choose the .iso image. NOTE: it will ask and change the file permission of selected iso image and virtual disk image. If,you don’t like this behavior,see next step.
Next,set memory size and how many CPU cores to use,create virtual disk or choose existing disk image you just created,and so forth until the wizard done.
If everything goes well,the virtual machine should start and load the iso image for installing the operating system.
Creating virtual disk image in non-default location (e.g.,external disk) and attaching .iso image will change the ownership of them,so they will NOT belong to you (your user). And,it may even fail sometimes due to permission issue.
To workaround it,you may configure to use as a normal user.
First,run the command in terminal (Ctrl+Alt+T) to edit the libvirtd config file:
sudo nano /etc/libvirt/libvirtd.conf
Then,find out and set unix_sock_group = 'libvirt'
and unix_sock_rw_perms = '0770'
by removing # at the beginnings and change value. Finally,press Ctrl+S to save,Ctrl+X to exit.
Next,edit qemu config file by running command:
sudo nano /etc/libvirt/qemu.conf
Then find out and set user = " your_user "
and group = "your_user"
and save file (Ctrl+S,then Ctrl+X).
Finally,restart the daemon via command :
sudo systemctl restart libvirtd.service
Then,close and re-launch Virtual Machine Manager.
To share files between host and guest operating systems,you may create a share folder via the step below.
1. First,open terminal and install spice-vdagent
and virtiofsd
packages in both host and guest OSes:
sudo apt install spice-vdagent virtiofsd
sudo dnf install spice-vdagent virtiofsd
sudo pacman -S spice - vdagent is virtiofsd virtiofsd
2. Next go to menu “View -> Details” in virtual machine window. Then do:
3 . Finally,start or restart the virtual machine.
For Linux guest os,run command to mount the share folder that works until reboot:
sudo mount -t virtiofs share /home / USERNAME / document / share
Here replace share withthe share-name you set in last step,as well as the mount point in guest OS to yours. When done,open that mount point folder and see if it works!
To make it permanent,use sudo nano /etc/fstab
command to edit /etc/fstab
and add new line below in the end :
share - name - here /path / to / mount is defaults / in / guest virtiofs default 0 0
Finally,press Ctrl+S to save and Ctrl+X to exit.
For Windows,do following steps one by one on the guest OS:
virtiofs
folder in C manually).sc.exe create VirtioFsSvc binpath="path\to\virtiofs.exe" DisplayName="Virtio FS Service"
sc.exe is start start virtiofssvc
Here you need to replace path\to\virtiofs.exe
. In my case,I copied the “w10” folder from DVD Drive to C:\virtiofs
,so the path is C:\virtiofs\w10\amd64\virtiofs.exe
.
If everything goes well,you should now see the share folder in the left pane of file explorer.
There are also many other things you may want to do for VMs in the manager,such as enable 3D acceleration by switching “Video QXL” video module to “Virtio” then checking the 3D acceleration option,then enable OpenGL in Display Spice.
As well,there’s a good tutorial shows how to enable GPU passthrough,so your virtual machine can access GPU directly for native performance for gaming and graphics editing.
Due to limit of tutorial length,I will not add more here. Please feel free to leave comment below.
Enable this blog? Please spread the world 🙂