Index: .fossil-settings/ignore-glob
==================================================================
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -8,10 +8,11 @@
 pki.tcl
 CA
 build/qemu/root/lib/modules
 build/qemu/appfs.img
 build/qemu/boot/vmlinuz
+build/qemu/boot/initrd
 build/qemu/init
 build/qemu/root/bin/appfs-cache
 build/qemu/root/bin/appfs-mkfs
 build/qemu/root/bin/appfsd
 build/qemu/root/bin/init

Index: build/qemu/assemble
==================================================================
--- build/qemu/assemble
+++ build/qemu/assemble
@@ -3,60 +3,71 @@
 set -e
 
 # Not included:
 #  1. Downloading huge.s from Slackware64 kernels (into boot/)
 #  2. Downloading kernel modules package from Slackware64 (into root/)
-#  3. Downloading a static Tclkit with TUAPI
-#  4. Downloading a static AppFS
+#  3. Running "depmod" within the chroot root/
+#  4. Downloading a static Tclkit with TUAPI
+#  5. Downloading a static AppFS
+
+image_file="$(pwd)/appfs.img"
+old_loop_dev="$(losetup --noheadings --output name --associated "${image_file}")" || old_loop_dev=''
+extlinux_mbr_bin='/usr/lib/EXTLINUX/mbr.bin'
 
 make init LDFLAGS=-static
 cp init root/bin
 
-rm -f appfs.img
-truncate --size 1024M appfs.img
-sfdisk --no-tell-kernel --no-reread ./appfs.img <<<'label: dos
-size=16M type=83 bootable
-size=239M type=83
-type=83'
-
-sudo umount x-boot || :
-sudo losetup -d /dev/loop3 || :
-sudo losetup --partscan /dev/loop3 $(pwd)/appfs.img
-sudo chown "$(id -u):$(id -g)" /dev/loop3 /dev/loop3p1 /dev/loop3p2
-
-sudo mke2fs \
+rm -f boot/initrd
+(
+	cd root || exit 1
+	find . ! -name '.' -print0 | sort --zero-terminated --dictionary-order | cpio -o -0 --owner 0:0 --dot -H newc
+) | gzip -1c > boot/initrd
+
+rm -f "${image_file}"
+truncate --size 1024M "${image_file}"
+sfdisk --no-tell-kernel --no-reread "${image_file}" <<<'label: dos
+size=128M type=83 bootable
+type=83'
+
+if [ -d 'x-boot' ]; then
+	sudo umount x-boot || :
+fi
+if [ -n "${old_loop_dev}" ]; then
+	sudo losetup -d "${old_loop_dev}" || :
+fi
+sudo losetup --partscan --find "${image_file}"
+loop_dev="$(losetup --noheadings --output name --associated "${image_file}")"
+if [ -z "${loop_dev}" ]; then
+	echo "No loop device found" >&2
+	exit 1
+fi
+sudo chown "$(id -u):$(id -g)" "${loop_dev}" "${loop_dev}p1" "${loop_dev}p2"
+
+mke2fs \
   -L 'BOOT' \
   -N 0 \
   -O ^64bit \
   -d boot \
   -m 5 \
   -r 1 \
   -t ext4 \
-  /dev/loop3p1
-
-sudo mke2fs \
-  -L 'ROOT' \
-  -N 0 \
-  -O ^64bit \
-  -d root \
-  -m 5 \
-  -r 1 \
-  -t ext4 \
-  /dev/loop3p2
-
-sudo mke2fs \
+  "${loop_dev}p1"
+
+mke2fs \
   -L 'DATA' \
   -N 0 \
   -O ^64bit \
   -m 5 \
   -r 1 \
   -t ext4 \
-  /dev/loop3p3
+  "${loop_dev}p2"
 
 mkdir x-boot || :
-sudo mount /dev/loop3p1 x-boot
+sudo mount "${loop_dev}p1" x-boot
 sudo extlinux --install $(pwd)/x-boot
 sudo umount x-boot
-dd if=/usr/lib/EXTLINUX/mbr.bin of=appfs.img conv=notrunc
+dd if="${extlinux_mbr_bin}" of="${image_file}" conv=notrunc
 rmdir x-boot
 
-losetup -d /dev/loop3
+losetup -d "${loop_dev}"
+
+exit 0

Index: build/qemu/boot/extlinux.conf
==================================================================
--- build/qemu/boot/extlinux.conf
+++ build/qemu/boot/extlinux.conf
@@ -1,6 +1,7 @@
 DEFAULT appfs
 SERIAL 0 9600 0x003
 
 LABEL appfs
 	KERNEL vmlinuz
-	APPEND root=/dev/vda2 console=tty0 console=ttyS0 consoleblank=0 loglevel=8
+	INITRD initrd
+	APPEND rdinit=/bin/init console=tty0 console=ttyS0 consoleblank=0 loglevel=8

Index: build/qemu/init.c
==================================================================
--- build/qemu/init.c
+++ build/qemu/init.c
@@ -43,14 +43,56 @@
 
 	exit(EXIT_FAILURE);
 }
 
 int main(int argc, char **argv) {
+	int mount_ret;
+
+	/*
+	 * Load kernel modules (drivers)
+	 */
+	mkdir("/sys", 0755);
+	mount("sysfs", "/sys", "sysfs", 0, NULL);
+
+	run("/bin/init-modules", "init-modules", NULL);
+
+	umount("/sys");
+	rmdir("/sys");
+
 	/*
-	 * Remount root filesystem read-write
+	 * Mount root filesystem
 	 */
-	mount("/dev/vda2", "/", "ext4", MS_REMOUNT, NULL);
+	mkdir("/dev", 0755);
+	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);
+
+	mkdir("/new-root", 0755);
+	mount_ret = mount("/dev/vda2", "/new-root", "ext4", 0, NULL);
+	if (mount_ret != 0) {
+		mount_ret = mount("/dev/sda2", "/new-root", "ext4", 0, NULL);
+	}
+	if (mount_ret != 0) {
+		mount_ret = mount("/dev/hda2", "/new-root", "ext4", 0, NULL);
+	}
+	umount("/dev");
+	rmdir("/dev");
+
+	if (mount_ret == 0) {
+		mkdir("/new-root/initramfs", 0755);
+		mkdir("/new-root/bin", 0755);
+		mkdir("/new-root/lib", 0755);
+		symlink("../initramfs/bin/appfsd", "/new-root/bin/appfsd");
+		symlink("../initramfs/bin/init", "/new-root/bin/init");
+		symlink("../initramfs/bin/init-modules", "/new-root/bin/init-modules");
+		symlink("../initramfs/bin/init-networking", "/new-root/bin/init-networking");
+		symlink("../initramfs/bin/appfs-cache", "/new-root/bin/appfs-cache");
+		symlink("../initramfs/bin/tclkit", "/new-root/bin/tclkit");
+		symlink("../initramfs/lib/modules", "/new-root/lib/modules");
+		chdir("/new-root");
+		mount("/", "/new-root/initramfs", "bind", MS_BIND, NULL);
+		chroot("/new-root");
+		chdir("/");
+	}
 
 	/*
 	 * Mount needed filesystems
 	 */
 	mkdir("/dev", 0755);
@@ -67,11 +109,10 @@
 
 	/*
 	 * Setup networking
 	 */
 	run("/bin/init-networking", "init-networking", NULL);
-	run("/bin/init-fuse", "init-fuse", NULL);
 
 	mkdir("/etc", 0755);
 	mkdir("/bin", 0755);
 	mkdir("/lib", 0755);
 	mkdir("/opt", 0755);
@@ -78,11 +119,10 @@
 	mkdir("/opt/appfs", 0755);
 
 	mkdir("/var", 0755);
 	mkdir("/var/cache", 0755);
 	mkdir("/var/cache/appfs", 0755);
-	mount("/dev/vda3", "/var/cache/appfs", "ext4", 0, NULL);
 
 	run("/bin/appfsd", "appfsd", "/var/cache/appfs", "/opt/appfs", NULL);
 
 	symlink(".", "/usr");
 	symlink("lib", "/lib64");
@@ -100,19 +140,9 @@
 	run("/bin/appfs-cache", "appfs-cache", "install", "core.appfs.rkeene.org", "procps-ng", NULL);
 	setenv("PATH", "/bin", 1);
 
 	run("/bin/sh", "sh", NULL);
 
-	/*
-	 * Remount root filesystem read-only
-	 */
-	umount("/dev");
-	umount("/tmp");
-	umount("/proc");
-	umount("/sys");
-	umount("/opt/appfs");
-	umount("/var/cache/appfs");
-	mount("/dev/vda2", "/", "ext4", MS_REMOUNT | MS_RDONLY, NULL);
 	sync();
 
 	return(0);
 }

DELETED build/qemu/root/bin/init-fuse
Index: build/qemu/root/bin/init-fuse
==================================================================
--- build/qemu/root/bin/init-fuse
+++ /dev/null
@@ -1,5 +0,0 @@
-#! /bin/tclkit
-
-package require tuapi
-
-::tuapi::modprobe fuse

ADDED   build/qemu/root/bin/init-modules
Index: build/qemu/root/bin/init-modules
==================================================================
--- /dev/null
+++ build/qemu/root/bin/init-modules
@@ -0,0 +1,7 @@
+#! /bin/tclkit
+
+package require tuapi
+
+::tuapi::scan_and_load_kernel_modules
+
+::tuapi::modprobe fuse

Index: build/qemu/root/bin/init-networking
==================================================================
--- build/qemu/root/bin/init-networking
+++ build/qemu/root/bin/init-networking
@@ -1,11 +1,9 @@
 #! /bin/tclkit
 
 package require tuapi
 
-::tuapi::scan_and_load_kernel_modules
-
 ::tuapi::ifconfig eth0 address 10.0.2.15 netmask 255.255.255.0 flags {BROADCAST MULTICAST UP}
 ::tuapi::syscall::route add 0.0.0.0 0.0.0.0 gateway 10.0.2.2 dev eth0
 
 file mkdir /etc   
 set fd [open /etc/resolv.conf w]

Index: build/qemu/run
==================================================================
--- build/qemu/run
+++ build/qemu/run
@@ -3,6 +3,6 @@
 sudo chown $(id -u) /dev/kvm
 qemu-system-x86_64  \
 	-display none -vga none -serial stdio \
 	-m 2048 -enable-kvm -cpu host -smp 2 \
 	-net nic -net user \
-	-drive file=appfs.img,if=virtio,cache=unsafe
+	-drive file=appfs.img,if=virtio,format=raw