diff mbox

[OpenWrt-Devel,1/2] mount_root: implement overlay= boot option

Message ID 1461865160-26373-1-git-send-email-josua.mayer97@gmail.com
State Changes Requested
Delegated to: John Crispin
Headers show

Commit Message

Josua Mayer April 28, 2016, 5:39 p.m. UTC
From: Josua Mayer <privacy@not.given>

This change adds code to handle a new option on cmdline: overlay=
This is used to find the rootfs_data partition / disk when it has a
non-standard name or location.

It takes either the device node name, or the full path to the device node:
i.e. /dev/mmcblk0p3 or mmcblk0p3

This option has precedence over the default name "rootfs_data", and extroot.

Signed-off-by: Josua Mayer <josua.mayer97@gmail.com>.
---
 mount_root.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff mbox

Patch

diff --git a/mount_root.c b/mount_root.c
index 47a3409..9d2c0de 100644
--- a/mount_root.c
+++ b/mount_root.c
@@ -33,6 +33,35 @@  start(int argc, char *argv[1])
 	if (!getenv("PREINIT"))
 		return -1;
 
+	/*
+	 * Check cmdline for a hint about overlay device
+	 */
+	if(!data) {
+		FILE *fp;
+		char buffer[100] = {0};
+
+		fp = fopen("/proc/cmdline", "r");
+		while(!feof(fp)) {
+			if(fscanf(fp, "overlay=%s", buffer))
+				break;
+
+			fseek(fp, 1, SEEK_CUR);
+		}
+		fclose(fp);
+
+		// overlay= argument was found
+		if(buffer[0]) {
+			// strip /dev/ prefix if any
+			int offset = 0;
+			if(strstr(buffer, "/dev/"))
+				offset = 5;
+
+			// try to find the volume
+			ULOG_NOTE("Looking for overlay device given on commandline\n");
+			data = volume_find(buffer + offset);
+		}
+	}
+
 	if (!data) {
 		root = volume_find("rootfs");
 		volume_init(root);