Skip to content

Instantly share code, notes, and snippets.

@kuyagic
Forked from gaoyifan/uml-on-debian.md
Created February 19, 2017 05:41
Show Gist options
  • Save kuyagic/83d7a3348e4bea61615a94888730082b to your computer and use it in GitHub Desktop.
Save kuyagic/83d7a3348e4bea61615a94888730082b to your computer and use it in GitHub Desktop.
User Mode Linux on Debian Jessie

User Mode Linux on Debian Jessie

host kernel version: 3.16.36-1+deb8u2

target kernel version: 4.9-rc5

Build UML kernel

Preparation

Install build environment:

apt-get install build-essential libtool automake libncurses5-dev kernel-package

Download kernel source code:

wget -O- https://cdn.kernel.org/pub/linux/kernel/v4.x/testing/linux-4.9-rc5.tar.xz | tar -xJ
cd linux-4.9-rc5

Build

default config:

make defconfig ARCH=um

change the config as you like:

make menuconfig ARCH=um

build:

make linux ARCH=um

Create a Debian Jessie rootfs

Preparation

install debootstrap:

apt-get install debootstrap

Create rootfs

Create a file used as root partition:

fallocate -l 4G rootfs

Format with ext4:

mkfs.ext4 rootfs

Mount to a tmp location:

mkdir mnt
mount rootfs mnt

Bootstrap a basic Debian system:

debootstrap jessie mnt http://ftp.cn.debian.org/debian

Config rootfs

change password:

chroot mnt /bin/bash

# run `passwd` under chroot environment
passwd root

# exit chroot environment
exit

change fstab:

echo "/dev/ubda / ext4 defaults 0 0" > mnt/etc/fstab

umount rootfs:

umount mnt

Run UML

install uml-utilities and screen:

apt-get install uml-utilities screen

run UML:

./linux ubda=rootfs eth0=tuntap,,,192.168.80.254 mem=512M

attach to tty:

screen /dev/pts/1

assign address:

# run in UML
ifconfig eth0 192.168.80.1 up

add default gateway:

# run in UML
ip route add default via 192.168.80.254 dev eth0

if you want UML get access to extranet, run the fowllowing command in host server:

iptables -t nat -A POSTROUTING -s 192.168.80.0/24 -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment