Note: This note was originally in the Raspberry Pi, overlayfs read-write root, read-only NFS base post.
In trying to get the various options out there working I found a number of debugging strategies helpful, they're mostly simple -
set -v - put this after the
#!/bin/sh (or equivalent) line and afterwards every command executed will also be echoed which is helpful for seeing context around errors.
echo - good for printing status or variable contents, along with things like
cat that can provide the contents of a file at a given time.
Third, drop to bash. Calling
/bin/bash when you want to do a bit of real-time debugging can be useful if the Pi is connected to a Keyboard and Display - however it is a little quirky, like it doesn't print input as typed!
Finally, the serial console (details below) allowed me to easily see all the boot output from the start, as it moves very fast, as well as copying bits of test to compare.