Virtual machine on linux: qemu
Create a harddrive file
qemu-img create -f qcow2 ./qemu-vm-hdd.qcow2 32G
qemu-imgis a tool to create or edit harddrive images for the virtual machine. This is where the filesystem of the virtual machine will typically be.
-f qcow2sets the format of the harddrive image file (alternatively
rawmay be used).
./qemu-vm-hdd.qcow2 32Ginitializes a new file at the given location with a size of 32 GiB.
Run the virtual machine using the harddrive file
qemu-system-x86_64 -cdrom "./os-installation-disk.iso" -vga vmware -cpu host -enable-kvm -m 4G -smp 4 -drive file=./qemu-vm-hdd.qcow2,format=qcow2
qemu-system-x86_64indicates that the chosen architecture is
x86_64(other common architectures are:
systempart of this command indicates that it should run a complete system, and not just any stand-alone application.
-cdrom "./os-installation-disk.iso"is a bootable iso-file. Typically, an OS provides an iso-file for download from their website or mirrors.
-vga vmwareis used, because the default value for this option (
std) resulted in wrong colors (blue is red, and vice versa) being displayed.
-cpu host -enable-kvmallows the virtual machine to directly use the CPU of the host (=parent) using a kernel virtualization module (Kernel-based Virtual Machine (KVM)).
-m 4G -smp 4enables qemu to use respectively 4GB of RAM and 4 CPU cores.
-drive file=./qemu-vm-hdd.qcow2,format=qcow2is the file that represents the virtual machine's harddrive, this is used as a permanent internal storage so to speak. You can also use the format:
-bios /usr/share/edk2-ovmf/x64/OVMF_CODE.fddmakes it possible to boot from GPT EFI partition (using
The first time you start the virtual machine using the given command, the virtual machine will boot using the provided installation disk (
The harddrive file will be created by the virtual machine, if not exists already.
During this time you will install a bootable OS on the virtual machine's harddrive file (
Unless there are other filesystems mounted into the virtual machine, there will only be one harddrive available within the virtual machine, which refers to the given harddrive file.
The second time you start the virtual machine, you may run the command without the
-cdrom "./os-installation-disk.iso" option, since it should now boot from the newly installed OS.
By default, the virtual machine will already use the internet/network access of the host.