A few months ago I wanted to test something that involved OpenVPN on a small VPS I rented.
At this point it would've been easier to give up or temporarily rent another VPS, but I really wanted to run the test on this particular one.
Enter: User Mode Linux
User Mode Linux (UML) is a way to run the Linux kernel as an user-mode process on another Linux system, no root or special setup required.
At its time it was considered to be useful for virtualization, sandboxing and more. These days it's well past its prime but it still exists in the Linux source and more importantly works.
You'd build a kernel binary like this:
git clone --depth=100 https://github.com/torvalds/linux cd linux make ARCH=um defconfig nice make ARCH=um -j4 strip vmlinux
The virtual machine will require a root filesystem image, you can obtain one
via the usual ways such as
debootstrap (Debian/Ubuntu) or
which I won't cover here.
Now onto the next issue: How is networking supported in User Mode Linux?
slirpimplementation is found on sourceforge: https://sourceforge.net/projects/slirp/
security.patchthat swaps out a few
/* TODO: length check */in other places.
The only logical thing to do now is to rewrite
slirp so that it works.
Here's the code: https://gist.github.com/sfan5/696ad2f03f05a3e13952c44f7b767e81
vmlinux: the User Mode Linux kernel
root_fs: a root filesystem image
/path/to/slirp: the compiled slirp binary (build it using the Makefile that comes with it)
At this point your virtualized Linux system is just one command away:
ip a add dev eth0 10.0.2.1 && ip l set eth0 up && ip r add default dev eth0
echo nameserver 10.0.2.3 >/etc/resolv.conf
You can forward port(s) from outside into the VM by editing the commented out code section in