--- mage/branches/alx-0_6_0/include/alx.minc 2011/06/30 15:25:12 2518 +++ mage/branches/alx-0_6_0/include/alx.minc 2011/07/04 20:10:20 2563 @@ -42,6 +42,7 @@ local grubopts local OLD_IFS local grubconf="/boot/grub/grub.conf" + local grub2conf="/boot/grub/grub.cfg" local pass KERNEL_IMAGE="$1" @@ -56,65 +57,95 @@ [ -z "${KERNEL_DESCRIPTION}" ] && KERNEL_DESCRIPTION="${KERNEL_IMAGE}" - if [ ! -f ${grubconf} ] + # grub2 + if [[ -x /sbin/grub-mkconfig ]] then - echo "${grubconf} not found" - return 1 - fi + # create a device.map + if [[ ! -f /boot/grub/device.map ]] + then + grub-mkdevicemap + fi - # first of all get the first rootfs instance - for i in $(< ${grubconf}) - do - rootfs="$(echo ${i} | grep root=)" - [[ -n ${rootfs} ]] && break - done - - # then get the grub-root - OLD_IFS="$IFS" - IFS=$'\n' - for i in $(< ${grubconf}) - do - grubroot="$(echo ${i} | grep 'root (' | cut -d' ' -f2)" - [[ -n ${grubroot} ]] && break - done - IFS="${OLD_IFS}" + # needed by grub-mkconfig on the first run + if [[ ! -f /boot/grub/video.lst ]] + then + install -m0644 /$(mlibdir)/grub/*/video.lst /boot/grub/video.lst + fi - # check for special hardware - if [[ -x $(which hwinfo) ]] - then - # zotac devices - if [[ ! -z $(hwinfo --bios --storage | grep -i zotac) ]] + # update grub.cfg + LC_ALL=C grub-mkconfig -o ${grub2conf} + + # install bootloader to disk + #local bootpartition="$(df -h /boot |(read; awk '{print $1; exit}'))" + local bootdisk + bootdisk="$(grub-probe --target=drive /boot | sed 's:(\(.*\),.*):(\1):')" + + # Generate core.img, but don't let it be installed in boot sector + grub-install --no-floppy "${bootdisk}" + + # grub legacy + else + + if [ ! -f ${grubconf} ] then - grubopts="rootdelay=8" - echo "Special device 'ZOTAC' detected!" + echo "${grubconf} not found" + return 1 fi - fi - # fix description - : > ${grubconf} - echo "default 0" >> ${grubconf} - echo "timeout 3" >> ${grubconf} - # using roots current password if one was set - pass="$(grep '^root:' /etc/shadow | cut -d: -f2)" - # or fallback to a default password - [[ -z ${pass} ]] && pass="$1$oc/rCMuc$ZodLQSj6N5zYIJtOBg.RT/" - echo "password --md5 ${pass}" >> ${grubconf} - echo >> ${grubconf} - echo "# normal boot" >> ${grubconf} - echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf} - echo "root ${grubroot}" >> ${grubconf} - echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts}" >> ${grubconf} - echo >> ${grubconf} - echo "# admin boots" >> ${grubconf} - echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf} - echo "lock" >> ${grubconf} - echo "root ${grubroot}" >> ${grubconf} - echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} hardware-auto-detection" >> ${grubconf} - echo >> ${grubconf} - echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf} - echo "lock" >> ${grubconf} - echo "root ${grubroot}" >> ${grubconf} - echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} alx-reset-settings" >> ${grubconf} + # first of all get the first rootfs instance + for i in $(< ${grubconf}) + do + rootfs="$(echo ${i} | grep root=)" + [[ -n ${rootfs} ]] && break + done + + # then get the grub-root + OLD_IFS="$IFS" + IFS=$'\n' + for i in $(< ${grubconf}) + do + grubroot="$(echo ${i} | grep 'root (' | cut -d' ' -f2)" + [[ -n ${grubroot} ]] && break + done + IFS="${OLD_IFS}" + + # check for special hardware + if [[ -x $(which hwinfo) ]] + then + # zotac devices + if [[ ! -z $(hwinfo --bios --storage | grep -i zotac) ]] + then + grubopts="rootdelay=8" + echo "Special device 'ZOTAC' detected!" + fi + fi + + # fix description + : > ${grubconf} + echo "default 0" >> ${grubconf} + echo "timeout 3" >> ${grubconf} + # using roots current password if one was set + pass="$(grep '^root:' /etc/shadow | cut -d: -f2)" + # or fallback to a default password + [[ -z ${pass} ]] && pass="$1$oc/rCMuc$ZodLQSj6N5zYIJtOBg.RT/" + echo "password --md5 ${pass}" >> ${grubconf} + echo >> ${grubconf} + echo "# normal boot" >> ${grubconf} + echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf} + echo "root ${grubroot}" >> ${grubconf} + echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts}" >> ${grubconf} + echo >> ${grubconf} + echo "# admin boots" >> ${grubconf} + echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf} + echo "lock" >> ${grubconf} + echo "root ${grubroot}" >> ${grubconf} + echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} hardware-auto-detection" >> ${grubconf} + echo >> ${grubconf} + echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf} + echo "lock" >> ${grubconf} + echo "root ${grubroot}" >> ${grubconf} + echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} alx-reset-settings" >> ${grubconf} + fi } ## compat