Menu

#89 Takes 20sec to load and includes non-bootable partition

closed
nobody
None
5
2011-09-17
2011-09-16
Ken Yeung
No

My machine is a MBA 2011 11.6". I had wiped the entire disk then created these partitions for Lion, Win7 & a share volume (with exFAT FS):

/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *121.3 GB disk0
1: EFI 209.7 MB disk0s1
2: Microsoft Basic Data Win7 20.0 GB disk0s2
3: Microsoft Basic Data Share 50.1 GB disk0s3
4: Apple_HFS Lion 50.3 GB disk0s4
5: Apple_Boot Recovery HD 650.0 MB disk0s5

I manually installed rEFIt to the EFI partition then blessed it with below commands (I need to do this frequently so I made it as rebless.sh:

#!/bin/sh

mount_msdos /dev/disk0s1 /efi

bless --mount /efi --setBoot --file /efi/EFI/refit/refit.efi --labelfile /efi/EFI/refit/refit.vollabel

The problem is that it takes around 20secs to load the OS selection screen, it was just few secs with my another MAC with MACOSX 10.6.

Moreover, the "Share" partition was "detected" by rEFIt and selectable as "Legacy OS", would be nice if that can be removed.

Thanks in advance.

- Ken

Discussion

  • joevt

    joevt - 2011-09-16

    You might consider putting your bless command in rEFItBlesser. You can manually install it by dragging the rEFItBlesser folder to /Library/StartupItems/
    http://sourceforge.net/tracker/index.php?func=detail&aid=3400551&group_id=161917&atid=821764

    http://refit.sourceforge.net/doc/c4s4_safesleep.html
    http://refit.sourceforge.net/doc/c1s1_install.html
    http://refit.sourceforge.net/help/install_reboot.html
    http://refit.sourceforge.net/doc/c1s4_osxupdates.html

    Replace StopService in rEFItBlesser with the below (replace YourLionOSXDisk with the name of one of the partitions on the same disk containing the EFI partition - make sure the name doesn't exist on any other disks so that the wrong EFI partition is not blessed). I haven't tested this myself yet:

    StopService ()
    {
    if MacOSXBlessed ; then
    diskutiloutput="`diskutil list`"
    DEVICE=`echo "$diskutiloutput" | sed -n -E "/^.* \
    YourLionOSXDisk .* (disk[0-9]*)s[0-9]*$/s//\1/p"`
    SLICE=`echo "$diskutiloutput" | sed -n -E "/^.* \
    EFI .* ("$DEVICE"s[0-9]*)$/s//\1/p"`
    MOUNTPOINT="/tmp/EFI"$SLICE
    mkdir $MOUNTPOINT
    mount_msdos /dev/$SLICE $MOUNTPOINT
    if [ -f "$MOUNTPOINT/efi/refit/refit.efi" ]; then
    echo "rEFItBlesser blessing rEFIt on Shutdown"
    bless --mount "$MOUNTPOINT" --file \
    "$MOUNTPOINT/efi/refit/refit.efi" --setBoot
    fi
    umount $MOUNTPOINT
    fi
    return 0
    }

    What rEFItBlesser does is bless Mac OS X on startup, and bless rEFIt at shutdown. You can use "bless --info --getBoot" to see what the current startup preference is.

    I'm not sure what is taking 20 seconds. Did your other Mac use rEFIt on the EFI partition also? Maybe remove the drivers folder from rEFIt.

    The refit.conf file has no options to hide specific partitions. It wouldn't be too difficult to add the feature though.

     
  • Ken Yeung

    Ken Yeung - 2011-09-17

    Thanks Joevt.

    I checked with bless --info and found the startup preference was unset. I manually ran the StartService() commands to bless the MACOSX boot.efi, then copied the rEFItBlesser folder to StartupItems (chown to root:wheel; chmod to 755 as well). I expected the next reboot would trigger the StopService(), but after rebooted I went straight to Lion without rEFIt boot menu.

    How do I check if StopService() had been ran nicely? I did modify a bit of the StopService() as I'm sure about the EFI partition is disk0s1 and the refit.efi file is on "/tmp/EFIdisk0s1/EFI/refit/".

    SLICE="disk0s1"

    StopService ()
    {
    if MacOSXBlessed ; then
    diskutiloutput="`diskutil list`"
    # DEVICE=`echo "$diskutiloutput" | sed -n -E "/^.* Lion .*(disk[0-9]*)s[0-9]*$/s//\1/p"`
    # SLICE=`echo "$diskutiloutput" | sed -n -E "/^.* EFI .*("$DEVICE"s[0-9]*)$/s//\1/p"`
    MOUNTPOINT="/tmp/EFI"$SLICE
    mkdir $MOUNTPOINT
    mount_msdos /dev/$SLICE $MOUNTPOINT
    if [ -f "$MOUNTPOINT/EFI/refit/refit.efi" ]; then
    echo "rEFItBlesser blessing rEFIt on Shutdown"
    bless --mount "$MOUNTPOINT" --file "$MOUNTPOINT/EFI/refit/refit.efi" --setBoot
    fi
    umount $MOUNTPOINT
    fi
    return 0
    }

     
  • joevt

    joevt - 2011-09-17

    I believe those permissions are correct. I have:
    ls -lR /Library/StartupItems
    drwxr-xr-x 4 root wheel 136 Mar 7 2010 rEFItBlesser
    /Library/StartupItems/rEFItBlesser:
    -rw-r--r-- 1 root wheel 72 Mar 7 2010 StartupParameters.plist
    -rwxr-xr-x 1 root wheel 1325 Sep 16 21:34 rEFItBlesser
    Joes-Mac-Pro:~ joevt$

    I added echo commands to StartService and StopService but only the ones in StartService appear in system.log and All Messages in Console.app. So I did "echo >> /Users/Shared/rEFItBlesser.log" which works for both StartService and StopService but I think they will not create the file so you have to make sure the file exists already.

    My StartService looks like this:
    StartService ()
    {
    echo "rEFItBlesser StartService"
    echo "`date` rEFItBlesser StartService" >> /Users/Shared/rEFItBlesser.log
    if ! MacOSXBlessed ; then
    echo "rEFItBlesser blessing Mac OS X on Startup"
    echo "`date` rEFItBlesser blessing Mac OS X on Startup" >> /Users/Shared/rEFItBlesser.log
    bless --folder /System/Library/CoreServices --file /System/Library/CoreServices/boot.efi --setBoot
    fi
    return 0
    }

    You can make similar changes to StopService () to see if it executes all your commands.

    If you edit rEFItBlesser, I think that StopService will not run until after you restart again. Maybe there's a command to make it run at shutdown again without requiring a restart?

    If your Mac has more than one disk, it's not guaranteed that the startup disk will be disk0. The disk number may change after restart.

    About hiding your Share partition:
    I reread a note at https://sourceforge.net/tracker/?func=detail&aid=3174709&group_id=161917&atid=821765 which states that rEFIt looks for boot code on the partition. You could hide your Share partition from rEFIt if you remove the boot code.

    The ScanVolumeBootcode routine that does the check is at:
    http://refit.svn.sourceforge.net/viewvc/refit/trunk/refit/refit/lib.c?revision=451&view=markup

    It looks at the last two bytes of the first block of the partition to make sure they are 0x55, 0xaa and then it checks that the first byte is not 0x00.

    So if you set the first byte of the partition to 0x00, then rEFIt shouldn't show the partition.

    Use fdisk or gdisk to get the start block of the partition (in the below example, I used 409640). Then dd | xxd to output the bytes. Then edit the byte in a text editor. Then xxd | dd the bytes back to the block.

    sudo gpt -r show -l disk0
    sudo dd if=/dev/disk0 bs=512 count=1 skip=409640 | xxd > bootblock.txt
    bbedit bootblock.txt # change the first byte to 00
    xxd -r bootblock.txt > bootblock.bin
    #warning: * untested * will screw up your disk if it's wrong:
    #sudo dd if=bootblock.bin of=/dev/disk0 bs=512 count=1 seek=409640

     
  • joevt

    joevt - 2011-09-17

    I got it working. I noticed that it takes 33 seconds for rEFIt to show up when it's on the EFI partition. It takes only 6 seconds when it's on the Lion partition. Maybe it's because the EFI partition is FAT-32 instead of HFS+? On the EFI partition, I have rEFIt in a folder called EFI (uppercase) which is different than on my Lion partition (efi lowercase). I suppose the thing to test would be a different FAT-32 partition and a different HFS+ partition and different case of the efi folder for each file system.

    diskutil can't be used with StopService. I made a new version which uses mount instead. It assumes the EFI partition is on slice 1 of the startup disk (the one mounted at / )

    StopService ()
    {
    echo "rEFItBlesser StopService"
    echo "`date` rEFItBlesser StopService" >> /Users/Shared/rEFItBlesser.log
    if MacOSXBlessed ; then
    mountoutput="`mount`"
    DEVICE=`echo "$mountoutput" | sed -n -E "/\/dev\/(disk[0-9]*)s[0-9]* on \/ .*$/s//\1/p"`
    SLICE="$DEVICE""s1"
    MOUNTPOINT="/tmp/EFI"$SLICE
    mkdir $MOUNTPOINT >> /Users/Shared/rEFItBlesser.log 2>&1
    mount_msdos /dev/$SLICE $MOUNTPOINT
    if [ -f "$MOUNTPOINT/EFI/refit/refit.efi" ]; then
    echo "rEFItBlesser blessing rEFIt on Shutdown"
    echo "`date` rEFItBlesser blessing rEFIt on Shutdown" >> /Users/Shared/rEFItBlesser.log
    bless --mount "$MOUNTPOINT" --file "$MOUNTPOINT/EFI/refit/refit.efi" --setBoot
    fi
    umount $MOUNTPOINT
    fi
    return 0
    }

    I also fixed an issue in MacOSXBlessed for when the mount point containing the existing blessed item is not mounted during StartService:

    MacOSXBlessed ()
    {
    if bless --info 2> /dev/null | grep 'Blessed System File' | grep ' /System/Library/CoreServices/boot.efi' >/dev/null 2>&1 ; then
    return 0
    fi
    return 1
    }

     
  • Ken Yeung

    Ken Yeung - 2011-09-17

    Eventually I "reinstalled" rEFIt i.e. moved the folders from EFI partitions' /EFI folder to my Lion partition and it was all good.

    Now I'm just using the default rEFItBlesser but added the lines for logging. I ran the enable.sh once then rebooted, from the log I confirmed the Start/Stop Service () were running fine since then.

    For the Share partition thing I just let it be. I'm not totally understand what modifying the partition bytes is so I better stay away for the time being, may be later when I want to clean install of something.

    Thanks a lot Joevt, you're the torch lighting my path and I learnt a lot working on this.

     
  • Ken Yeung

    Ken Yeung - 2011-09-17
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB