From: Sebastian Pipping <sebastian@pipping.org>
To: grub-devel@gnu.org
Subject: Future of installing GRUB to LVM volumes (and loop devices)
Date: Tue, 05 May 2015 18:54:03 +0200 [thread overview]
Message-ID: <5548F5AB.4080305@pipping.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 3222 bytes --]
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
[-- Attachment #2: 0001-Allow-for-lvmid-device-map-entries.patch --]
[-- Type: text/x-patch, Size: 1113 bytes --]
From 810f62351dbb181843fdfdff7add4893e4e17710 Mon Sep 17 00:00:00 2001
From: Sebastian Pipping <sebastian@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
next reply other threads:[~2015-05-05 16:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-05 16:54 Sebastian Pipping [this message]
2015-05-05 17:38 ` Future of installing GRUB to LVM volumes (and loop devices) Andrei Borzenkov
2015-05-06 12:30 ` Sebastian Pipping
2015-05-06 17:16 ` Andrei Borzenkov
2015-05-12 10:41 ` Sebastian Pipping
2015-05-12 11:41 ` Andrei Borzenkov
2015-05-15 9:28 ` Sebastian Pipping
2015-05-15 9:34 ` Andrei Borzenkov
2015-05-15 10:42 ` Sebastian Pipping
2015-05-16 3:47 ` Jordan Uggla
2015-05-16 14:10 ` Sebastian Pipping
2015-05-16 23:33 ` Jordan Uggla
2015-05-17 8:14 ` Andrei Borzenkov
2015-05-21 21:41 ` Sebastian Pipping
2015-05-21 21:44 ` Vladimir 'phcoder' Serbinenko
2015-05-21 21:48 ` Sebastian Pipping
2015-05-21 22:17 ` Vladimir 'phcoder' Serbinenko
2015-05-21 22:20 ` Sebastian Pipping
2015-05-22 2:25 ` Andrei Borzenkov
2015-05-07 9:35 ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-05-12 9:16 ` Sebastian Pipping
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=5548F5AB.4080305@pipping.org \
--to=sebastian@pipping.org \
--cc=grub-devel@gnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).