Using QEMU for Emulation and Virtualization (with examples)
1: Boot from image emulating i386 architecture
qemu-system-i386 -hda image_name.img
Motivation:
This command is used to boot a QEMU instance from a disk image while emulating the i386 architecture. It is useful when testing software or operating systems designed for this specific architecture.
Explanation:
qemu-system-i386
: This specifies the emulator executable for the i386 architecture.-hda image_name.img
: This option specifies the path to the disk image that will be used as the hard drive for the virtual machine.
Example Output:
If the disk image is a bootable operating system, QEMU will start emulating the i386 architecture and the operating system will boot up inside the virtual machine.
2: Boot from image emulating x64 architecture
qemu-system-x86_64 -hda image_name.img
Motivation:
This command is used to boot a QEMU instance from a disk image while emulating the x64 architecture. It is useful when testing or running software that requires x64 compatibility.
Explanation:
qemu-system-x86_64
: This specifies the emulator executable for the x64 architecture.-hda image_name.img
: This option specifies the path to the disk image that will be used as the hard drive for the virtual machine.
Example Output:
If the disk image is a bootable operating system, QEMU will start emulating the x64 architecture and the operating system will boot up inside the virtual machine.
3: Boot QEMU instance with a live ISO image
qemu-system-i386 -hda image_name.img -cdrom os_image.iso -boot d
Motivation:
This command is used to boot a QEMU instance with a live ISO image, allowing for testing or running an operating system directly from the ISO image without installing it.
Explanation:
qemu-system-i386
: This specifies the emulator executable for the i386 architecture.-hda image_name.img
: This option specifies the path to the disk image that will be used as the hard drive for the virtual machine.-cdrom os_image.iso
: This option specifies the path to the ISO image that will be used as the CD-ROM drive for the virtual machine.-boot d
: This specifies that the virtual machine should boot from the CD-ROM drive.
Example Output:
If the ISO image contains a live operating system, QEMU will start emulating the i386 architecture and the live operating system will boot up inside the virtual machine.
4: Specify amount of RAM for instance
qemu-system-i386 -m 256 -hda image_name.img -cdrom os-image.iso -boot d
Motivation:
This command allows specifying the amount of RAM allocated to the QEMU instance. It is useful when testing or running software that requires a specific amount of memory.
Explanation:
qemu-system-i386
: This specifies the emulator executable for the i386 architecture.-m 256
: This option specifies the amount of memory to allocate to the virtual machine. In this example, it allocates 256 megabytes of RAM.-hda image_name.img
: This option specifies the path to the disk image that will be used as the hard drive for the virtual machine.-cdrom os-image.iso
: This option specifies the path to the ISO image that will be used as the CD-ROM drive for the virtual machine.-boot d
: This specifies that the virtual machine should boot from the CD-ROM drive.
Example Output:
QEMU will start emulating the i386 architecture with 256 megabytes of allocated RAM. The operating system from the disk image or ISO image will boot up inside the virtual machine.
5: Boot from physical device
qemu-system-i386 -hda /dev/storage_device
Motivation:
This command is used to boot a QEMU instance directly from a physical device, such as a USB drive or a hard drive. It is useful for testing or debugging bootable media without altering the actual system.
Explanation:
qemu-system-i386
: This specifies the emulator executable for the i386 architecture.-hda /dev/storage_device
: This option specifies the path to the physical device that will be used as the hard drive for the virtual machine.
Example Output:
QEMU will start emulating the i386 architecture and boot directly from the specified physical device. The contents of the device, such as a bootable medium, will be executed inside the virtual machine.