ADDED build/qemu/assemble Index: build/qemu/assemble ================================================================== --- build/qemu/assemble +++ build/qemu/assemble @@ -0,0 +1,52 @@ +#! /usr/bin/env bash + +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 + +make init LDFLAGS=-static +cp init root/bin + +rm -f appfs.img +truncate --size 512M appfs.img +sfdisk --no-tell-kernel --no-reread ./appfs.img <<<'label: dos +size=16M type=83 bootable +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 \ + -L 'BOOT' \ + -N 0 \ + -O ^64bit \ + -d boot \ + -m 5 \ + -r 1 \ + -t ext2 \ + /dev/loop3p1 + +sudo mke2fs \ + -L 'ROOT' \ + -N 0 \ + -O ^64bit \ + -d root \ + -m 5 \ + -r 1 \ + -t ext2 \ + /dev/loop3p2 + +mkdir x-boot || : +sudo mount /dev/loop3p1 x-boot +sudo extlinux --install $(pwd)/x-boot +sudo umount x-boot +dd if=/usr/lib/EXTLINUX/mbr.bin of=appfs.img conv=notrunc +rmdir x-boot + +losetup -d /dev/loop3 ADDED build/qemu/boot/extlinux.conf Index: build/qemu/boot/extlinux.conf ================================================================== --- build/qemu/boot/extlinux.conf +++ build/qemu/boot/extlinux.conf @@ -0,0 +1,6 @@ +DEFAULT appfs +SERIAL 0 9600 0x003 + +LABEL appfs + KERNEL vmlinuz + APPEND root=/dev/vda2 console=tty0 console=ttyS0 consoleblank=0 loglevel=8 ADDED build/qemu/init.c Index: build/qemu/init.c ================================================================== --- build/qemu/init.c +++ build/qemu/init.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int run(const char *path, ...) { + va_list ap; + char **argv; + int argvMax, argvIdx; + pid_t pid; + int pidstat; + + pid = fork(); + if (pid == ((pid_t) -1)) { + return(-1); + } + + if (pid != 0) { + waitpid(pid, &pidstat, 0); + + return(pidstat); + } + + argvMax = 32; + argv = malloc(sizeof(*argv) * argvMax); + + va_start(ap, path); + + for (argvIdx = 0; argvIdx < argvMax; argvIdx++) { + argv[argvIdx] = va_arg(ap, char *); + if (argv[argvIdx] == NULL) { + break; + } + } + + va_end(ap); + + execv(path, argv); + + exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) { + /* + * Remount root filesystem read-write + */ + mount("/dev/vda2", "/", "ext2", MS_REMOUNT, NULL); + + /* + * Mount needed filesystems + */ + mkdir("/dev", 0755); + mount("devtmpfs", "/dev", "devtmpfs", 0, NULL); + + mkdir("/tmp", 0755); + mount("tmpfs", "/tmp", "tmpfs", 0, NULL); + + mkdir("/proc", 0755); + mount("proc", "/proc", "proc", 0, NULL); + + mkdir("/sys", 0755); + mount("sysfs", "/sys", "sysfs", 0, NULL); + + /* + * Setup networking + */ + run("/bin/init-networking", "init-networking", NULL); + run("/bin/init-fuse", "init-fuse", NULL); + + mkdir("/bin", 0755); + mkdir("/lib", 0755); + mkdir("/opt", 0755); + mkdir("/opt/appfs", 0755); + mkdir("/var", 0755); + mkdir("/var/cache", 0755); + mkdir("/var/cache/appfs", 0755); + run("/bin/appfsd", "appfsd", "/var/cache/appfs", "/opt/appfs", NULL); + + symlink(".", "/usr"); + symlink("lib", "/lib64"); + + symlink("/opt/appfs/core.appfs.rkeene.org/bash/platform/latest/bin/bash", "/bin/bash"); + symlink("/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin/env", "/bin/env"); + + symlink("/bin/bash", "/bin/sh"); + + setenv("PATH", "/bin:/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin", 1); + run("/bin/appfs-cache", "appfs-cache", "install", "-lib", "core.appfs.rkeene.org", "glibc", NULL); + run("/bin/appfs-cache", "appfs-cache", "install", "core.appfs.rkeene.org", "coreutils", NULL); + setenv("PATH", "/bin", 1); + + run("/bin/sh", "sh", NULL); + + return(0); +} ADDED build/qemu/root/bin/init-fuse Index: build/qemu/root/bin/init-fuse ================================================================== --- build/qemu/root/bin/init-fuse +++ build/qemu/root/bin/init-fuse @@ -0,0 +1,5 @@ +#! /bin/tclkit + +package require tuapi + +::tuapi::modprobe fuse ADDED build/qemu/root/bin/init-networking Index: build/qemu/root/bin/init-networking ================================================================== --- build/qemu/root/bin/init-networking +++ build/qemu/root/bin/init-networking @@ -0,0 +1,13 @@ +#! /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] +puts $fd "nameserver 10.0.2.3" +close $fd ADDED build/qemu/run Index: build/qemu/run ================================================================== --- build/qemu/run +++ build/qemu/run @@ -0,0 +1,8 @@ +#! /usr/bin/env bash + +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