Skip to content

Instantly share code, notes, and snippets.

@hughpearse
Last active May 20, 2021 13:39
Show Gist options
  • Save hughpearse/98c1ae466e9462b44e305649fbfd5db2 to your computer and use it in GitHub Desktop.
Save hughpearse/98c1ae466e9462b44e305649fbfd5db2 to your computer and use it in GitHub Desktop.
Building and running User Mode Linux (UML)
docker pull gcc
docker run --name gcc -it gcc /bin/bash
cd ~
apt update
apt-get -y install build-essential flex bison xz-utils wget ca-certificates bc linux-headers-5.10.0-6-common slirp
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.12.4.tar.xz
tar -xf linux-5.12.4.tar.xz
cd linux-5.12.4
make menuconfig ARCH=um
UML-specific Options:
- Host filesystem
Networking support (enable this to get the submenu to show up):
- Networking options:
- TCP/IP Networking
UML Network devices:
- Virtual network device
- SLiRP transport
=> Save and exit
make ARCH=um -j$(nproc)
mkdir -p ~/bin
cp linux ~/bin/linux
export PATH=$PATH:$HOME/bin
mkdir -p $HOME/prefix/uml-demo
cd $HOME/prefix
wget https://dl-cdn.alpinelinux.org/alpine/v3.13/releases/x86_64/alpine-minirootfs-3.13.5-x86_64.tar.gz
cd uml-demo
tar xf ../alpine*.tar.gz
wget -O tini https://github.com/krallin/tini/releases/download/v0.18.0/tini-static
chmod +x tini
export TMPDIR=/tmp
slirp > /dev/null 2>&1 &
linux root=/dev/root rootfstype=hostfs rootflags=$HOME/prefix/uml-demo rw mem=64M init=/bin/sh eth0=slirp,,/usr/bin/slirp
mount -t proc proc proc/
mount -t sysfs sys sys/
ifconfig eth0 10.0.2.14 netmask 255.255.255.240 broadcast 10.0.2.15
route add default gw 10.0.2.2
nslookup google.com 8.8.8.8
uname -av
exec /tini -s /bin/sh
exit
kill %1
exit
docker container stop gcc
docker container rm gcc
Sources
https://sudonull.com/post/25569-How-to-start-using-User-Mode-in-Linux-ITSumma-Blog
https://christine.website/blog/howto-usermode-linux-2019-07-07
https://www.cnblogs.com/dream397/p/14251617.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment