#!/bin/sh
# Log the state after mountroot and before run-init, to /boot/dekroot.log.
# A missing line here means mountroot/checkfs failed; a present one means the
# failure is in run-init or later.

B=/dev/sda2
mkdir -p /tmp/dlog2
if mount -o rw "$B" /tmp/dlog2 2>/dev/null; then
    {
        echo "--- local-bottom ---"
        if mountpoint -q /root 2>/dev/null; then
            echo "/root is a mountpoint"
            echo "top entries: $(ls /root 2>/dev/null | tr '\n' ' ')"
            echo "init: $(ls -l /root/sbin/init 2>&1)"
        else
            echo "/root NOT a mountpoint"
        fi
        echo "fstab root line: $(grep -m1 ' / ' /etc/fstab 2>/dev/null)"
    } >> /tmp/dlog2/dekroot.log
    umount /tmp/dlog2 2>/dev/null
fi
echo "deklog: local-bottom reached" > /dev/kmsg
