# /etc/inittab
#
# Copyright
#
# Note: BusyBox init doesn't support runlevels.  The runlevels field is
# completely ignored by BusyBox init. If you want runlevels, use
# sysvinit.

# Format for each entry: <id>:<runlevels>:<action>:<process>
#
# id        == tty to run on, or empty for /dev/console
# runlevels == ignored
# action    == one of sysinit, respawn, askfirst, wait, and once
# process   == program to run


# Startup the system.

::sysinit:/bin/mount /proc  # Lightwhale requires the pseudo file systems for setup-persistence...
::sysinit:/bin/mount /sys   # ...and since the rootfs is already mounted in RAM at this point...
::sysinit:/bin/mount /run   # ...we have /etc/fstab present which is used for mount options...
::sysinit:/bin/mount /tmp   # ...so we are mounting them as intended.
::sysinit:/bin/mount /mnt   # 
::sysinit:/bin/mount /var/log 
::sysinit:/bin/mount -t cgroup2 none /sys/fs/cgroup

::sysinit:/bin/mkdir -p /dev/pts /dev/shm /run/lock /run/db  # Subdirs in pseudo file system required by init scripts.

#::sysinit:/lib/lightwhale/rescue-shell
#::sysinit:/lib/lightwhale/setup-persistence

# create a read-only mapping of the rootfs 
::sysinit:mkdir -p /mnt/root.squashfs
::sysinit:mount --bind / /mnt/root.squashfs
::sysinit:mount --make-rprivate /mnt/root.squashfs/

# create overlay
::sysinit:/usr/sbin/zpool import nimux-zfs
::sysinit:/bin/mount -t overlay overlay-etc -o lowerdir=/mnt/root.squashfs/etc/,upperdir=/mnt/overlays/root/etc/upper,workdir=/mnt/overlays/root/etc/work /etc
::sysinit:/bin/mount -t overlay overlay-home -o lowerdir=/mnt/root.squashfs/home/,upperdir=/mnt/overlays/root/home/upper,workdir=/mnt/overlays/root/home/work /home

null::sysinit:/bin/ln -sf /proc/self/fd /dev/fd
null::sysinit:/bin/ln -sf /proc/self/fd/0 /dev/stdin
null::sysinit:/bin/ln -sf /proc/self/fd/1 /dev/stdout
null::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr

::sysinit:/bin/mount -a
#::sysinit:/sbin/swapon -a
::sysinit:/bin/hostname -F /etc/hostname   # Because a custom hostname may have been mounted at this point.

# Now run all the lovely rc scripts.
::sysinit:/etc/init.d/rcS

# Put a getty on the serial port.
tty1::respawn:/sbin/getty -L tty1 0 vt100        # First console
tty2::respawn:/sbin/getty -L tty2 0 vt100        # Extra console, for good measure.
console::respawn:/sbin/getty -L console 0 vt100 # Serial console, for headless QEMU.

# Stuff to do before rebooting.
::shutdown:/etc/init.d/rcK
#::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
