Giter Club home page Giter Club logo

kvm-kernel-example's Introduction

KVM-Kernel Example

The source code are examples on my blog: Learning KVM - implement your own Linux kernel.

I've described how to implement a KVM-based hypervisor and key points to implement Linux kernel on my blog. You can leave comments in the blog or file issues here if you have questions or find any bugs.

Dir

Hypervisor

The KVM-based hypervisor, its role is like qemu-system.

Kernel

A extremely simple Linux kernel, supports few syscalls.

User

Simple ELF(s) for testing our kernel. Pre-built user program was provided, and you can re-generate by the following commands:

$ pip2 install pwntools
$ cd user
$ ./gen.py

NOTE: You have to install Python 2.x in advance.

Setup

Check KVM support

Check if your CPU supports virtualization:

$ egrep '(vmx|svm)' /proc/cpuinfo

NOTE: CPUs in VM might not support virtualization (i.e. no nested virtualization). For example, EC2 on AWS doesn't support using KVM.

Install KVM device

Check if KVM device exists:

$ ls -la /dev/kvm

If /dev/kvm is not found, you can enable it (on Ubuntu) with:

$ sudo apt install qemu-kvm

If you are not root, you need to add yourself into the kvm group to have permission for accessing /dev/kvm.

$ sudo usermod -a -G kvm `whoami`

Remember to logout and login to have the group changing effective.

How to run

$ git clone https://github.com/david942j/kvm-kernel-example
$ cd kvm-kernel-example && make
$ hypervisor/hypervisor.elf kernel/kernel.bin user/orw.elf /etc/os-release
# NAME="Ubuntu"
# VERSION="18.04.1 LTS (Bionic Beaver)"
# ID=ubuntu
# ID_LIKE=debian
# PRETTY_NAME="Ubuntu 18.04.1 LTS"
# VERSION_ID="18.04"
# HOME_URL="https://www.ubuntu.com/"
# SUPPORT_URL="https://help.ubuntu.com/"
# BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
# PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
# VERSION_CODENAME=bionic
# UBUNTU_CODENAME=bionic
# +++ exited with 0 +++

Environment

I only tested the code on Ubuntu 18.04, but I expected it works on all KVM-supported x86 Linux distributions. File an issue if you find it's not true.

kvm-kernel-example's People

Contributors

david942j avatar jserv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.