HACK: Use a read-only rootfs (almost)

This is supposed to be supported by upstream systemd *and* buildroot by
now, so let's see what breaks. I expect that sysrepo & netopeer won't
like this because of repository paths and what not. It also won't be
possible to change the system's timezone, passwords, network
configuration etc, which is something that we will have to fix before
this works "for real".

Originally I wanted to go and use something like RAUC this week, but it
isn't really trivial. This hack at least works on the CL-ROADMv2. It's
ugly.

Change-Id: I52510509370c2605787a3c33e78884c936ec1717
diff --git a/board/czechlight/common/overlay/root/doit-CL-ROADM-v2.sh b/board/czechlight/common/overlay/root/doit-CL-ROADM-v2.sh
index 1c48f2d..9baa4a9 100755
--- a/board/czechlight/common/overlay/root/doit-CL-ROADM-v2.sh
+++ b/board/czechlight/common/overlay/root/doit-CL-ROADM-v2.sh
@@ -3,17 +3,31 @@
 set -eux -o pipefail
 shopt -s failglob
 
+mount / -o remount,rw
+mv /etc/sysrepo /etc/sysrepo.orig
+mkdir /etc/sysrepo
+chmod 000 /etc/sysrepo
+mke2fs -t ext4 -F -F -q /dev/sda2
+echo '/dev/sda2 /etc/sysrepo ext4 defaults 0 0' >> /etc/fstab
+mount -a
+mv /etc/sysrepo.orig/* /etc/sysrepo/
+rmdir /etc/sysrepo.orig
+
+# some of these need r/w rootfs due to SSH keys
 for DIR in /etc/yang-setup/*; do
 	${DIR}/install-yang.sh
 done
 
+mount / -o remount,ro
+
 sysrepoctl --install --search-dir /usr/share/cla-sysrepo/yang --yang /usr/share/cla-sysrepo/yang/czechlight-roadm-v2.yang
 sysrepocfg --datastore=startup --import=/usr/share/cla-sysrepo/yang/czechlight-roadm-v2.startup.xml czechlight-roadm-v2
 
-systemctl enable czechlight-roadm-v2
 systemctl start czechlight-roadm-v2
-
-systemctl enable netopeer2-server
 systemctl start netopeer2-server
 
+mount / -o remount,rw
+systemctl enable czechlight-roadm-v2
+systemctl enable netopeer2-server
 echo 'cla-sysrepod --properties-log-level=5 --sr-bridge-log-level=5 --sysrepo-log-level=3 --driver=CL-ROADMv2 --port=/dev/ttyUSB0' >> ~/.ash_history
+mount / -o remount,ro
diff --git a/board/czechlight/epia_geode/genimage.cfg b/board/czechlight/epia_geode/genimage.cfg
index a84794f..d346949 100644
--- a/board/czechlight/epia_geode/genimage.cfg
+++ b/board/czechlight/epia_geode/genimage.cfg
@@ -17,4 +17,8 @@
 		partition-type = 0x83
 		image = "rootfs.ext4"
 	}
+	partition sysrepo {
+		partition-type = 0x83
+		size = 32M
+	}
 }
diff --git a/configs/czechlight_beaglebone_defconfig b/configs/czechlight_beaglebone_defconfig
index c028035..7d7137f 100644
--- a/configs/czechlight_beaglebone_defconfig
+++ b/configs/czechlight_beaglebone_defconfig
@@ -10,6 +10,7 @@
 BR2_TARGET_GENERIC_PASSWD_SHA256=y
 BR2_INIT_SYSTEMD=y
 BR2_TARGET_GENERIC_GETTY_PORT="ttyO0"
+# BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
 BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/common/overlay/ $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/beaglebone/overlay/"
 BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/common/dhcp-network.sh $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/common/systemd-watchdog.sh"
 BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/beaglebone/post-image.sh"
diff --git a/configs/czechlight_epia_geode_defconfig b/configs/czechlight_epia_geode_defconfig
index f322e5b..8426ddb 100644
--- a/configs/czechlight_epia_geode_defconfig
+++ b/configs/czechlight_epia_geode_defconfig
@@ -14,6 +14,7 @@
 BR2_TARGET_GENERIC_PASSWD_SHA512=y
 BR2_INIT_SYSTEMD=y
 BR2_TARGET_GENERIC_GETTY_PORT="tty0"
+# BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
 BR2_ENABLE_LOCALE_WHITELIST="C en_US en_US.utf8"
 BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/common/overlay/ $(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/epia_geode/overlay/"
 BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL_CZECHLIGHT_PATH)/board/czechlight/common/dhcp-network.sh"