--- old/usr/src/cmd/boot/bootadm/bootadm.c	2012-07-27 03:18:16.522340104 +0400
+++ new/usr/src/cmd/boot/bootadm/bootadm.c	2012-07-27 03:18:14.944809997 +0400
@@ -118,8 +118,8 @@
 
 #define	GRUB_DIR		"/boot/grub"
 #define	GRUB_STAGE2		GRUB_DIR "/stage2"
-#define	GRUB_MENU		"/boot/grub/menu.lst"
-#define	MENU_TMP		"/boot/grub/menu.lst.tmp"
+#define	GRUB_MENU		"/boot/illumos.cfg"
+#define	MENU_TMP		"/boot/illumos.cfg.tmp"
 #define	GRUB_BACKUP_MENU	"/etc/lu/GRUB_backup_menu"
 #define	RAMDISK_SPECIAL		"/ramdisk"
 #define	STUBBOOT		"/stubboot"
@@ -178,20 +178,21 @@
  * menu_cmd_t and menu_cmds must be kept in sync
  */
 char *menu_cmds[] = {
-	"default",	/* DEFAULT_CMD */
+	"default_entry",/* DEFAULT_CMD */
 	"timeout",	/* TIMEOUT_CMD */
-	"title",	/* TITLE_CMD */
-	"root",		/* ROOT_CMD */
-	"kernel",	/* KERNEL_CMD */
-	"kernel$",	/* KERNEL_DOLLAR_CMD */
-	"module",	/* MODULE_CMD */
-	"module$",	/* MODULE_DOLLAR_CMD */
-	" ",		/* SEP_CMD */
+	"entry_name",	/* TITLE_CMD */
+	"pool_uuid",	/* ROOT_CMD */
+	"kernel_path$",	/* KERNEL_CMD */
+	"kernel_path",	/* KERNEL_DOLLAR_CMD */
+	"module$",	/* MODULE_CMD */
+	"module",	/* MODULE_DOLLAR_CMD */
+	"=",		/* SEP_CMD */
 	"#",		/* COMMENT_CMD */
 	"chainloader",	/* CHAINLOADER_CMD */
 	"args",		/* ARGS_CMD */
-	"findroot",	/* FINDROOT_CMD */
-	"bootfs",	/* BOOTFS_CMD */
+	"pool_label",	/* FINDROOT_CMD */
+	"dataset",	/* BOOTFS_CMD */
+	"kernel_options",/* KERNEL_OPTIONS_CMD */
 	NULL
 };
 
@@ -4690,6 +4691,7 @@
 	menu_cmd_t	k_cmd;
 	menu_cmd_t	m_cmd;
 	const char	*fcn = "add_boot_entry()";
+	char * options;
 
 	assert(mp);
 
@@ -4756,10 +4758,20 @@
 		line_parser(mp, linebuf, &lineNum, &entryNum);
 	}
 
+	options = strpbrk(kernel, " \t");
+	if (options)
+		*options++ = 0;
+
 	(void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
 	    menu_cmds[k_cmd], menu_cmds[SEP_CMD], kernel);
 	line_parser(mp, linebuf, &lineNum, &entryNum);
 
+	if (options) {
+		(void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
+		    menu_cmds[KERNEL_OPTIONS_CMD], menu_cmds[SEP_CMD], options);
+		line_parser(mp, linebuf, &lineNum, &entryNum);
+	}
+
 	if (mod_kernel != NULL) {
 		(void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
 		    menu_cmds[m_cmd], menu_cmds[SEP_CMD], mod_kernel);
@@ -7112,18 +7124,19 @@
 	slice = strrchr(osdev, 's');
 
 	grubsign = s_calloc(1, MAXNAMELEN + 10);
-	if (slice) {
+/*	if (slice) {
 		(void) snprintf(grubsign, MAXNAMELEN + 10, "(%s,%d,%c)",
 		    sign, fdiskpart, slice[1] + 'a' - '0');
 	} else
 		(void) snprintf(grubsign, MAXNAMELEN + 10, "(%s,%d)",
-		    sign, fdiskpart);
+		    sign, fdiskpart);*/
+	grubsign = strdup(sign);
 
 	free(sign);
 
 	BAM_DPRINTF((D_GET_GRUBSIGN_SUCCESS, fcn, grubsign));
 
-	return (grubsign);
+	return (strchr(grubsign,'_') + 1);
 }
 
 static char *
@@ -7812,7 +7825,7 @@
 				continue;
 			}
 			/* findroot command found, try match  */
-			if (strcmp(lp->arg, findroot) != 0) {
+			if (strncmp(lp->arg, strchr(findroot, '_') + 1, strlen(lp->arg)) != 0) {
 				BAM_DPRINTF((D_NOMATCH_FINDROOT,
 				    fcn, findroot, lp->arg));
 				continue;
@@ -7870,6 +7883,7 @@
 		 * For xpv entries, there are two module lines, so we
 		 * do the check twice.
 		 */
+		lp = lp->next;	/* advance to options line */
 		lp = lp->next;	/* advance to module line */
 		if (check_cmd(lp->cmd, MODULE_CMD, lp->arg, module) ||
 		    (((lp = lp->next) != NULL) &&
@@ -7911,6 +7925,7 @@
 	line_t		*tlp;
 	char		linebuf[BAM_MAXLINE];
 	const char	*fcn = "update_boot_entry()";
+	char 		*label;
 
 	/* note: don't match on title, it's updated on upgrade */
 	ent = find_boot_entry(mp, NULL, kernel, findroot, root, module,
@@ -7967,10 +7982,13 @@
 
 	lp->cmd = s_strdup(menu_cmds[FINDROOT_CMD]);
 	lp->sep = s_strdup(menu_cmds[SEP_CMD]);
-	lp->arg = s_strdup(findroot);
+	label = s_strdup(strchr(findroot, '_') + 1);
+	*(strchr(label,',')) = 0;
+	lp->arg = s_strdup(label);
 	(void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
-	    menu_cmds[FINDROOT_CMD], menu_cmds[SEP_CMD], findroot);
+	    menu_cmds[FINDROOT_CMD], menu_cmds[SEP_CMD], label);
 	lp->line = s_strdup(linebuf);
+	free(label);
 	BAM_DPRINTF((D_ADDING_FINDROOT_LINE, fcn, findroot));
 
 	/* kernel line */
@@ -7978,16 +7996,13 @@
 
 	if (ent->flags & BAM_ENTRY_UPGFSKERNEL) {
 		char		*params = NULL;
+		char		*opts = NULL;
 
-		params = strstr(lp->line, "-s");
-		if (params != NULL)
-			(void) snprintf(linebuf, sizeof (linebuf), "%s%s%s%s",
-			    menu_cmds[KERNEL_DOLLAR_CMD], menu_cmds[SEP_CMD],
-			    kernel, params+2);
-		else
-			(void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
-			    menu_cmds[KERNEL_DOLLAR_CMD], menu_cmds[SEP_CMD],
-			    kernel);
+		opts = strpbrk(kernel, " \t");
+		*opts++ = '\0';
+		(void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
+		    menu_cmds[KERNEL_DOLLAR_CMD], menu_cmds[SEP_CMD],
+		    kernel);
 
 		if (lp->cmd != NULL)
 			free(lp->cmd);
@@ -7999,12 +8014,28 @@
 		lp->line = s_strdup(linebuf);
 		ent->flags &= ~BAM_ENTRY_UPGFSKERNEL;
 		BAM_DPRINTF((D_ADDING_KERNEL_DOLLAR, fcn, lp->prev->cmd));
+
+		lp = lp->next;
+		params = strstr(lp->arg, "-s");
+		free(lp->arg);
+		free(lp->line);
+		if (params)
+			(void) snprintf(linebuf, sizeof(linebuf), "%s%s%s -s",
+				lp->cmd, menu_cmds[SEP_CMD],opts);
+		else
+			(void) snprintf(linebuf, sizeof(linebuf), "%s%s%s",
+				lp->cmd, menu_cmds[SEP_CMD],opts);
+		lp->line = s_strdup(linebuf);
+		lp->arg = s_strdup(strchr(linebuf, '=') + 1);
 	}
 
 	if (change_kernel) {
+		char		*opts = NULL;
 		/*
 		 * We're upgrading from multiboot to directboot.
 		 */
+		opts = strpbrk(kernel, " \t");
+		*opts++ = '\0';
 		if (lp->cmd != NULL &&
 		    strcmp(lp->cmd, menu_cmds[KERNEL_CMD]) == 0) {
 			(void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
@@ -8018,6 +8049,12 @@
 			lp->line = s_strdup(linebuf);
 			lp = lp->next;
 			BAM_DPRINTF((D_ADDING_KERNEL_DOLLAR, fcn, kernel));
+			(void) snprintf(linebuf, sizeof(linebuf), "%s%s%s",
+				lp->cmd, menu_cmds[SEP_CMD],opts);
+			free(lp->arg);
+			free(lp->line);
+			lp->line = s_strdup(linebuf);
+			lp->arg = s_strdup(strchr(linebuf, '=') + 1);
 		}
 		if (lp->cmd != NULL &&
 		    strcmp(lp->cmd, menu_cmds[MODULE_CMD]) == 0) {
@@ -8946,8 +8983,8 @@
 			new_str_len = (sizeof (DIRECT_BOOT_KERNEL) - 1) +
 			    strlen(old_args) + 2;
 			new_arg = s_calloc(1, new_str_len);
-			(void) snprintf(new_arg, new_str_len, "%s %s",
-			    DIRECT_BOOT_KERNEL, old_args);
+			(void) snprintf(new_arg, new_str_len, "%s",
+			    DIRECT_BOOT_KERNEL);
 			free(kernelp->arg);
 			kernelp->arg = new_arg;
 
@@ -9108,9 +9145,10 @@
 		BAM_DPRINTF((D_GET_SET_KERNEL_REPLACED_KERNEL_SAME_ARG, fcn,
 		    kernelp->arg));
 	} else {
-		new_str_len = old_kernel_len + strlen(path) + 8;
+		kernelp = kernelp->next;
+		new_str_len = strlen(kernelp->arg) + strlen(path) + 8;
 		new_arg = s_calloc(1, new_str_len);
-		(void) strncpy(new_arg, kernelp->arg, old_kernel_len);
+		(void) strncpy(new_arg, kernelp->arg, strlen(kernelp->arg));
 		(void) strlcat(new_arg, " ", new_str_len);
 		(void) strlcat(new_arg, path, new_str_len);
 		free(kernelp->arg);
