Finally some progress. Hooking up the right pin for two-way serial on my serial adapter (FTDI or whatever) and trying a minimal /init:
#!/bin/sh
echo "======================= Running init from rootfs_overlay"
mount -t devtmpfs none /dev
mount -t proc proc /proc
mount -t sysfs sysfs /sys
echo "Waiting for /dev/mmcblk0p2..."
until [ -b "/dev/mmcblk0p2" ]; do
sleep 5
done
echo "Starting shell?"
exec sh
Then I could actually see what was happening as I was getting really weird errors and the output was being swallowed.
mkdir /media/mmcblk0p2
mount /dev/mmcblk0p2 /media/mmcblk0p2
exec switch_root /media/mmcblk0p2/ /sbin/init
This gave me a proper error!
# exec switch_root /media/mmcblk0p2 /sbin/init
erlinit: Cannot remount /dev
erlinit: Cannot create /dev/pts
erlinit: Cannot create /dev/shm
erlinit: Could not create symlink '/dev/rootdisk0'->'/dev/mmcblk0': Read-only file system
erlinit: Could not create symlink '/dev/rootdisk0p3'->'/dev/mmcblk0p3': Read-only file system
erlinit: Could not create symlink '/dev/rootdisk0p2'->'/dev/mmcblk0p2': Read-only file system
erlinit: Could not create symlink '/dev/rootdisk0p1'->'/dev/mmcblk0p1': Read-only file system
erlinit: error setting controlling terminal: /dev/tty1
erlinit: Cannot mount /dev/mmcblk0p1 at /boot: No such file or directory
erlinit: Cannot mount /dev/mmcblk0p3 at /root: No such file or directory
erlinit: Couldn't open /dev/null
erlinit: `/usr/bin/boardid` failed. Using default ID: '00000000'
erlinit: Unable to create seed directory
nbtty: Could not find a pty.
[nbtty: terminating]
erlinit: Erlang VM exited
erlinit: Sending SIGTERM to all processes
erlinit: Sending SIGKILL to all processes
erlinit: Unable to create seed directory
[ 5902.674349] reboot: Restarting system
So I need to understand what’s going on with /dev because we do need devices.
Fundamentally I think everything else fails off of that.
After a lot of fiddling to avoid needing to recompile for 45 minutes to modify the executable bit on init_sh I have switched root and have a shell inside my rootfs.img:
# exec switch_root /media/root/ /sbin/init_sh
======================= Running second /init
Starting second shell
# ls
var tmp srv run proc mnt lib64 etc data bin
usr sys sbin root opt media lib dev boot
# ls /dev
shm pts log
# mount -t devtmpfs -o rw none /dev
mount: permission denied (are you root?)
# whoami
sh: whoami: not found
# id -u
1000
# exec switch_root /media/root/ /sbin/init_sh
======================= Running second /init
Starting second shell
# ls
var tmp srv run proc mnt lib64 etc data bin
usr sys sbin root opt media lib dev boot
# mount -t devtmpfs -o rw none /dev
# mount -t proc proc /proc
# mount -t sysfs sysfs /sys
# exec /sbin/init
[ 40.991680] erlinit: Cannot mount /sys
[ 41.009972] F2FS-fs (mmcblk0p3): Magic Mismatch, valid(0xf2f52010) - read(0xffffffff)
[ 41.018038] F2FS-fs (mmcblk0p3): Can't find valid F2FS filesystem in 1th superblock
[ 41.026147] F2FS-fs (mmcblk0p3): Magic Mismatch, valid(0xf2f52010) - read(0xffffffff)
[ 41.034110] F2FS-fs (mmcblk0p3): Can't find valid F2FS filesystem in 2th superblock
[ 41.042127] erlinit: Cannot mount /dev/mmcblk0p3 at /root: Invalid argument
erlinit: The shell will be launched on tty 'tty1'.
erlinit: If you would like the shell to be on this tty,
erlinit: configure erlinit with '-c ttyS0'.
erlinit: The hostname is 'nerves-72cf'.
Now to see if I can just script it without going through an interactive shell each time. Which seems to be a problem?