host kernel version: 3.16.36-1+deb8u2
target kernel version: 4.9-rc5
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
default config:
make defconfig ARCH=um
change the config as you like:
make menuconfig ARCH=um
build:
make linux ARCH=um
install debootstrap:
apt-get install debootstrap
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
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
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