How to Install and Use QEMU on Ubuntu
How to Install and Use QEMU on Ubuntu
QEMU is an open-source emulator that enables users to run virtual machines and emulate different hardware architectures. It provides a robust solution for developers, testers, and system administrators who need to run multiple operating systems on a single machine. In this guide, we will explore how to install QEMU on Ubuntu, configure it for use, and run a virtual machine.
System Requirements
Before you start installing QEMU, ensure that your system meets the following requirements:
An Ubuntu-based distribution (such as Ubuntu 20.04 or later).
A minimum of 2 GB of RAM (4 GB recommended for better performance).
At least 20 GB of free disk space.
An active internet connection for downloading packages.
Step 1: Update Your System
It is crucial to keep your system updated before installing new software. Open your terminal and run the following commands:
sudo apt update
sudo apt upgrade -y
These commands will ensure that all your packages are up to date and ready for the installation process.
Step 2: Install QEMU
To install QEMU, you can use the official Ubuntu repositories. Run the following command in your terminal:
sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils -y
This command installs QEMU along with KVM (Kernel-based Virtual Machine) and other necessary packages that enable virtualization. The installation process might take a few minutes, depending on your internet speed.
Step 3: Verify the Installation
Once the installation is complete, you can verify that QEMU has been installed correctly by checking its version. Run the following command:
qemu –version
You should see the installed version of QEMU displayed in the terminal. If you see the version number, it means that QEMU is installed successfully.
Step 4: Configure KVM
To utilize KVM with QEMU, you need to ensure that your CPU supports virtualization. You can check this by running:
egrep -c ‘(vmx|svm)’ /proc/cpuinfo
If the output is greater than zero, your CPU supports virtualization. Next, you must add your user account to the kvm group to run QEMU with KVM support:
sudo adduser $USER kvm
After executing this command, log out and back in for the changes to take effect.
Step 5: Create a Virtual Machine
Now that QEMU and KVM are set up, you can create a virtual machine. To do this, you need an ISO image of the operating system you wish to install. For this example, letβs use an Ubuntu ISO image.
Download the Ubuntu ISO: You can download the latest version of Ubuntu from the official website.
Create a Disk Image: Before you launch the virtual machine, create a disk image to store the operating system. For example, to create a 20 GB disk image named ubuntu_vm.img, use the following command:
qemu-img create -f qcow2 ubuntu_vm.img 20G
Launch the Virtual Machine: Use the following command to launch your virtual machine:
qemu-system-x86_64 -hda ubuntu_vm.img -cdrom /path/to/ubuntu.iso -boot d -m 2048 -smp 2 -net nic -net user
-hda: Specifies the disk image to use.
-cdrom: Specifies the ISO file to use as a CD-ROM.
-boot d: Boots from the CD-ROM first.
-m: Allocates memory (in MB) to the virtual machine. Here, we allocate 2048 MB (2 GB).
-smp: Allocates the number of CPU cores. Here, we allocate 2 cores.
-net nic: Creates a virtual network interface card.
-net user: Configures user-mode networking.
Install the Operating System: After launching the command, the QEMU window will open, allowing you to install Ubuntu just like you would on a physical machine. Follow the installation prompts to complete the setup.
Step 6: Using the Virtual Machine
Once the operating system is installed, you can boot your virtual machine using the disk image you created. Simply run:
qemu-system-x86_64 -hda ubuntu_vm.img -m 2048 -smp 2 -net nic -net user
You can manage the virtual machine through the QEMU window, allowing you to install applications, access files, and perform tasks just as you would on a real machine.
Additional Configuration
QEMU offers a wide range of options for advanced configurations:
Networking: For more advanced networking setups, you can create a bridged network connection to allow your virtual machine to communicate with other devices on your network.
Storage Options: You can create multiple disk images for different purposes or use shared folders to access files from the host machine.
Snapshots: QEMU allows you to take snapshots of your virtual machines, enabling you to restore to a previous state if needed.
Thank you for reading our article! If you’re interested in learning more about Linux systems, Libvirt, and Docker Compose, feel free to check out the link below. π
How to Get Started with Libvirt on Linux
How to Install Docker Compose on Linux
If you’re looking to boost your server skills, you can explore these packages by selecting a reliable and suitable server from our site. Wishing you the best of luck! π
Conclusion
By following the steps outlined above, you can successfully install and use QEMU on your Ubuntu system. QEMU provides a powerful and flexible solution for virtualization, allowing you to test, develop, and run multiple operating systems with ease. For more information and advanced usage options, you can refer to the QEMU documentation.
With QEMU, the possibilities for experimentation and development are vast, making it an invaluable tool for both professionals and enthusiasts in the Linux community.