Hello!

I noticed that GRUB stopped supporting installation to LVM volumes and
that installing to loop devices also started failing unless --force is
given.  The Release of Debian jessie made me realize that GRUB
2.02~beta2 stopped doing what 1.99 did without complaining.  So I did
some debugging.

A word on what this is needed for:
I have a case where grub-install is asked to install to an LVM volume
[1] that is later passed to Xen to boot a Xen guest.  Inside the Xen
guest the LVM volume is seen as a regular hard disk.  So I can no longer
use grml-debootstrap/grub-install to install to LVM volumes without
patching at least one of those.

To reproduce it:

  # touch /var/tmp/disk2
  # truncate --size=$((100*1024**2)) /var/tmp/disk2
  # loop_device_2="$(losetup --show -f /var/tmp/disk2)"
  # vgcreate vg "${loop_device_2}"
  # lvcreate --name lv -l 100%free vg
  # parted /dev/vg/lv mklabel msdos
  # parted /dev/vg/lv mkpart primary ext4 4m 100%
  # mkfs.ext4 /dev/mapper/vg-lvp1
  # mkdir /mnt/lv-root
  # mount /dev/mapper/vg-lvp1 /mnt/lv-root
  # mkdir /mnt/lv-root/boot
  # grub-install --boot-directory=/mnt/lv-root/boot /dev/mapper/vg-lv
  Installing for i386-pc platform.
  grub-install: error: disk
`lvmid/GrSIBA-3EPT-TxGE-cnSa-glgA-pXpy-Kw8cOg/PD3WT8-956c-CEJ8-yPJE-ttGy-yACP-ffwTac'
not found.

When I add a device map containing that drive ..

  # echo -e
'(lvmid/GrSIBA-3EPT-TxGE-cnSa-glgA-pXpy-Kw8cOg/PD3WT8-956c-CEJ8-yPJE-ttGy-yACP-ffwTac)\t/dev/mapper/vg-lv'
> /mnt/lv-root/boot/grub/device.map

.. grub-install replaces the "lvmid/*" drive to
"hostdisk//dev/mapper/vg-lv" saying

  grub-install: warning: the drive name
`lvmid/GrSIBA-3EPT-TxGE-cnSa-glgA-pXpy-Kw8cOg/PD3WT8-956c-CEJ8-yPJE-ttGy-yACP-ffwTac'
in device.map is incorrect. Using hostdisk//dev/mapper/vg-lv instead.
Please use the form [hfc]d[0-9]* (E.g. `hd0' or `cd').

and remains complaining "disk `lvmid/...' not found.
Since the docs at "13.1 How to specify devices" (docs/grub.info)
advertise "lvmid/" in Git for valid drive syntax, that came unexpected
to me.
Inspecting the code of read_device_map shows that only

  (fd0) ...
  (hd0) ...
  (cd) ...

of the documented syntax are actually registering the drive as-is (which
does match the warning), everything else (including "(lvmid/*)") ends up
being re-written to "(hostdisk/<file>)".  So it does not allow me
helping GRUB in finding the disk.


I did manage convincing grub-install to accept lvmid device map entries
using the patch attached but I would also like to see something that
works out of the box again (including loop devices), of course.


Now that you know about the scenario and problem I would like to ask:

 * How you would like to see this addressed in GRUB code?

 * What replacements to "grub-install --boot-directory=<X> <Y>" can
   you think of for a temporary workaround?
   How would use existing GRUB commands to dump future MBR bytes needed
   to some regular file to apply that to any device using dd after or
   something like that?


Many thanks in advance,



Sebastian


[1] from inside a tool called grmldeboostrap [2], a wrapper around
    deboostrap installing Debian to a given block device
[2] https://github.com/grml/grml-debootstrap
>From 810f62351dbb181843fdfdff7add4893e4e17710 Mon Sep 17 00:00:00 2001
From: Sebastian Pipping <sebast...@pipping.org>
Date: Tue, 5 May 2015 17:58:45 +0200
Subject: [PATCH] Allow for "lvmid/*" device map entries

---
 grub-core/kern/emu/hostdisk.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c
index a3b00c8..81b9840 100644
--- a/grub-core/kern/emu/hostdisk.c
+++ b/grub-core/kern/emu/hostdisk.c
@@ -538,8 +538,14 @@ read_device_map (const char *dev_map)
       map[drive].device = grub_canonicalize_file_name (p);
       if (! map[drive].device)
 	map[drive].device = xstrdup (p);
-      
-      if (!map[drive].drive)
+
+      if (strncmp(drive_e, "lvmid/", sizeof("lvmid/") - 1) == 0)
+	{
+	  map[drive].drive = xmalloc (drive_p - drive_e + sizeof ('\0'));
+	  strncpy (map[drive].drive, drive_e, drive_p - drive_e + sizeof ('\0'));
+	  map[drive].drive[drive_p - drive_e] = '\0';
+	}
+      else if (!map[drive].drive)
 	{
 	  char c;
 	  map[drive].drive = xmalloc (sizeof ("hostdisk/") + strlen (p));
-- 
2.1.4

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to