Here are some ideas for limited environments
Environments such as embedded or pre-boot, where watch, tail, cat, dd and other commands might not be available, might need different gymnastics.
This is what some lightweight Linux distributions do:
while dmesg -c >> /tmp/dmesg.log; do sleep 0.1; done & tail -f /tmp/dmesg.log
It backgrounds the while loop (with &) while tailing the generated output.
If you can't write to /tmp:
mount -t tmpfs - /tmp
# or
mount -t ramfs - /tmp
# or use /dev/shm instead of /tmp - which is available in newer environments
If you don't have tail, you can
cat /tmp/dmesg.log
# or
dd if=/tmp/dmesg.log
# or
dd if=/tmp/dmesg.log 2>/dev/null
Or you might be in a busybox environment that doesn't have dmesg linked, then just:
busybox dmesg -c
You might also need to
busybox sleep
instead of sleep
If you don't have sleep:
while dmesg -c; do echo >/dev/null; done
If you don't have "dmesg":
while sleep 0.1; do cat -v /proc/kmsg; done
This only works if nothing else is reading from here. You might also have a /dev/kmsg.
Bonus tip:
If you don't know what you have, and you don't have "ls", just:
busybox ls
# or simply:
echo *
kernel.log
does not contain the same output asdmesg
. For example, for a damaged drive, file read errors indmesg
specify exactly which file could not be read, whilekernel.log
unfortunately provides only the less-than-helpful notice:disk0s2: I/O error.
sudo dmesg >> "$TMPDIR/dmesg.log"; tail -f "$TMPDIR/dmesg.log"
on Mac.