UML

From Segfault
Jump to navigation Jump to search

Installation

We'll only need a UML kernel:

make ARCH=um defconfig
make ARCH=um

Usage

We'll need to create a (very basic) root file system first:

dd if=/dev/zero of=disk0.img bs=1M count=128
mkfs.ext2 disk0.img
sudo mount -o loop disk0.img /mnt/disk/

As root:

cd /mnt/disk/
mkdir {bin,dev,mnt,proc,sys}

cat > init << EOF
#!/bin/sh
mount -t devtmpfs none /dev
mount -t proc     none /proc
mount -t sysfs    none /sys
echo
exec /bin/sh
EOF
chmod +x init

cp /sbin/busybox bin/
bin/busybox --install bin

With that in place, we should be able to start UML as a user:

./linux mem=1024M ubd0=disk0.img
# uname -nrv
(none) 5.3.0-rc6-00115-g9e8312f5e160 #1 Thu Aug 29 00:28:07 PDT 2019

The Gentoo Wiki has more examples on UML usage.

Links