Bug 911584

Summary: Perl-Bootloader: (...) <3> pbl-1790.2 Core::GRUB2::GrubDev2UnixDev.252: Error: did not find a match for hd0 in the device map
Product: [openSUSE] openSUSE Distribution Reporter: Ulrich Windl <Ulrich.Windl>
Component: BootloaderAssignee: Steffen Winterfeldt <snwint>
Status: RESOLVED FIXED QA Contact: Jiri Srain <jsrain>
Severity: Major    
Priority: P5 - None CC: mchang, Ulrich.Windl
Version: 13.2   
Target Milestone: ---   
Hardware: x86-64   
OS: openSUSE 13.2   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: Relevant part of pbl.log

Description Ulrich Windl 2015-01-03 19:51:24 UTC
When installing "http://download.opensuse.org/repositories/openSUSE:/13.2/standard/x86_64/ucode-intel-20140913-1.1.x86_64.rpm" the booloader possibly wasn't updated correctly:
[...]
*** Creating image file done ***
Update bootloader...
Perl-Bootloader: 2015-01-03 20:20:30 <3> pbl-1790.2 Core::GRUB2::GrubDev2UnixDev.252: Error: did not find a match for hd0 in the device map
+ exit
D: %posttrans(ucode-intel-20140913-1.1.x86_64): waitpid(3324) rc 3324 status 0
--
This is the contents of /boot/grub2/device.map:
(hd1)	/dev/md125
(hd0)	/dev/md124
--
Installation was done on LVM with LIKS-encrypted PV on an Intel-ICH RAID1; /proc/mdstat:
Personalities : [raid1] 
md124 : active (auto-read-only) raid1 sdc[1] sdd[0]
      244195328 blocks super external:/md125/0 [2/2] [UU]
      
md125 : inactive sdc[1](S) sdd[0](S)
      6248 blocks super external:imsm
--
  PV                                                               VG     Fmt  Attr PSize   PFree
  /dev/mapper/cr_md-uuid-2047fabb:aa554b5d:ff1519a1:7d0ff016-part5 system lvm2 a--  199,98g 3,88g
--

Possible reasons for the problem could be the messages form pbl.log:
pbl-1790.2 Core::GRUB2::GetDeviceMap.131: skip partition /dev/md124 in device map
--
leading to:
pbl-1790.2 Core::GRUB2::GetDeviceMap.180: Warning: empty device.map
--

Some more helpful lines from that log:
pbl-1790.2 Core::SplitDevPath.267: /boot was split to /dev/system/root + /boot
pbl-1790.2 Core::GRUB2::GetKernelDevice.199: From /dev/system/root to /dev/dm-2
pbl-1790.2 Core::GRUB2::ParseLines.503: checking boot device /dev/disk/by-id/md-uuid-2047fabb:aa554b5d:ff1519a1:7d0ff016
pbl-1790.2 Core::GRUB2::ParseLines.539: detected boot_root
--
When running grub2-mkconfig, the following message appeared:
grub2-probe: Fehler: Laufwerk »lvmid/3Ef9oz-Xfr2-XuKX-0fAt-8atP-yzlY-40E7Kz/ELfc6R-zGSn-gPma-Plqu-iakm-opLT-kw8wDv« wurde nicht gefunden..
--
Note the ID refers to VG "system", thin LV "archive" (which is not activly used):
  --- Logical volume ---
  LV Path                /dev/system/archive
  LV Name                archive
  VG Name                system
  LV UUID                ELfc6R-zGSn-gPma-Plqu-iakm-opLT-kw8wDv
  LV Write Access        read/write
  LV Creation host, time i7a, 2014-11-28 22:52:02 +0100
  LV Pool name           arcpool
  LV Status              available
  # open                 0
  LV Size                40,00 GiB
  Mapped size            80,64%
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:8
--
Anyway, a openSUSE boot entry is present in an updated /boot/grub2/grub.cfg.
(Uses "set root='lvmid/3Ef9oz-Xfr2-XuKX-0fAt-8atP-yzlY-40E7Kz/Cksomh-IXF2-DRHY-u1TX-LYSt-Psfa-oPWN9g'")
Comment 1 Steffen Winterfeldt 2015-01-07 09:23:49 UTC
Good point. Michael, as the code was from you, the assumption

https://github.com/openSUSE/perl-bootloader/blob/master/src/Core/GRUB2.pm#L130

is not safe. Looking at the sysfs tree like

--- a/src/Core/GRUB2.pm
+++ b/src/Core/GRUB2.pm
@@ -127,7 +127,9 @@ sub GetDeviceMap {
         }
 
         # skip partitions, assume they were ended with digits
-        if ($kern_dev =~ /\d+$/) {
+        my $sys_dev = $kern_dev;
+        $sys_dev =~ s#/#!#;
+        if (!-d "/sys/block/$sys_dev") {
             $self->milestone ("skip partition $kern_dev in device map");
             next GETMAP;
         }

might work better.

But I'm not at home with the grub2 device map code. :-)
Comment 2 Michael Chang 2015-01-08 09:03:51 UTC
Thanks Steffen.

Hi Ulrich,

Could you please test the updated perl bootloader package from this repository ?

http://download.opensuse.org/repositories/home:/michael-chang:/branches:/Base:/System/openSUSE_Factory/

Thanks.
Comment 3 Ulrich Windl 2015-01-08 10:07:11 UTC
(In reply to Michael Chang from comment #2 "Could you please test...")
Please be a little bit more verbose: What after I installed the package? Run "mkinitrd" or what?
Comment 4 Michael Chang 2015-01-08 10:17:22 UTC
Hi Ulrich,

You can try the commands to see is there any error messages.

 update-bootloader --refresh

 update-bootloader -reinit

Thanks.
Comment 5 Ulrich Windl 2015-01-08 10:33:48 UTC
(In reply to Steffen Winterfeldt from comment #1)
> +        $sys_dev =~ s#/#!#;

I wonder: Shouldn't it be "$sys_dev =~ s#^.*/##;"?
If the device is "/dev/md123" your command would make "!dev/md123" from it, while my command would make "md123". I didn't watch the whole context, but in /sys/block there are entries like "md123"...
While at it, also fix the comment, because the code does something different than the comment suggests.
Comment 6 Steffen Winterfeldt 2015-01-08 11:00:25 UTC
The var holds the device name without '/dev/'.
Comment 7 Ulrich Windl 2015-01-08 19:04:10 UTC
(In reply to comment #2 and comment #4)
The suggested commands take quite some time, and the first one finished without output, while the second one (what is it supposed to do?) gave this output:
Perl-Bootloader: 2015-01-08 20:01:00 <3> pbl-2016.2 Core::RunCommand.1658: Error: '/usr/sbin/grub2-install --target=i386-pc --force --skip-fs-probe "/dev/system/root"' failed with exit code 1, output:
<<<<<<<<<<<<<<<<
i386-pc wird für Ihre Plattform installiert.
  WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
  WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
  WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
  WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
  WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
/usr/sbin/grub2-install: Warnung: Dateisystem »ext2« unterstützt keine Einbettungen.
/usr/sbin/grub2-install: Warnung: Einbettung ist nicht möglich. GRUB kann in dieser Konfiguration nur mittels Blocklisten installiert werden. Blocklisten sind allerdings UNZUVERLÄSSIG und deren Verwendung wird daher nicht empfohlen..
/usr/sbin/grub2-install: Fehler: diskfilter writes are not supported.

>>>>>>>>>>>>>>>>

Was that the command to ruin my boot configuration? ;-)
Comment 8 Michael Chang 2015-01-09 08:46:16 UTC
(In reply to Ulrich Windl from comment #7)
> (In reply to comment #2 and comment #4)
> The suggested commands take quite some time, and the first one finished
> without output, while the second one (what is it supposed to do?) gave this
> output:

It (update-bootloader --reinit) is supposed to reintall your bootloader and also recreate bootloader config.

> Perl-Bootloader: 2015-01-08 20:01:00 <3> pbl-2016.2 Core::RunCommand.1658:
> Error: '/usr/sbin/grub2-install --target=i386-pc --force --skip-fs-probe
> "/dev/system/root"' failed with exit code 1, output:
> <<<<<<<<<<<<<<<<

That's odd, the /dev/system/root definitely can't be the install device. And if it was how could it pass the installation and booted.   

What is your content of /etc/default/grub_installdevice ? Could you please attach it. And also please attach /var/log/pbl.log.

Thanks.

> Was that the command to ruin my boot configuration? ;-)

I suppose Not, because it was failed and aborted ..
Comment 10 Ulrich Windl 2015-01-09 10:13:11 UTC
(In reply to Michael Chang from comment #8)
> That's odd, the /dev/system/root definitely can't be the install device. And
> if it was how could it pass the installation and booted.

--somewhat off-topic--
Well, when installing, I entered that selection in Yast, and Yast accepted it. At the end of the installation there was an error installing the bootloader, and somehow YaST ended with replacing my MBR boot code...

As this is not what I wanted, I had started this query:
https://forums.opensuse.org/showthread.php/502944-Adding-GRUB2-quot-boot-sector-quot-to-Windows-7-boot-manager-with-LUKS-enabled

At the end I managed to install the GRUB2 bootloader in a way that Windows bootloader still works (I guess after the MBR before the first partition starts).
I guess I did not adjust some configuration settings after that
---end off-topic---

> > What is your content of /etc/default/grub_installdevice ? Could you please
> attach it. And also please attach /var/log/pbl.log.

I don't have those here right now. Later.

> > Was that the command to ruin my boot configuration? ;-)
> 
> I suppose Not, because it was failed and aborted ..

Unfortunately not: It replaced my MBR bootloader (Windows). I used my MBR backup to revert the change.
Comment 11 Ulrich Windl 2015-01-15 10:21:30 UTC
Created attachment 619661 [details]
Relevant part of pbl.log
Comment 12 Ulrich Windl 2015-01-17 22:24:15 UTC
# cat /etc/default/grub_installdevice
/dev/disk/by-id/md-uuid-2047fabb:aa594b5d:ff1519a1:7d0ff516
/dev/system/root
Comment 13 Michael Chang 2015-01-19 10:24:26 UTC
(In reply to Ulrich Windl from comment #12)
> # cat /etc/default/grub_installdevice
> /dev/disk/by-id/md-uuid-2047fabb:aa594b5d:ff1519a1:7d0ff516
Fine, this is mbr disk devce on Intel Firmware Raid.

> /dev/system/root

Did your yast2 bootloader settings have enabled root partition as install device for grub2?

Thanks.
Comment 14 Ulrich Windl 2015-01-19 11:40:50 UTC
(In reply to Michael Chang from comment #13)
> Did your yast2 bootloader settings have enabled root partition as install
> device for grub2?

Yes.
Comment 15 Michael Chang 2015-01-20 08:08:27 UTC
(In reply to Ulrich Windl from comment #14)
> (In reply to Michael Chang from comment #13)
> > Did your yast2 bootloader settings have enabled root partition as install
> > device for grub2?
> 
> Yes.

Did you enable it manually? If yes, why ? MBR is unable to chain-load loader image from lvm blocks.

If the setting was not explicitly enabled by user, I wonder YaST did a wrong location proposal here.
Comment 16 Michael Chang 2015-01-20 08:11:02 UTC
Anyway you should delete /dev/system/root in /etc/default/grub_installdevice and do the test again ..
Comment 17 Ulrich Windl 2015-01-20 08:57:30 UTC
In reply to comment #15: I selected (it was allowed) to install the boot loader in the root partition (with the intention to chain-start that from the Windows bootloader), but during installation Yast also installed the bootloader to MBR, replacing the Windows boot loader.
As said in comment #10, I managed to chain-load GRUB2 from Windows boot loader, and I want to keep it that way. I only wish a kernel update would not replace the windows bootloader again. I'm not sure what the requirements for a working configuration are (maybe a boot partition is OK, while a boot Logical Volume ist not).
Comment 18 Michael Chang 2015-01-26 07:38:24 UTC
If you want to keep your Windows MBR, you need to create a boot partition without LVM and place grub2's boot.img (stage1) on that boot file system's reserved sector (usually the first sector) for bootloader. 

For direct LVM booting, MBR is required as we need to embed core.img on continuous sectors larger than 512 byte, which is offered by the gap between MBR and 1st partition, which is considered as extended from MBR.
Comment 19 Michael Chang 2015-01-26 07:42:44 UTC
If no one objects, I'll push the patch in test package (comment#2) to Steffen and close this one.
Comment 20 Michael Chang 2015-01-26 09:10:02 UTC
https://github.com/openSUSE/perl-bootloader/pull/60
Comment 22 Steffen Winterfeldt 2015-03-31 08:22:29 UTC
fix was fixed in Factory