Skip to content

Commit

Permalink
In MIGRATION_MODE apply disk mappings when devices in GRUB2_INSTALL_D…
Browse files Browse the repository at this point in the history
…EVICES match (cf. issue 1437)
  • Loading branch information
jsmeix committed Jun 27, 2018
1 parent 32098b9 commit 0ce177d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
7 changes: 5 additions & 2 deletions usr/share/rear/conf/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2393,8 +2393,11 @@ BOOTLOADER=""
# so that during "rear recover" /dev/sda could be the USB disk.
# In this case GRUB2_INSTALL_DEVICES="/dev/sda" would install GRUB2
# with the system's GRUB2 configuration on the USB disk which would
# overwrite/destroy the ReaR recovery system bootloader,
# cf. the MIGRATION_MODE description above.
# overwrite/destroy the ReaR recovery system bootloader.
# In MIGRATION_MODE disk mappings (in var/lib/rear/layout/disk_mappings)
# are applied when devices in GRUB2_INSTALL_DEVICES match so that enforcing
# MIGRATION_MODE helps to avoid that GRUB2 gets installed on a wrong disk
# when more than one disk is used.
# When GRUB2_INSTALL_DEVICES is not specified, ReaR tries to automatically determine
# where to install GRUB2 but then the bootloader installation could get wrong.
# For details see the finalize/Linux-i386/620_install_grub2.sh script.
Expand Down
22 changes: 19 additions & 3 deletions usr/share/rear/finalize/Linux-i386/620_install_grub2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,25 @@ fi
if test "$GRUB2_INSTALL_DEVICES" ; then
grub2_install_failed="no"
for grub2_install_device in $GRUB2_INSTALL_DEVICES ; do
LogPrint "Installing GRUB2 on $grub2_install_device (specified in GRUB2_INSTALL_DEVICES)"
# Consider mapped disks (crucial in MIGRATION_MODE),
# cf. https://github.com/rear/rear/issues/1437
# MAPPING_FILE (var/lib/rear/layout/disk_mappings)
# is set in layout/prepare/default/300_map_disks.sh
# but only if MIGRATION_MODE is true:
if test -s "$MAPPING_FILE" ; then
# Cf. the function apply_layout_mappings() in lib/layout-functions.sh
while read source_disk target_disk junk ; do
if test "$grub2_install_device" = "$source_disk" ; then
LogPrint "Installing GRUB2 on $target_disk ($source_disk in GRUB2_INSTALL_DEVICES is mapped to $target_disk in $MAPPING_FILE)"
grub2_install_device="$target_disk"
break
fi
done < "$MAPPING_FILE"
else
LogPrint "Installing GRUB2 on $grub2_install_device (specified in GRUB2_INSTALL_DEVICES)"
fi
if ! chroot $TARGET_FS_ROOT /bin/bash --login -c "$grub_name-install $grub2_install_device" ; then
LogPrintError "Failed to install GRUB2 on the specified $grub2_install_device"
LogPrintError "Failed to install GRUB2 on $grub2_install_device"
grub2_install_failed="yes"
fi
done
Expand Down Expand Up @@ -133,7 +149,7 @@ for disk in $disks ; do
# is written to the correct disk. That's why we make all disks bootable:
continue
fi
LogPrintError "Failed to install GRUB2 on $bootdisk"
LogPrintError "Failed to install GRUB2 on possible boot disk $bootdisk"
fi
done

Expand Down

0 comments on commit 0ce177d

Please sign in to comment.