summaryrefslogtreecommitdiffstats
path: root/perl-install/bootloader.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/bootloader.pm')
-rw-r--r--perl-install/bootloader.pm28
1 files changed, 26 insertions, 2 deletions
diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm
index 845674276..adca7a9d3 100644
--- a/perl-install/bootloader.pm
+++ b/perl-install/bootloader.pm
@@ -209,16 +209,40 @@ sub read_grub {
my ($fstab) = @_;
my $grub2dev = read_grub_device_map();
+ my $boot_root = read_grub_install_sh();
+ _may_fix_grub2dev($fstab, $grub2dev, $boot_root->{root});
my $bootloader = read_grub_menu_lst($fstab, $grub2dev) or return;
- if (my $boot = read_grub_install_sh()->{boot}) {
- $bootloader->{boot} = grub2dev($boot, $grub2dev);
+ if ($boot_root->{boot}) {
+ $bootloader->{boot} = grub2dev($boot_root->{boot}, $grub2dev);
}
$bootloader;
}
+sub _may_fix_grub2dev {
+ my ($fstab, $grub2dev, $root) = @_;
+ my $real_root_part = fs::get::root($fstab);
+
+ if (my $prev_root_part = fs::get::device2part(grub2dev($root, $grub2dev), $fstab)) { # the root_device as far as grub config files say
+ $real_root_part == $prev_root_part and return;
+ }
+
+ log::l("WARNING: we have detected that device.map is inconsistent with the system");
+
+ my $real_root_dev = $real_root_part->{rootDevice};
+
+ my ($hd_grub, undef, undef) = parse_grub_file($root);
+ if (my $prev_hd_grub = find { $grub2dev->{$_} eq $real_root_dev } keys %$grub2dev) {
+ $grub2dev->{$prev_hd_grub} = $grub2dev->{$hd_grub};
+ log::l("swapping result: $hd_grub/$real_root_dev and $prev_hd_grub/$grub2dev->{$hd_grub}");
+ } else {
+ log::l("argh... can't swap, setting $hd_grub to $real_root_dev anyway");
+ }
+ $grub2dev->{$hd_grub} = $real_root_dev;
+}
+
sub read_grub_install_sh() {
my $s = cat_("$::prefix/boot/grub/install.sh");
my %h;