From e219385e870764ee4a6b7f9d26e8617eec60f172 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 21 Mar 2008 16:49:14 +0000 Subject: - bootloader-config, drakboot: o fix device.map if it is not consistent with the system (eg: it says hd0 in sdb whereas it now is sda) (#39160) --- perl-install/NEWS | 3 +++ perl-install/bootloader.pm | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'perl-install') diff --git a/perl-install/NEWS b/perl-install/NEWS index 807eb181c..eeda0f57b 100644 --- a/perl-install/NEWS +++ b/perl-install/NEWS @@ -1,3 +1,6 @@ +- bootloader-config, drakboot: + o fix device.map if it is not consistent with the system + (eg: it says hd0 in sdb whereas it now is sda) (#39160) - diskdrake: o fix setting mount point of a /dev/mdX (#39142) (regression introduced in 10.8) 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; -- cgit v1.2.1