All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raz Ben Yehuda <rbenyehuda@manz.com>
To: <linux-kernel@vger.kernel.org>
Subject: Subject:[PATCH 1:1] boot paramer "root=" gets a list of devices
Date: Thu, 15 Dec 2011 11:17:44 +0200	[thread overview]
Message-ID: <1323940664.16032.6.camel@raz> (raw)

From: Raz ben yehuda <rbenyehuda@manz.com>

Patch is aimed to bypass the need for initramfs when it is not
known which disk has the root file system.

Example: The kernel boot parameter "root=/dev/sda1,/dev/sdc1,/dev/sdb4".
Check if /dev/sda1 exists ,if /dev/sda1 does not exist then try
/dev/sdc1 an so on upto the first a device that exists ( ROOT_DEV != 0 ), 
else use the last device as the mount device.

Signed-off-by: Raz Ben Yehuda <rbenyehuda@manz.com>

---

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 0f6e1d9..02ed235 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -162,9 +162,10 @@ done:
  *         of partition - device number of disk plus the partition number
  *	5) /dev/<disk_name>p<decimal> - same as the above, that form is
  *	   used when disk name of partitioned disk ends on a digit.
- *	6) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the
+ *	6) /dev/<disk name><decimal>,/dev/<disk name><decimal>,...
+ *	7) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the
  *	   unique id of a partition if the partition table provides it.
- *	7) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to
+ *	8) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to
  *	   a partition with a known unique id.
  *
  *	If name doesn't have fall into the categories above, we return (0,0).
@@ -469,6 +470,63 @@ void __init mount_root(void)
 #endif
 }
 
+void scan_root_dev_list(void)
+{
+	char *root_device_eol;
+	char *tmp_dev_name = saved_root_name;
+	char *comma;
+
+	comma = root_device_name;
+	root_device_eol = root_device_name + strlen(root_device_name);
+
+	for (; comma != root_device_eol ;) {
+		char dev_name[64];
+		/*
+		 * scan for active device from
+		 * root=/dev/sda1,/dev/sda2,...
+		*/
+		comma = strchr(tmp_dev_name, ',');
+		if (!comma) {
+			/*
+			 * if there is no list of devices
+			 * ( root=/dev/sdaX) or we are at the end
+			*/
+			root_device_name = tmp_dev_name;
+			ROOT_DEV = name_to_dev_t(root_device_name);
+			printk(KERN_INFO "trying device %s\n",
+				root_device_name);
+			break;
+		}
+		/*
+		 * ok, we failed with first device,
+		 * move to next one in the comma separated list
+		 */
+		memset(dev_name, 0, sizeof(dev_name));
+		strncpy(dev_name, tmp_dev_name,
+					(long)comma - (long)tmp_dev_name);
+		ROOT_DEV = name_to_dev_t(dev_name);
+		printk(KERN_INFO "trying device %s\n", dev_name);
+		if (ROOT_DEV == 0) {
+			tmp_dev_name = comma + 1;
+			if (tmp_dev_name < root_device_eol)
+				continue;
+			break;
+		}
+		/*
+		 * we're lucky, we have a device,
+		 * let set root_device_name to point at it
+		*/
+		strcpy(root_device_name, dev_name);
+		break;
+	}
+	if (ROOT_DEV == 0) {
+		printk(KERN_INFO "kernel is likely to panic aiee..\n");
+		return;
+	}
+	printk(KERN_INFO "Found %s appropriate for boot\n",
+		root_device_name);
+}
+
 /*
  * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
  */
@@ -500,10 +558,10 @@ void __init prepare_namespace(void)
 			mount_block_root(root_device_name, root_mountflags);
 			goto out;
 		}
-		ROOT_DEV = name_to_dev_t(root_device_name);
-		if (strncmp(root_device_name, "/dev/", 5) == 0)
-			root_device_name += 5;
+		scan_root_dev_list();
 	}
+	if (strncmp(root_device_name, "/dev/", 5) == 0)
+			root_device_name += 5;
 
 	if (initrd_load())
 		goto out;



             reply	other threads:[~2011-12-15  9:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-15  9:17 Raz Ben Yehuda [this message]
     [not found] <1323940396.16032.2.camel@raz>
     [not found] ` <4EEA0C05.4030907@zytor.com>
2011-12-15 15:19   ` Subject:[PATCH 1:1] boot paramer "root=" gets a list of devices Raz Ben Yehuda
2011-12-15 15:22     ` H. Peter Anvin
2011-12-15 18:11       ` Kay Sievers
2011-12-18  8:54         ` Raz Ben Yehuda
2012-01-04 17:48           ` Will Drewry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323940664.16032.6.camel@raz \
    --to=rbenyehuda@manz.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.