Setting up Stali Linux as XEN/PVH guest

mkdir -p /root/guests/stali/lala/
cd /root/guests/stali/

git clone http://git.sta.li/rootfs-x86_64

dd if=/dev/zero of=stali.reiser4 bs=1GB count=0 seek=10
mkfs.reiser4 -fy stali.reiser4
mount stali.reiser4 lala/

cp -a rootfs-x86_64/* lala/
rm -rf rootfs-x86_64/

    mkdir lala/lib/modules/
    tar xzf /data/kernels/5.2.21.domureiser4.modules.tar.gz -C lala/lib/modules/

vi lala/etc/fstab

/dev/xvda1      /       reiser4 noatime,discard                 0 1
tmpfs           /tmp    tmpfs   nodev,nosuid,mode=1777          0 0
tmpfs           /dev/shm tmpfs  defaults                        0 0

mv -i lala/etc/rc.init lala/etc/rc.init.dist
rm -f lala/etc/rc.conf*
chmod -x lala/etc/rc.init.dist
vi lala/etc/rc.init

#!/bin/sh

echo rc.init PATH is $PATH

umask 022

/bin/mount -n -t proc -o nosuid,noexec,nodev proc /proc
/bin/mount -n -t sysfs -o nosuid,noexec,nodev sysfs /sys

# we have /dev on the disk not as tmpfs nor devtmpfs
/bin/umount /dev
/bin/mount -n -t devpts -o gid=5,mode=0620 devpts /dev/pts

/bin/mount -o remount,rw /
/bin/mount -a

echo -n Loading TMEM...
/bin/modprobe tmem && echo done || echo FAILED

/bin/hostname stali

/bin/ip addr add 127.0.0.1/8 dev lo broadcast + scope host
/bin/ip link set lo up

/bin/ip addr add 10.3.3.9/24 dev eth0
/bin/ip link set eth0 up
/bin/ip route add 10.3.3.1/24 dev eth0

test -f /etc/random-seed && /bin/cat /etc/random-seed >/dev/urandom
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2>/dev/null

ulimit -c unlimited

# usage: /bin/getty [tty] [term] [cmd] [args...]
/bin/respawn /bin/getty /dev/hvc0 xterm /bin/sh

chmod +x lala/etc/rc.init

echo 127.0.0.1 localhost stali > lala/etc/hosts

cat > lala/etc/resolv.conf <<EOF
search nethence.com
nameserver 62.210.16.6
nameserver 62.210.16.7
EOF

cp -i lala/etc/rc.exit lala/etc/rc.exit.dist
chmod -x lala/etc/rc.exit.dist
vi lala/etc/rc.exit

(remove the call to unused rc.conf)

re-wrap sinit altogether

echo /bin/kill -s USR1 1 > lala/bin/poweroff
echo /bin/kill -s INT 1 > lala/bin/reboot
chmod +x lala/bin/poweroff lala/bin/reboot

create device files

mkdir -p lala/{dev/pts,dev/shm,proc,tmp,sys,log,run}/

mknod -m 600 lala/dev/console c 5 1
mknod -m 600 lala/dev/hvc0 c 229 0

mknod -m 660 lala/dev/ptmx c 5 2
mknod -m 660 lala/dev/tty c 5 0
grep ^tty lala/etc/group
chown root:tty lala/dev/ptmx
chown root:tty lala/dev/tty

mknod -m 666 lala/dev/null c 1 3
mknod -m 666 lala/dev/zero c 1 5

mknod -m 444 lala/dev/random c 1 8
mknod -m 444 lala/dev/urandom c 1 9

ln -s /proc/self/fd lala/dev/fd
ln -s /proc/self/fd/0 lala/dev/stdin
ln -s /proc/self/fd/1 lala/dev/stdout
ln -s /proc/self/fd/2 lala/dev/stderr
ln -s /proc/kcore lala/dev/core

and for xen

mkdir -p lala/dev/xen/

mknod -m 660 lala/dev/xen/evtchn c 10 60
mknod -m 660 lala/dev/xen/gntalloc c 10 58
mknod -m 660 lala/dev/xen/gntdev c 10 59
mknod -m 660 lala/dev/xen/hypercall c 10 56
mknod -m 660 lala/dev/xen/privcmd c 10 57
mknod -m 660 lala/dev/xen/xenbus c 10 61

then finish-up

#chroot lala/ passwd
du -sh lala/
#65M goes 213M
umount lala/
vi stali

kernel = "/data/kernels/vmlinuz"
root = "/dev/xvda1 ro console=hvc0 mitigations=off"
name = "stali"
vcpus = 3
maxvcpus = 8
memory = 7168
disk = ['tap:tapdisk:aio:/root/guests/stali/stali.reiser4,xvda1,w']
vif = [ 'bridge=br0, vifname=stali.0' ]
type = "pvh"

#extra = "init=/bin/bash"

xl create stali -c

Acceptance

lsmod
free -m
curl -I http://146.112.62.105/
curl -I https://www.opendns.com/

TODO

make /var/ alive again and get rid of /log/ and /run/

note: /run/ is required while logging in

fopen /run/utmp: No such file or directory

Additional notes

otherwise within rc.init

/bin/mknod -m 600 /dev/console c 5 1
/bin/mknod -m 600 /dev/hvc0 c 229 0
/bin/mknod -m 666 /dev/null c 1 3
/bin/mknod -m 666 /dev/zero c 1 5
/bin/mknod -m 666 /dev/ptmx c 5 2
/bin/mknod -m 666 /dev/tty c 5 0
/bin/mknod -m 444 /dev/random c 1 8
/bin/mknod -m 444 /dev/urandom c 1 9
ln -s /proc/self/fd fd
ln -s /proc/self/fd/0 stdin
ln -s /proc/self/fd/1 stdout
ln -s /proc/self/fd/2 stderr
ln -s /proc/kcore core

it is worth noting that kernel’s dev mount options look like this

devtmpfs /dev devtmpfs rw,relatime,size=3563240k,nr_inodes=890810,mode=755 0 0

Resources

https://sta.li/

https://core.suckless.org/sinit/

http://www.linuxfromscratch.org/lfs/view/6.1/chapter06/devices.html

https://git.suckless.org/ubase/files.html

https://git.suckless.org/sbase/files.html

https://gitlab.com/garbeam/src/-/blob/master/bin/ubase/halt.8


HOME | GUIDES | BENCHMARKS | html