help-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Installing grub to raw image


From: Jeremy Davis
Subject: Re: Installing grub to raw image
Date: Wed, 14 Oct 2015 12:53:22 +1100

For the record there is a workaround for the Jessie version of grub.
Primarily it involves forcing grub to load some modules... As previously
noted this is not required in the later grub version.

# set vars
loopdev=/dev/loop0
rootfs.fs=/mnt
grubcfg=$rootfs.fs/boot/grub/grub.cfg
devicemap=$rootfs.fs/boot/grub/device.map
VG=lv

# make a temp device.map
cat > $devicemap <<EOF
(hd0)   $loopdev
EOF

# install grub
chroot $rootfs.fs grub-mkconfig -o /boot/grub/grub.cfg
grub-install --force --modules='part_msdos ext2 search_fs_uuid'
--root-directory=$rootfs.fs $loopdev

# tweak grub config
sed -i "/loopback/d; /set root=(loop/d; s|\(root=\).*
ro|\1/dev/mapper/$VG-root ro dolvm|" $grubcfg

#remove temp grub/device.map
rm -f $devicemap


On 08/10/15 21:51, Jeremy Davis wrote:
> Hi Andrei,
> 
> Thanks for your guidance.
> 
> My primary issue appears to be a bug in the Jessie version of grub
> (2.02~beta2-22). I installed 2.02~beta2-28 (from Stretch) and it all
> seems to be working as it should...
> 
> Like you suggested it seems grub doesn't realise that
> /dev/mapper/loop0p1 is the child of /dev/loop0 whereas the newer version
> does.
> 
> Regards,
> Jeremy
> 
> On 08/10/15 06:07, Andrei Borzenkov wrote:
>> 07.10.2015 05:32, Jeremy Davis пишет:
>>> Hi,
>>>
>>> I am trying to install grub to a raw image (i.e. a flat file that will
>>> be used to house a VM). Host & guest image both Debian Jessie
>>>
>>> I have partitioned the file:
>>> part 1 : ext2 (for boot)
>>> part 2 : LVM (for root & swap)
>>>
>>> I have the raw mounted to /dev/loop0 with kpartx so these partitions
>>> map to:
>>>
>>> part 1 : /dev/mapper/loop0p1
>>> part 2 : /dev/mapper/loop0p2
>>>
>>
>> I can reproduce something similar using grub2 in openSUSE Tumbleweed
>> (2.02~beta2 with selected patches). The problem is that grub fails to
>> detect that /dev/mapper/loop0p1 is partition of /dev/loop0 and so it
>> does not include partition driver. The UUID in my case was correct (that
>> of the first partition), but grub simply could not access it.
>>
>> Current upstream seems to work for me in this configuration. You may
>> want to test if it works for you.
>>
>>> The LVM setup (vg labelled "lv")on part 2 provides:
>>> /dev/mapper/lv-root
>>> /dev/mapper/lv-swap_1
>>>
>>> I then have it mounted like this:
>>>
>>> /dev/mapper/lv-root -> /mnt
>>> /dev/mapper/loop0p1 -> /mnt/boot
>>>
>>> I then install grub like this:
>>>
>>> devicemap=/mnt/boot/grub/device.map
>>> chroot /mnt grub-mkdevicemap
>>> chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
>>> grub-install --force --grub-mkdevicemap=$devicemap --root-directory=/mnt
>>> /dev/loop0
>>>
>>
>> --grub-mkdevicemap is a) no-op, it is accepted for legacy reasons only
>> and b) you are using it incorrectly anyway, it pointed to a program to
>> rebuild device.map, not to device.map itself.
>>
>>> Which appears to install as it should:
>>>
>>> # chroot /mnt grub-mkdevicemap
>>> # chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
>>> Generating grub configuration file ...
>>> Found linux image: /boot/vmlinuz-3.16.0-4-amd64
>>> Found initrd image: /boot/initrd.img-3.16.0-4-amd64
>>> done
>>> # grub-install --force --grub-mkdevicemap=$devicemap
>>> --root-directory=/mnt /dev/loop0
>>> Installing for i386-pc platform.
>>> Installation finished. No error reported.
>>>
>>> (note that both systems are 64 bit so maybe this is the issue? But i
>>> doubt it as the host has the same info...)
>>>
>>> So this appears to all complete fine...
>>>
>>> But when I boot the raw image I get an error about a device not found (a
>>> UUID that I have no idea where it comes from. It does not appear to
>>> match any of the UUIDs that I see in the grub.cfg so I have no idea
>>> where this is coming from!?)
>>>
>>> I can fix grub easy enough from the vm:
>>> -boot with live iso
>>> -mount /dev/mapper/lv-root as /mnt & /dev/sda1 as /mnt/boot
>>> # grub-install --root-directory=/mnt /dev/sda
>>>
>>> Once grub is repaired than all works as it should, however I want it to
>>> just work from the start...
>>>
>>>  From looking around inside the (unbootable) raw it just looks like grub
>>> wasn't installed properly...
>>>
>>> # ls -l /mnt/grub
>>> total 2363
>>> -rw-r--r-- 1 root root      50 Oct  7 01:47 device.map
>>> -r--r--r-- 1 root root    5657 Oct  7 01:47 grub.cfg
>>> -rw-r--r-- 1 root root 2400500 Oct  6 10:18 unicode.pf2
>>>
>>
>> Yes, it looks like grub installed somewhere else. You may want to run
>> grub-install --debug ... to see what it did.
>>
>>> Nothing like (working) /boot/grub on the host:
>>>
>>> # ls -l /boot/grub
>>> total 2380
>>> drwxr-xr-x 2 root root    4096 Aug 31 01:01 fonts
>>> -r--r--r-- 1 root root    7882 Oct  7 00:52 grub.cfg
>>> -rw-r--r-- 1 root root    1024 Aug 31 01:01 grubenv
>>> drwxr-xr-x 2 root root   12288 Oct  7 00:56 i386-pc
>>> drwxr-xr-x 2 root root    4096 Aug 31 01:01 locale
>>> -rw-r--r-- 1 root root 2400500 Aug 13 13:08 unicode.pf2
>>>
>>> FWIW the fixed /boot/grub dir looks the same as the host...
>>>
>>> Any help/guidance/insight/etc warmly welcomed!
>>>
>>> Regards,
>>> Jeremy Davis
>>>
>>> _______________________________________________
>>> Help-grub mailing list
>>> address@hidden
>>> https://lists.gnu.org/mailman/listinfo/help-grub
>>>
>>
> 
> 
> _______________________________________________
> Help-grub mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-grub
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]