---
title: Qemu - Install Guide
tags: VM, qemu
---
# QEMU-KVM - How to install and create a VM
1. Download and build QEMU source code
```bash=1
wget http://download.qemu-project.org/qemu-2.8.0.tar.xz
tar xvJf qemu-2.8.0.tar.xz
cd qemu-2.8.0
./configure --target-list=x86_64-softmmu \
--python=/bin/python2.7 \
--prefix=${TARGET_DIR}
make -j 4
make install
```
- `${TARGET_DIR}` is your absolute path you want to install your Qemu to, e.g. */home/demouser/qemu-bin*
2. Create the image format supported by QEMU
```bash=1
mkdir project
cd project
${TARGET_DIR}/bin/qemu-img create -f raw ubuntu.img 15G
```
- ubuntu.img is the image file name
- 15G is the size of the image file
3. Install ubuntu-16.04 server on VM
1. Prepare to boot the kernel
```bash=1
${TARGET_DIR}/bin/qemu-system-x86_64 \
--enable-kvm -drive format=raw,file=ubuntu.img,if=virtio \
-m 2048 -net nic,model=virtio -net user \
-rtc base=localtime,clock=host \
-cdrom /home/share/ubuntu/ubuntu.iso -kernel /home/share/ubuntu/vmlinuz \
-nographic -append console=ttyS0 \
-initrd /home/share/ubuntu/initrd.gz
```
Command illustration:
- -m : memory size
- -net : network interface setting
- -cdrom : ubuntu-16.04 image
- -kernel vmlinuz : a compresses linux kernel from vmlinux
- -nographic -append console=ttyS0 : Redirect standard output to host machine
2. Install ubuntu 16.04







input "your studentID"-0





















3. **Terminate QEMU**
1. Open a new session on terminal and login your account
2. **Kill QEMU**
```bash=1
killall qemu-system-x86_64
```
4. Exexute the virtual machine:
```bash=1
${TARGET_DIR}/bin/qemu-system-x86_64 \
--enable-kvm -drive format=raw,file=image_file,if=virtio \
-m 2048 -net nic,model=virtio -net user \
-rtc base=localtime,clock=host \
-curses
```
- You will find out your VM is blocked in this step ...

- Two ways to solve this issue:
1. Switch to QEMU monitor console in the current terminal
- Press `alt` + `2` or `esc` + `2` to switch to QEMU console, type `sendkey ctrl-alt-f1`, and then press `enter`

- Press `alt` + `1` or `esc + 1` to switch back to screen

2. Access the QEMU monitor console via Telnet
- Add the telnet option (`-monitor telnet:127.0.0.1:5566,server,nowait`) when launching the VM:
```bash=1
${TARGET_DIR}/bin/qemu-system-x86_64 \
--enable-kvm -drive format=raw,file=ubuntu.img,if=virtio \
-m 2048 -net nic,model=virtio -net user \
-rtc base=localtime,clock=host \
-curses \
-monitor telnet:127.0.0.1:5566,server,nowait
```
- Open a new session on terminal and type:
- $ `telnet 127.0.0.1 5566`
- Enter the QEMU monitor and input:
- (qemu) `sendkey ctrl-alt-f1`
- Switch to the original session and log in to your account