fix partition module names when /boot is on diskfilter

/usr/local/grub2/sbin/grub-install: info: grub-mkimage --directory '/usr/local/grub2/lib/grub/i386-pc' --prefix '(mduuid/e6d1dcf06cea72140bafae74a8677f36)/grub' --output '/boot/grub/i386-pc/core.img' --format 'i386-pc' --compression 'auto'  'ext2' 'msdos' 'msdos' 'diskfilter' 'mdraid1x' 'biosdisk'
.
/usr/local/grub2/sbin/grub-install: error: cannot open `/usr/local/grub2/lib/grub/i386-pc/msdos.mod': No such file or directory.

Introduce common helper for both diskfilter and non-diskfilter case that
converts partition map names into module names.
This commit is contained in:
Andrey Borzenkov 2013-12-07 15:00:37 +04:00
parent 5ff249072d
commit f585c90505
4 changed files with 71 additions and 39 deletions

View File

@ -1,3 +1,9 @@
2013-12-07 Andrey Borzenkov <arvidjaar@gmail.com>
* util/grub-install.c (push_partmap_module): Add helper to convert
partmap names to module names and use it in probe_mods(). Fixes
failure to find partmap modules in diskfilter case.
2013-12-07 Vladimir Serbinenko <phcoder@gmail.com>
* configure.ac: Make unifont mandatory on coreboot.

View File

@ -322,6 +322,21 @@ probe_raid_level (grub_disk_t disk)
return ((struct grub_diskfilter_lv *) disk->data)->segments->type;
}
static void
push_partmap_module (const char *map)
{
char buf[50];
if (strcmp (map, "openbsd") == 0 || strcmp (map, "netbsd") == 0)
{
grub_install_push_module ("part_bsd");
return;
}
snprintf (buf, sizeof (buf), "part_%s", map);
grub_install_push_module (buf);
}
static void
probe_mods (grub_disk_t disk)
{
@ -333,21 +348,11 @@ probe_mods (grub_disk_t disk)
grub_util_info ("no partition map found for %s", disk->name);
for (part = disk->partition; part; part = part->parent)
{
char buf[50];
if (strcmp (part->partmap->name, "openbsd") == 0
|| strcmp (part->partmap->name, "netbsd") == 0)
{
grub_install_push_module ("part_bsd");
continue;
}
snprintf (buf, sizeof (buf), "part_%s", part->partmap->name);
grub_install_push_module (buf);
}
push_partmap_module (part->partmap->name);
if (disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID)
{
grub_diskfilter_get_partmap (disk, grub_install_push_module);
grub_diskfilter_get_partmap (disk, push_partmap_module);
have_abstractions = 1;
}
@ -1098,7 +1103,13 @@ main (int argc, char *argv[])
{
if (install_device[0] == '('
&& install_device[grub_strlen (install_device) - 1] == ')')
install_drive = xstrdup (install_device);
{
size_t len = grub_strlen (install_device) - 2;
install_drive = xmalloc (len + 1);
memcpy (install_drive, install_device + 1, len);
install_drive[len] = '\0';
}
else
{
grub_util_pull_device (install_device);

View File

@ -209,9 +209,23 @@ DEVICE must be an OS device (e.g. /dev/sda)."),
NULL, help_filter, NULL
};
static char *
get_device_name (char *dev)
{
size_t len = strlen (dev);
if (dev[0] != '(' || dev[len - 1] != ')')
return 0;
dev[len - 1] = '\0';
return dev + 1;
}
int
main (int argc, char *argv[])
{
char *root_dev = NULL;
char *dest_dev = NULL;
struct arguments arguments;
grub_util_host_init (&argc, &argv);
@ -250,11 +264,34 @@ main (int argc, char *argv[])
grub_mdraid1x_init ();
grub_lvm_init ();
dest_dev = get_device_name (arguments.device);
if (! dest_dev)
{
/* Possibly, the user specified an OS device file. */
dest_dev = grub_util_get_grub_dev (arguments.device);
if (! dest_dev)
{
char *program = xstrdup(program_name);
fprintf (stderr, _("Invalid device `%s'.\n"), arguments.device);
argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
free(program);
exit(1);
}
grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
arguments.device, dest_dev);
}
else
{
/* For simplicity. */
dest_dev = xstrdup (dest_dev);
grub_util_info ("Using `%s' as GRUB device", dest_dev);
}
/* Do the real work. */
GRUB_SETUP_FUNC (arguments.dir ? : DEFAULT_DIRECTORY,
arguments.boot_file ? : DEFAULT_BOOT_FILE,
arguments.core_file ? : DEFAULT_CORE_FILE,
arguments.device, arguments.force,
dest_dev, arguments.force,
arguments.fs_probe, arguments.allow_floppy);
/* Free resources. */
@ -266,6 +303,8 @@ main (int argc, char *argv[])
free (arguments.dir);
free (arguments.dev_map);
free (arguments.device);
free (root_dev);
free (dest_dev);
return 0;
}

View File

@ -247,13 +247,12 @@ identify_partmap (grub_disk_t disk __attribute__ ((unused)),
void
SETUP (const char *dir,
const char *boot_file, const char *core_file,
const char *dev, int force,
const char *dest, int force,
int fs_probe, int allow_floppy)
{
char *core_path;
char *boot_img, *core_img, *boot_path;
char *root = 0;
char *dest = 0;
size_t boot_size, core_size;
#ifdef GRUB_SETUP_BIOS
grub_uint16_t core_sectors;
@ -270,28 +269,6 @@ SETUP (const char *dir,
#endif
bl.last_length = 0;
{
size_t len = strlen (dev);
if (len > 2 && dev[0] == '(' && dev[len - 1] == ')')
{
dest = xmalloc (len - 1);
strncpy (dest, dev + 1, len - 2);
dest[len - 2] = '\0';
}
}
if (! dest)
{
/* Possibly, the user specified an OS device file. */
dest = grub_util_get_grub_dev (dev);
if (! dest)
grub_util_error (_("Invalid device `%s'.\n"), dev);
grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
dev, dest);
}
/* Read the boot image by the OS service. */
boot_path = grub_util_get_path (dir, boot_file);
boot_size = grub_util_get_image_size (boot_path);
@ -326,7 +303,6 @@ SETUP (const char *dir,
dest_dev = grub_device_open (dest);
if (! dest_dev)
grub_util_error ("%s", grub_errmsg);
free (dest);
core_dev = dest_dev;