bootrecover: support for EFI (currently only target x86_64-efi)

This commit is contained in:
Silvan Calarco 2013-06-11 17:19:57 +02:00
parent deb176ea16
commit dcdb576efe
2 changed files with 173 additions and 118 deletions

View File

@ -457,28 +457,6 @@ This tool is also useful before the installation of a third party boot manager i
<string></string>
</stringlist>
</property>
<widget class="Label">
<property name="name">
<cstring>Label24</cstring>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>540</width>
<height>40</height>
</rect>
</property>
<property name="text">
<string>Please, select the openmamba system partition where you want the boot loader to be installed from.</string>
</property>
<property name="textFormat">
<enum>RichText</enum>
</property>
<property name="alignment">
<set>WordBreak|AlignTop</set>
</property>
</widget>
<widget class="Label">
<property name="name">
<cstring>Label3</cstring>
@ -503,27 +481,6 @@ This tool is also useful before the installation of a third party boot manager i
<set>AlignVCenter|AlignLeft</set>
</property>
</widget>
<widget class="ListBox">
<property name="name">
<cstring>devicesbox</cstring>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>540</width>
<height>230</height>
</rect>
</property>
<property name="populationText">
<string></string>
</property>
<property name="associations" stdset="0">
<stringlist>
<string></string>
</stringlist>
</property>
</widget>
<widget class="Label">
<property name="name">
<cstring>showdevice</cstring>
@ -545,6 +502,49 @@ This tool is also useful before the installation of a third party boot manager i
</stringlist>
</property>
</widget>
<widget class="Label">
<property name="name">
<cstring>Label24</cstring>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>540</width>
<height>40</height>
</rect>
</property>
<property name="text">
<string>Please, select the openmamba system partition where you want the boot loader to be installed from.</string>
</property>
<property name="textFormat">
<enum>RichText</enum>
</property>
<property name="alignment">
<set>WordBreak|AlignTop</set>
</property>
</widget>
<widget class="ListBox">
<property name="name">
<cstring>devicesbox</cstring>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>540</width>
<height>230</height>
</rect>
</property>
<property name="populationText">
<string></string>
</property>
<property name="associations" stdset="0">
<stringlist>
<string></string>
</stringlist>
</property>
</widget>
</widget>
<widget class="ScriptObject">
<property name="name">
@ -646,6 +646,9 @@ done
function get_udisks_key() {
LANG=C udisks --show-info $1 | grep " $2:" | head -n1 | sed "s|[[:space:]]*$2:[[:space:]]*\(.*\)|\1|"
}
function get_udisks_key_last() {
LANG=C udisks --show-info $1 | grep " $2:" | tail -n1 | sed "s|[[:space:]]*$2:[[:space:]]*\(.*\)|\1|"
}
@if (@devicesbox.currentItem &gt;= 0)
currdev=@String.section(@devicesbox.item(@devicesbox.currentItem)," ",0)
@showdevice.setText(@devicesbox.item(@devicesbox.currentItem))
@ -661,12 +664,18 @@ function get_udisks_key() {
for device in $devices; do
native_path=`get_udisks_key $device native-path`
[ -e $native_path/partition ] &amp;&amp; continue
is_system_internal=`get_udisks_key $device "system internal"`
partscheme=`get_udisks_key $device scheme`
if [ "$is_system_internal" == "1" -o "@removablebox.checked" == "1" ]; then
[ "$partscheme" == "mbr" ] &amp;&amp; \
dcop @dcopid KommanderIf "addListItem(QString,QString,int)" mbrbox "${device:5:5} (master boot record)" 0
if [ -e $native_path/partition ]; then
partition_label=`get_udisks_key_last $device label`
if [ "${partition_label:0:3}" = "EFI" ]; then
dcop @dcopid KommanderIf "addListItem(QString,QString,int)" mbrbox "${device:5:5} (@i18n("EFI system partition"))" 0
fi
else
is_system_internal=`get_udisks_key $device "system internal"`
partscheme=`get_udisks_key $device scheme`
if [ "$is_system_internal" == "1" -o "@removablebox.checked" == "1" ]; then
[ "$partscheme" == "mbr" ] &amp;&amp; \
dcop @dcopid KommanderIf "addListItem(QString,QString,int)" mbrbox "${device:5:5} (master boot record)" 0
fi
fi
done
dcop @dcopid KommanderIf "setCurrentItem(int)" 0
@ -709,6 +718,44 @@ function get_udisks_key() {
<set>AlignCenter</set>
</property>
</widget>
<widget class="ScriptObject">
<property name="name">
<cstring>setBootableCheckbox</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>530</x>
<y>0</y>
<width>32</width>
<height>32</height>
</rect>
</property>
<property name="associations" stdset="0">
<stringlist>
<string>@BackBox.setChecked(true)
@NextBox.setChecked(true)
@execBegin
mbrstring=@String.section(@mbrbox.item(@mbrbox.currentItem)," ",1)
mbrdevice=@String.section(@mbrbox.item(@mbrbox.currentItem)," ",0)
mbrpart=${mbrdevice:3:2}
if [ "$mbrpart" -a "${mbrstring/EFI}" = "${mbrstring}" ]; then
if [ $mbrpart -le 4 ]; then
dcop @dcopid KommanderIf setEnabled bootableBox true
else
dcop @dcopid KommanderIf setEnabled bootableBox false
dcop @dcopid KommanderIf setChecked bootableBox false
fi
else
dcop @dcopid KommanderIf setEnabled bootableBox false
fi
@execEnd
</string>
</stringlist>
</property>
</widget>
<widget class="ButtonGroup">
<property name="name">
<cstring>BootloaderBox</cstring>
@ -831,43 +878,6 @@ function get_udisks_key() {
</hbox>
</widget>
</widget>
<widget class="ScriptObject">
<property name="name">
<cstring>setBootableCheckbox</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>530</x>
<y>0</y>
<width>32</width>
<height>32</height>
</rect>
</property>
<property name="associations" stdset="0">
<stringlist>
<string>@BackBox.setChecked(true)
@NextBox.setChecked(true)
@execBegin
mbrdevice=@String.section(@mbrbox.item(@mbrbox.currentItem)," ",0)
mbrpart=${mbrdevice:3:2}
if [ "$mbrpart" ]; then
if [ $mbrpart -le 4 ]; then
dcop @dcopid KommanderIf setEnabled bootableBox true
else
dcop @dcopid KommanderIf setEnabled bootableBox false
dcop @dcopid KommanderIf setChecked bootableBox false
fi
else
dcop @dcopid KommanderIf setEnabled bootableBox false
fi
@execEnd
</string>
</stringlist>
</property>
</widget>
</widget>
<widget class="QWidget">
<property name="name">
@ -943,6 +953,25 @@ fi
</stringlist>
</property>
</widget>
<widget class="ScriptObject">
<property name="name">
<cstring>ScriptObject7</cstring>
</property>
<property name="geometry">
<rect>
<x>540</x>
<y>20</y>
<width>32</width>
<height>32</height>
</rect>
</property>
<property name="associations" stdset="0">
<stringlist>
<string>dcop @dcopid KommanderIf setText installlog "`cat ~/.bootrecover.log`"
</string>
</stringlist>
</property>
</widget>
<widget class="ScriptObject">
<property name="name">
<cstring>launchinstall</cstring>
@ -967,11 +996,17 @@ cat &gt; $conffile &lt;&lt; _EOF
# created by openmamba bootrecover wizard
#
_EOF
@dcop(@dcopid, KommanderIf, enableWidget(QString,bool), back,false)
installdevice=@String.section(@devicesbox.item(@devicesbox.currentItem)," ",0)
mountpoint=@String.section(@devicesbox.item(@devicesbox.currentItem)," ",1)
mbrdevice=@String.section(@mbrbox.item(@mbrbox.currentItem)," ",0)
mbrstring="@mbrbox.item(@mbrbox.currentItem)"
if [ "${mbrstring/EFI}" != "${mbrstring}" ]; then
efidevice=/dev/@String.section(@mbrbox.item(@mbrbox.currentItem)," ",0)
else
mbrdevice=/dev/@String.section(@mbrbox.item(@mbrbox.currentItem)," ",0)
fi
IFS=$'\n'
CHAINLOAD_SELECTED=(`dcop @dcopid KommanderIf selection chainloadbox`)
@ -983,7 +1018,8 @@ IFS=$' \t\n'
cat &gt;&gt;$conffile &lt;&lt; _EOF
INSTALL_DEVICE='/dev/$installdevice'
INSTALL_MOUNTPOINT='$mountpoint'
INSTALL_BOOTLOADER_DEVICE='/dev/$mbrdevice'
INSTALL_BOOTLOADER_DEVICE='$mbrdevice'
INSTALL_BOOTLOADER_DEVICE_EFI='$efidevice'
INSTALL_BOOTLOADER_DEVICE_SETBOOTABLE=@bootableBox.checked
INSTALL_BOOTLOADER_CHAINLOAD=($chainloaddevices)
_EOF
@ -1008,25 +1044,6 @@ _EOF
@endif
@BackBox.setChecked(false)
</string>
</stringlist>
</property>
</widget>
<widget class="ScriptObject">
<property name="name">
<cstring>ScriptObject7</cstring>
</property>
<property name="geometry">
<rect>
<x>540</x>
<y>20</y>
<width>32</width>
<height>32</height>
</rect>
</property>
<property name="associations" stdset="0">
<stringlist>
<string>dcop @dcopid KommanderIf setText installlog "`cat ~/.bootrecover.log`"
</string>
</stringlist>
</property>

View File

@ -134,7 +134,8 @@ mount -o bind /proc $MOUNTPOINT/proc || {
abort
}
if [ "$INSTALL_BOOTLOADER_DEVICE" ]; then
if [ "$INSTALL_BOOTLOADER_DEVICE" -o "$INSTALL_BOOTLOADER_DEVICE_EFI" ]; then
for k in $MOUNTPOINT/boot/vmlinuz-*; do
KVER=${k/*\/boot\/vmlinuz-}
@ -143,17 +144,53 @@ if [ "$INSTALL_BOOTLOADER_DEVICE" ]; then
chroot $MOUNTPOINT mkinitrd -f /boot/initramfs-${KVER}.img ${KVER}
done
dcop_write $"Installing bootloader on $INSTALL_BOOTLOADER_DEVICE..." 90
echo $"Installing grub bootloader on $INSTALL_BOOTLOADER_DEVICE" | tee -a $LOG_FILE
if [ "$INSTALL_BOOTLOADER_DEVICE_EFI" ]; then
# EFI
dcop_write $"Installing bootloader on ""$INSTALL_BOOTLOADER_DEVICE_EFI (EFI)..." 90
echo $"Installing grub bootloader on ""$INSTALL_BOOTLOADER_DEVICE_EFI (EFI)" | tee -a $LOG_FILE
[ -e $MOUNTPOINT/boot/efi ] || mkdir -p $MOUNTPOINT/boot/efi
mount $INSTALL_BOOTLOADER_DEVICE_EFI $MOUNTPOINT/boot/efi
grub-install --root-directory=$MOUNTPOINT --efi-directory=$MOUNTPOINT/boot/efi --target=x86_64-efi \
--bootloader-id="openmamba Boot Manager" --recheck --no-floppy
umount $MOUNTPOINT/boot/efi
grub-install $INSTALL_BOOTLOADER_DEVICE --root-directory=$MOUNTPOINT --target=i386-pc --recheck --no-floppy
INSTALL_BOOTLOADER_DEVICE_EFI_BYID=$INSTALL_BOOTLOADER_DEVICE_EFI
for f in `ls /dev/disk/by-id/*`; do
if [ "$INSTALL_BOOTLOADER_DEVICE_EFI" = "`readlink -f $f`" ]; then
INSTALL_BOOTLOADER_DEVICE_EFI_BYID=$f
break
fi
done
sed -i "/^GRUB_INSTALL_DEVICE.*/d" $MOUNTPOINT/etc/sysconfig/grub
cat >> $MOUNTPOINT/etc/sysconfig/grub << _EOF
GRUB_INSTALL_DEVICE_EFI=$INSTALL_BOOTLOADER_DEVICE_EFI_BYID
_EOF
[ "$INSTALL_BOOTLOADER_DEVICE_SETBOOTABLE" = "1" -a \
"${INSTALL_BOOTLOADER_DEVICE:8:2}" ] && {
parted ${INSTALL_BOOTLOADER_DEVICE:0:8} \
set ${INSTALL_BOOTLOADER_DEVICE:8:2} boot on || \
echo $"Warning: there was an error setting bootloader partition as bootable." >&2
}
else
# BIOS
dcop_write $"Installing bootloader on $INSTALL_BOOTLOADER_DEVICE..." 90
echo $"Installing grub bootloader on $INSTALL_BOOTLOADER_DEVICE" | tee -a $LOG_FILE
grub-install $INSTALL_BOOTLOADER_DEVICE --root-directory=$MOUNTPOINT --target=i386-pc --recheck --no-floppy
INSTALL_BOOTLOADER_DEVICE_BYID=$INSTALL_BOOTLOADER_DEVICE
for f in `ls /dev/disk/by-id/*`; do
if [ "$INSTALL_BOOTLOADER_DEVICE" = "`readlink -f $f`" ]; then
INSTALL_BOOTLOADER_DEVICE_BYID=$f
break
fi
done
sed -i "/^GRUB_INSTALL_DEVICE.*/d" $MOUNTPOINT/etc/sysconfig/grub
cat >> $MOUNTPOINT/etc/sysconfig/grub << _EOF
GRUB_INSTALL_DEVICE=$INSTALL_BOOTLOADER_DEVICE_EFI_BYID
_EOF
[ "$INSTALL_BOOTLOADER_DEVICE_SETBOOTABLE" = "1" -a \
"${INSTALL_BOOTLOADER_DEVICE:8:2}" ] && {
parted ${INSTALL_BOOTLOADER_DEVICE:0:8} \
set ${INSTALL_BOOTLOADER_DEVICE:8:2} boot on || \
echo $"Warning: there was an error setting bootloader partition as bootable." >&2
}
fi
[ "$INSTALL_BOOTLOADER_CHAINLOAD" ] && {
# configure boot chainloader for e.g. windows
@ -188,6 +225,7 @@ if [ "$INSTALL_BOOTLOADER_DEVICE" ]; then
GRUB_OTHER_TITLES=(${GRUB_OTHER_TITLES[*]} "\"Windows on $GRUB_OTHER_DEV\"")
fi
done
sed -i "/^GRUB_OTHER_.*/d" $MOUNTPOINT/etc/sysconfig/grub
cat >> $MOUNTPOINT/etc/sysconfig/grub << _EOF
GRUB_OTHER_DEVICES=(${GRUB_OTHER_DEVICES[*]})
GRUB_OTHER_TITLES=(${GRUB_OTHER_TITLES[*]})
@ -207,7 +245,7 @@ fi
umount $MOUNTPOINT/dev
umount $MOUNTPOINT/sys
umount $MOUNTPOINT/proc
umount $MOUNTPOINT
sync
finished
echo $"Installation done. You can now reboot to start the freshly installed system." | tee -a $LOG_FILE