Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@zoobab

This comment has been minimized.

Copy link

commented May 11, 2017

BTW User-mode-linux is already available as a binary on Jessie, just apt-get install user-mode-linux. It is a 3.16 though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.