lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 15 Dec 2011 11:17:44 +0200
From:	Raz Ben Yehuda <rbenyehuda@...z.com>
To:	<linux-kernel@...r.kernel.org>
Subject: Subject:[PATCH 1:1] boot paramer "root=" gets a list of devices

From: Raz ben yehuda <rbenyehuda@...z.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@...z.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;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ