Douglas Winslow's internet home page updates | tech | games | art | community | parodies | e-mail | index

Self-centric dependency staging in User-Mode Linux

November 1, 2023 at 3 P.M. Eastern Time

Want to be productive on a second installation of Linux? Wow, who doesn't!

User-Mode Linux is a way to configure and compile a standard Linux kernel to run as a process on an existing operating system installation. This is useful for many reasons if you want to learn or debug the kernel (including filesystems and process accounting), or if you just don't want to play with virtual machine software to get your projects accomplished. I came back to UML as a side-hobby on October 24th.

In this example, I show how to create a small EXT4-fs filesystem image, copy an existing version of the busybox all-in-one binary and its dependencies into the main directory of it (wow!), set up a basic rcS script for init to run, set up directories for the kernel interstitials (dev, proc, sys), and symbolic link any directories (bin, lib, etc) back to CWD (the current working directory). You might have noticed a loop in there that automatically symlinks all the busybox routines into CWD, as well. It's even got the vi editor. It's a busy directory listing, but it works.

If you're not a fan of placing things self-centric in one place such as this, and instead you'd like the distraction of using mkdir some more to build a directory structure, consider the gains in productivity that come from not having to keep virtualizing new directory contexts in your understanding of CWD on a system-wide level. It may be that certain distraction-dependent mindsets can arise when participating in UNIX file management; that may be due to the default directory management utilities.

After you're done trying this example, if you have a spare physical media to write your filesystem to, a proper startup kernel, and a boot loader, you should be able to boot a PC as an Linux box with the result. If so, you should configure an MBR (master boot record) upon your media first as a minority of personal computers support Intel-EFI. If you have the proper hardware drivers compiled into your kernel software, you can have Linux find your interfaces (video, keyboard bus, storage, etc.). I'm using defconfig in this provided example for a compile of UML, however, you can also try tinyconfig and others without the UML designation to compile a startup kernel. Keep your .config files saved!

In some ways, UML may help you understand how really very simple or maybe fun it is to bring up your own Linux system in 2023, where otherwise it's a lot of setting LD_LIBRARY_PATH and hoping you have a binary's dependencies where you expect them to be if you're dealing with clashing installations. Maybe you'll see a productivity boost from this style of working or maybe not. There are some namespace efficiencies I'd like to try as I attempt to grow my particular UML installation. If you're a Linux user, you know there are few other small-form operating systems available today that have the flexibility to work with filesystem data like this. In all honesty, what can I say? If Linux II ever happens, maybe it's time to look back to the "minix" filesystem as the future..

 $ tar -xf linux-6.0.tar.xz
 $ cd linux-6.0/
 $ xz -dc patch-6.1.xz | patch -p1
 $ xz -dc patch-6.2.xz | patch -p1
 $ xz -dc patch-6.3.xz | patch -p1
 $ xz -dc patch-6.4.xz | patch -p1
 $ xz -dc patch-6.5.xz | patch -p1
 $ xz -dc patch-6.6.xz | patch -p1
 $ cd ..
 $ mv linux-6.0/ linux-6.6/

 $ cd linux-6.6/
 $ make ARCH=um defconfig
 $ make ARCH=um linux
 $ ./linux
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
Aborted

 $ mkdir mnt
 $ dd if=/dev/zero of=linux.fs bs=1 count=1 seek=32M
 $ mkfs.ext4 linux.fs
 $ tune2fs linux.fs -U 01234567-9abc-ef01-3456-89abcdef0123
 $ tune2fs linux.fs -L @`date +%Y%m%d%H%M%S`
 $ su root

 # mount linux.fs mnt
 # cd mnt

 # ln -s . bin
 # cp -p /usr/bin/busybox .
 # ln -s . lib64
 # ln -s . lib
 # ln -s . x86_64-linux-gnu
 # for i in `ldd ./busybox | sed -e "s/[\t ]/\n/g" | grep ^/`; do cp -pv $i .; done
 # for i in `./busybox --list`; do ln -sv busybox $i; done

 # mkdir dev proc sys
 # ln -s . etc
 # ln -s . init.d
 # echo "mount dev /dev -t devtmpfs" > rcS
 # echo "mount proc /proc -t proc" >> rcS
 # echo "mount sys /sys -t sysfs" >> rcS
 # echo "echo \"* Hello, world.\"" >> rcS
 # chmod +x rcS

 # cd ..
 # umount linux.fs
 # exit

 $ ls -l linux linux.fs
-rwxr-xr-x 2 drw drw 85803496 Nov  1 14:59 linux
-rw-r--r-- 1 drw drw 33554433 Nov  1 17:36 linux.fs
 $ strip linux
 $ ls -l linux
-rwxr-xr-x 2 drw drw 6026920 Nov  1 15:52 linux

 $ time ./linux ubda=linux.fs
EXT4-fs (ubda): mounted filesystem 01234567-9abc-ef01-3456-89abcdef0123 ro with ordered data mode. Quota mode: none.
VFS: Mounted root (ext4 filesystem) readonly on device 98:0.
* Hello, world.
/ # mount / -o remount,rw
EXT4-fs (ubda): re-mounted 01234567-9abc-ef01-3456-89abcdef0123 r/w. Quota mode: none.
ext4 filesystem being remounted at / supports timestamps until 2038-01-19 (0x7fffffff)
/ # sync
/ # md5sum httpd
dc611778e56e0ca9fe9a7e4bcfef5853  httpd
/ # ifconfig lo up
/ # ping -c 1 0
PING 0 (0.0.0.0): 56 data bytes
64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.488 ms
/ # uname -a
Linux (none) 6.6.0 #1 Wed Nov  1 14:58:40 EDT 2023 x86_64 GNU/Linux
/ # halt
The system is going down NOW!
Requesting system halt
reboot: System halted

 $

  • https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/linux-6.0.tar.xz MD5 (linux-6.0.tar.xz) = d681bd1d62d48049a4874646f6774d92
  • https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/patch-6.6.xz MD5 (patch-6.6.xz) = 3899e4dc6668387dbf33a31eeab17fd8
  • (Linux 6.6 is booting again natively on this Chromebook, but the latest i915 driver still hasn't restored access to change the brightness of its LCD panel backlight.)



    Copyright © 1996-2024 Douglas Rice Winslow III. All Rights Reserved. E-mail Address: <winslowdoug@gmail.com>