Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

RPI: Emergency configuration via FAT partition (/boot)



Hi,

something that seems to come up every now and then is the question of
configuration if no console is available, i.e., no HDMI screen and
(more importantly) no USB keyboard or serial cable.  The attached
patch makes the default /etc/rc.local run /boot/rc.netbsd (if
available) and installs a file /boot/rc.netbsd.sample that - if
renamed to /boot/rc.netbsd - adds a user, sets their and root's
password, and configures usmsc0 (on-board ethernet) to a static v4 IP.
The idea is for all this to run just as a last resort, so the script
is supposed to be run only once and not on every boot.  Therefore at
the end of this, rc.local then renames /boot/rc.netbsd to
/boot/rc.netbsd.disabled.

Right now, the patch as attached does all this *only* with rpi.img,
*not* with armv7.img.

Is this something that people might find useful?  Any other
comments/suggestions, e.g., should this perhaps also be done with
armv7.img (I don't think it needs to go to rpi_inst.img)?


thanks,
  Harold
--- src/distrib/utils/embedded/conf/rpi.conf	12 Dec 2017 21:00:28 -0000
+++ src/distrib/utils/embedded/conf/rpi.conf	22 Dec 2017 20:42:27 -0000
@@ -44,6 +44,48 @@
 EOF
 	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" \
 	    >> "$tmp/selected_sets"
+
+	cat >> ${mnt}/etc/rc.local << EOF
+
+# for emergency configuration via the FAT partition
+if [ -f /boot/rc.netbsd ]; then
+	/boot/rc.netbsd && mv /boot/rc.netbsd /boot/rc.netbsd.disabled
+fi
+EOF
+
+	cat >> ${mnt}/boot/rc.netbsd.sample << "EOF"
+#!/bin/sh
+
+# This script is executed as /boot/rc.netbsd from /etc/rc.local.  As such it
+# can be written to by mounting the (FAT) /boot partition on any machine that
+# supports FAT (msdosfs).  The idea for this is to be used to perform
+# "emergency" configuration if no machine is available to mount the NetBSD
+# partition and no console is available.
+#
+# The example below adds a user with a fixed password, sets the root password,
+# and configures a static IP on usmsc0 (the on-board ethernet).
+
+USERNAME=netbsd          # User to be added
+PASSWORD=changeme        # password for user
+ROOTPASS=changeme2       # new root password
+
+# Add user and set password
+/usr/sbin/useradd -m -s /bin/sh -G wheel ${USERNAME}
+/usr/sbin/usermod -p `/usr/bin/pwhash ${PASSWORD}` ${USERNAME}
+
+# Set root password
+/usr/sbin/usermod -p `/usr/bin/pwhash ${ROOTPASS}` root
+
+# Set on-board ethernet to static IP.
+# For DHCP append these two lines to /etc/rc.conf instead:
+#   dhcpcd=YES
+#   dhcpcd_flags="-qM usmsc0"
+/bin/echo "dhcpcd=NO" >> /etc/rc.conf
+/bin/echo "ifconfig_usmsc0=\"192.168.1.1\"" >> /etc/rc.conf
+
+exit 0
+EOF
+
 }
 
 populate() {


Home | Main Index | Thread Index | Old Index