Posts /

Use QEMU to Play with Linux Kernel

Twitter Facebook Google+
26 Feb 2017

Command summary

qemu-img create -f raw kernel_experiments 10G

qemu-system-x86_64 -cdrom ~/path/distro_iso.iso -boot order=d -drive \
                file=kernel_experiments,format=raw -m 2G

qemu-system-x86_64 -enable-kvm -net nic -net user,hostfwd=tcp::2222-:22,smb=$PWD/ \
                   -daemonize -m 4G -smp cores=4,cpus=4 kernel_experiments
Summary of all commands used in this post

Introduction

QEMU is a generic machine emulator based on dymamic translation [3]. QEMU can operates in two different modes [2]:

If you have recent x86 machine, you can also execute QEMU with kvm which increases the speed. Finally, we decided to use QEMU since it is a very popular open source tool and it provides a many resources for easily play with virtual machine.

Install QEMU and KVM

Install QEMU and Samba package. We want the samba package for allowing the directory share.

Arch

Install Debian packages [1]:

sudo pacman -S qemu samba qemu-arch-extra

Debian

Install Debian packages [2]:

sudo apt install qemu samba samba-client

Create an image

In order to use Qemu to install and use a Linux Distribution, you have to create a image disk. For illustration, we create an image named kernel_experiments with 15G:

qemu-img create -f raw kernel_experiments 15G

Installing an Distro

Next, download the distribution ISO of your preference (I recommend Debian and Arch). With your qemu image and your distro ISO, proceed with the command:

qemu-system-x86_64 -cdrom ~/path/distro_iso.iso -boot order=d -drive \
                   file=kernel_experiments,format=raw -m 2G

Configure ssh

Start Qemu

Finally, after the installation it is time to start the machine with the command:

qemu-system-x86_64 -enable-kvm -net nic -net user,hostfwd=tcp::2222-:22,smb=$PWD/ \
                   -daemonize -m 2G -smp cores=4,cpus=4 kernel_experiments

References

  1. QEMU Arch Linux
  2. QEMU Debian
  3. QEMU

Twitter Facebook Google+