Changeset 3398


Ignore:
Timestamp:
Aug 4, 2015, 8:57:25 AM (3 years ago)
Author:
bruno
Message:

Adds UEFI boot support to mindi

Refactor into PrepareBootDiskImage? the 2 previously separated functions
to create the boot image, now also supporting UEFI and grub (USB key not
reviewed for now)
Adds grub support for MakeBootConfFile? needed for UEFI boot

Location:
branches/3.2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi/mindi

    r3397 r3398  
    17321732    if [ "$type" = "elilo" ]; then
    17331733        sep="="
     1734        sepdef="="
    17341735    else
    17351736        sep=" "
     1737        sepdef=" "
     1738        if [ "$type" = "grub" ]; then
     1739            sepdef="="
     1740        fi
    17361741    fi
    17371742
    17381743    # Generic header for conf file
    1739     if [ "$type" != "elilo" ] ; then
     1744    if [ "$type" = "elilo" ]; then
     1745        echo -en "prompt\n"
     1746    elif [ "$type" = "grub" ]; then
     1747        echo -en "pause Press a key when ready to restore\n"
     1748    else
    17401749        echo -en "prompt 1\ndisplay message.txt\nF1 message.txt\nF2 boot1.txt\nF3 boot2.txt\nF4 pxe.txt\n"
    1741     else
    1742         echo -en "prompt\n"
    17431750    fi
    17441751
    17451752    # Compute which default option to boot from
     1753    echo -en "default${sepdef}"
    17461754    if [ "$CDRECOVERY" = "yes" ] ; then
    1747         echo -en "default${sep}RESTORE\n"
     1755        if [ "$type" = "grub" ]; then
     1756            # BCO: Which num ???
     1757            echo -en "0\n"
     1758        else
     1759            echo -en "RESTORE\n"
     1760        fi
    17481761    # In case it's mondoarchive
    17491762    elif [ _"$MONDO_SHARE" != _"" ]; then
    17501763        if [ -e "$MINDI_TMP/NETFS-SERVER-MOUNT" ] ; then
    1751             echo -en "default${sep}iso\n"
    1752         else
    1753             echo -en "default${sep}${MINDI_DEFAULT_BOOT_OPTION}\n"
     1764            if [ "$type" = "grub" ]; then
     1765                echo -en "3\n"
     1766            else
     1767                echo -en "iso\n"
     1768            fi
     1769        else
     1770            if [ "$type" = "grub" ]; then
     1771                echo -en "1\n"
     1772            else
     1773                echo -en "${MINDI_DEFAULT_BOOT_OPTION}\n"
     1774            fi
    17541775        fi
    17551776    else
    1756         echo -en "default${sep}expert\n"
     1777        if [ "$type" = "grub" ]; then
     1778            echo -en "0\n"
     1779        else
     1780            echo -en "expert\n"
     1781        fi
    17571782    fi
    17581783
     
    17821807        if [ "$type" = "elilo" ]; then
    17831808            outstr="image=/vmlinuz\n\tlabel=$i\n\tinitrd=/initrd.img\n\troot=/dev/ram0 append=\" rw ramdisk_size=$ramdisk_size $ooo $MINDI_ADDITIONAL_BOOT_PARAMS \"\n"
     1809        elif [ "$type" = "grub" ]; then
     1810            outstr="title $i\n\tkernel /EFI/vmlinuz root=/dev/ram0 rw ramdisk_size=$ramdisk_size ${ooo} $MINDI_ADDITIONAL_BOOT_PARAMS\n\tinitrd=/EFI/initrd.img\n"
    17841811        else
    17851812            ps="/"
     
    17991826            echo -en "image=/memtest.bin\n\tlabel=memtest\n"
    18001827            echo -en "image=/memdisk\n\tlabel=memdisk\nappend=\"initrd=memtest.img\"\n"
     1828        elif [ "$type" = "grub" ]; then
     1829            echo -en "title memtest\n\tkernel /EFI/memtest.efi\n\tinitrd=/EFI/memtest.img\n"
    18011830        else
    18021831            ps="/"
     
    18101839}
    18111840
    1812 
    1813 PrepareBootDiskImage_LILO() {
    1814     local imagesdir dev imagefile fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf
     1841PrepareBootDiskImage() {
     1842    # LILO originally
     1843    local imagesdir dev imagefile fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf bootimage
    18151844    imagesdir=$MINDI_CACHE
    18161845    kernelpath=$1
    1817 
    18181846    retval=0
    18191847
    18201848    old_pwd=`pwd`
    1821     [ ! -e "$kernelpath" ] && Die "PBDI lilo - cannot find $kernelpath kernel"
    1822     echo -en "Making "$BOOT_SIZE"KB boot disk..."
    1823     TurnTgzIntoRdz $MINDI_LIB/rootfs $MINDI_TMP/initrd.img `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into initrd.img; are you SURE your kernel supports loopfs?"
    1824     echo -en "..."
    1825     imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
    1826     mkdir -p $mountpoint
    1827     dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
    1828     LogFile "Creating vfat filesystem on $imagefile"
    1829     mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
    1830     mount -t vfat -o loop $imagefile $mountpoint || LogAll "ERROR: Cannot mount (PBDI)"
    1831 
    1832     # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
    1833     mkdir -p $mountpoint/etc
    1834     liloconf=$mountpoint/elilo.conf
    1835 
    1836     MakeBootConfFile elilo > $liloconf
    1837 
    1838     # Copy it so that CD-ROM menu entry is satisfied
    1839     mountefi=0
    1840     df -T | grep /boot/efi | grep -q vfat
    1841     if [ $? -ne 0 ]; then
    1842         mount /boot/efi
    1843         if [ $? -ne 0 ]; then
    1844             echo "You have to mount your EFI partition when using mindi"
    1845             MindiExit -1
    1846         fi
    1847         mountefi=1
    1848     fi
    1849     el=`find /boot/efi -name elilo.efi`
    1850     cp $el $mountpoint
    1851     cp $liloconf $mountpoint
    1852     if [ $mountefi -eq 1 ]; then
    1853         umount /boot/efi 2>&1 > /dev/null
    1854     fi
    1855 
    1856     LogFile "INFO: Copying $MINDI_TMP/initrd.img to $mountpoint..."
    1857     cp -f $MINDI_TMP/initrd.img $mountpoint 2>> $LOGFILE
    1858     if [ "$?" -ne "0" ] ; then
    1859         LogIt "ERROR: Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
    1860         cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
    1861         LogIt "       Please unload some of your modules and try again. Or increase EXTRA_SPACE and BOOT_SIZE in $MINDI_CONFIG"
    1862         rm -f $MINDI_TMP/mtpt.$$
    1863         LogIt "ERROR: Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
    1864         retval=$(($retval+1))
    1865     fi
    1866     MakeMessageFile $mountpoint | cut -c1-80 > $mountpoint/message.txt
    1867 
    1868     mkdir -p $mountpoint/tmp
    1869     if [ -f "$MINDI_TMP/$MRCFG" ]; then
    1870         cp -f $MINDI_TMP/$MRCFG $mountpoint/tmp
    1871     fi
    1872 
    1873     # copy the kernel across
    1874     [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
    1875     dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
    1876     free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
    1877     cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2>> $LOGFILE
    1878     if [ "$?" -ne "0" ] ; then
    1879         LogFile "INFO: Files at mountpoint ($mountpoint) :"
    1880         du -sk $mountpoint/* >> $LOGFILE
    1881         LogFile "--- end of list of files ---"
    1882         echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n" >> $LOGFILE
    1883         [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
    1884         cd "$old_pwd"
    1885         umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
    1886         rmdir $mountpoint || LogIt "ERROR: Cannot rmdir (PBDI)"
    1887     #   losetup /dev/loop0 -d
    1888         [ "$imagefile" != "" ] && rm -f $imagefile
    1889         LogIt "ERROR: Sorry, your kernel is too big for your image"
    1890         Die "Try to increase EXTRA_SPACE and BOOT_SIZE in $MINDI_CONFIG"
    1891         return 0
    1892     fi
    1893     max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
    1894     LogFile "INFO: Free space left on image = $free_space KB"
    1895     LogFile "INFO: Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K"
    1896     # make it bootable
    1897     [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
    1898     [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
    1899     if [ "$KERN_DISK_MADE" ] ; then
    1900         LogFile "INFO: Not running LILO. It's not that kind of disk."
    1901     fi
    1902 
    1903     cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
    1904     umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
    1905     echo -en "..."
    1906     rmdir $mountpoint || LogIt "ERROR: Cannot rmdir (PBDI)"
    1907     if [ "$retval" -eq "0" ] ; then
    1908         echo -en "...$DONE\n"
    1909         if [ "$KERN_DISK_MADE" ] ; then
    1910             LogIt "INFO: $BOOT_SIZE KB boot disks were created OK\n"
    1911         fi
    1912     else
    1913         echo -en "...failed\n"
    1914         LogIt "WARNING: $BOOT_SIZE""KB boot disk was NOT created\n"
    1915         [ "$imagefile" != "" ] && rm -f $imagefile
    1916     fi
    1917     [ "$retval" -ne "0" ] && LogIt "WARNING: PrepareBootDiskImage() is returning nonzero"
    1918     return $retval
    1919 }
    1920 
    1921 
    1922 PrepareBootDiskImage_ISOLINUX() {
    1923     local imagesdir dev imagefile fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage retval
    1924     imagesdir=$MINDI_CACHE
    1925     kernelpath=$1
    1926     do_boot_root_thingy=""
    1927     retval=0
    1928 
    1929     old_pwd=`pwd`
    1930     [ ! -e "$kernelpath" ] && Die "PBDI isolinux - cannot find $kernelpath kernel"
     1849    [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
    19311850    echo -en "Making "$BOOT_SIZE"KB boot disk..."
    19321851    TurnTgzIntoRdz $MINDI_LIB/rootfs $MINDI_TMP/initrd.img `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into initrd.img; are you SURE your kernel supports loopfs?"
     
    19371856    LogFile "INFO: Creating vfat filesystem on $imagefile"
    19381857    mkfs.vfat $imagefile >> $LOGFILE 2>> $LOGFILE
    1939     # syslinux should be run on a  local file (doen't work through NFS Cf: #297)
    1940     syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
     1858    if [ $BOOT_TYPE = "BIOS" ]; then
     1859        # syslinux should be run on a  local file (doen't work through NFS Cf: #297)
     1860        syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
     1861    fi
    19411862
    19421863    # Only move it now to its final destination and use it now
     
    19441865    imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
    19451866
    1946     mount -t vfat -o loop $imagefile $mountpoint || LogIt "ERROR: Cannot mount (PBDI)"
     1867    mount -t vfat -o loop $imagefile $mountpoint || LogAll "ERROR: Cannot mount (PBDI)"
    19471868
    19481869    # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
    1949     MakeMessageFile $mountpoint | cut -c1-80 > $mountpoint/message.txt
    1950     MakeBootConfFile isolinux > $mountpoint/syslinux.cfg
     1870    if [ $BOOT_TYPE != "BIOS" ]; then
     1871        if [ $BOOT_TYPE = "UNKNOWN" ]; then
     1872            LogAll "ERROR: UNKNOWN BOOT_TYPE. Please report upstream"
     1873            MindiExit -1
     1874        fi
     1875        # EFI or UEFI
     1876        if [ $BOOT_TYPE = "UEFI" ]; then
     1877            # UEFI
     1878            lilodir=$mountpoint/EFI
     1879            mkdir -p $lilodir
     1880            liloconf=$lilodir/BOOTX64.conf
     1881            lilobin=BOOTX64.efi
     1882           
     1883            MakeBootConfFile grub > $liloconf
     1884        else
     1885            # EFI
     1886            lilodir=$mountpoint
     1887            mkdir -p $lilodir
     1888            liloconf=$mountpoint/elilo.conf
     1889            lilobin=elilo.efi
     1890
     1891            MakeBootConfFile elilo > $liloconf
     1892        fi
     1893
     1894        # Copy it so that CD-ROM menu entry is satisfied
     1895        mountefi=0
     1896        df -T | grep /boot/efi | grep -qE 'vfat'
     1897        if [ $? -ne 0 ]; then
     1898            mount /boot/efi
     1899            if [ $? -ne 0 ]; then
     1900                echo "You have to mount your (U)EFI partition when using mindi"
     1901                MindiExit -1
     1902            fi
     1903            mountefi=1
     1904        fi
     1905        el=`find /boot/efi -name $lilobin`
     1906        cp $el $lilodir
     1907        cp $liloconf $lilodir
     1908        if [ $mountefi -eq 1 ]; then
     1909            umount /boot/efi 2>&1 > /dev/null
     1910        fi
     1911    else
     1912        MakeBootConfFile isolinux > $mountpoint/syslinux.cfg
     1913    fi
    19511914    LogFile "INFO: Copying $MINDI_TMP/initrd.img to $mountpoint/initrd.img..."
    19521915    cp -f $MINDI_TMP/initrd.img $mountpoint/initrd.img 2>> $LOGFILE
     
    19561919        LogAll "       Please unload some of your modules and try again."
    19571920        rm -f $MINDI_TMP/mtpt.$$
    1958         LogAll "       Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)."
     1921        LogAll "ERROR: Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
    19591922        LogAll "       Try to increase EXTRA_SPACE and BOOT_SIZE in $MINDI_CONFIG"
    19601923        retval=$(($retval+1))
    19611924    fi
     1925    MakeMessageFile $mountpoint | cut -c1-80 > $mountpoint/message.txt
    19621926
    19631927    mkdir -p $mountpoint/tmp
     
    19721936
    19731937    retval=0
    1974     cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
     1938    cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2>> $LOGFILE
    19751939    retval=$?
    19761940    if [ $KERNEL_IS_XEN = "yes" ]; then
     
    19881952        umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
    19891953        rmdir $mountpoint || LogAll "ERROR: Cannot rmdir (PBDI)"
    1990 
     1954        [ "$imagefile" != "" ] && rm -f $imagefile
    19911955        LogIt "ERROR: Sorry, your kernel is too big for your image"
    19921956        Die "Try to increase EXTRA_SPACE and BOOT_SIZE in $MINDI_CONFIG"
     
    19981962    # make it bootable
    19991963    [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
    2000     mkdir -p $mountpoint/etc
    20011964    [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
     1965
     1966    cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
    20021967    umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
    20031968    echo -en "..."
     
    20061971    if [ "$retval" -eq "0" ] ; then
    20071972        echo -en "...$DONE\n"
    2008         if [ "$KERN_DISK_MADE" ] ; then
    2009             [ "$imagefile" != "" ] && rm -f $imagefile
    2010             LogAll "INFO: $BOOT_SIZE KB boot disks were created OK\n"
    2011         fi
     1973        LogAll "INFO: $BOOT_SIZE KB boot disks were created OK\n"
    20121974    else
    20131975        echo -en "...failed\n"
    20141976        LogAll "WARNING: $BOOT_SIZE""KB boot disk was NOT created\n"
    2015         [ "$imagefile" != "" ] && rm -f $imagefile
    2016     fi
     1977    fi
     1978    [ "$imagefile" != "" ] && rm -f $imagefile
    20171979    [ "$retval" -ne "0" ] && LogAll "ERROR: PrepareBootDiskImage() is returning nonzero"
    20181980    return $retval
    20191981}
    2020 
    20211982
    20221983ParseModprobeForIncludes() {
     
    32803241done
    32813242
    3282 KERN_DISK_MADE=""
    3283 
    32843243LogFile "DIFFERENTIAL = $DIFFERENTIAL"
    32853244LogFile "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE"
     
    33303289
    33313290LogFile "INFO: Ramdisk will be $ramdisk_size KB"
    3332 if [ "$ARCH" = "ia64" ] ; then
    3333     PrepareBootDiskImage_LILO $kernelpath || Die "Failed to create ia64 image disk image."
    3334 else
    3335     PrepareBootDiskImage_ISOLINUX $kernelpath || Die "Failed to create $ramdisk_size KB disk image."
    3336 fi
     3291PrepareBootDiskImage $kernelpath || Die "Failed to create boot disk image."
    33373292
    33383293[ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
  • branches/3.2/mondo/src/common/libmondo-devices.c

    r3395 r3398  
    21262126    if (fd != NULL) {
    21272127        ret = UEFI;
     2128        log_msg(2, "UEFI boot mode detected");
    21282129        closedir(fd);
    21292130    }
  • branches/3.2/mondo/src/mondorestore/mondo-prep.c

    r3380 r3398  
    798798#else
    799799#ifdef __IA64__
    800     /* For EFI partitions take fat16
     800    /* For EFI or UEFI partitions take fat16
    801801     * as we want to make small ones */
    802802    mr_asprintf(program, "mkfs -t %s -F 16 %s", format, device);
Note: See TracChangeset for help on using the changeset viewer.