Menu

How to force legacy boot

2024-05-18
2024-05-20
  • William Morris

    William Morris - 2024-05-18

    I have a 2008 iMac on which I've installed Linux Mint Debian Edition. There's a problem when exiting from Suspend that leaves the screen pink and stripey. This is a known issue that is apparently fixed by booting in legacy mode. When I boot, rEFInd shows me three options:

    EFI\debian\grubx64.efi from BOOT
     boot\vmlinuz-6.1.0-12-amd64 from 107 GiB ext4 volume
     Legacy OS from whole disk volume
    

    Each of these is from the disk (each has a little disk icon)

    The first two work well and appear the same when running. The legacy option goes to a black screen with a slowly blinking cursor.

    I assume that the legacy option is not finding the Linux binary but it doesn't say so. The black screen continues apparently indefinitely (or at least ten minutes waiting). Do I need to configure rEFInd somehow to tell it where the binary is? And how?

    Here's the partition table. I used an MBR because I read somewhere that legacy mode booting would be triggered if an MBR was detected. It didn't work out that way.

    (parted) p                                                                
    Model: ATA Samsung SSD 850 (scsi)
    Disk /dev/sda: 120GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End     Size    Type     File system     Flags
     1      1049kB  316MB   315MB   primary  fat32           boot
     2      316MB   4611MB  4295MB  primary  linux-swap(v1)  swap
     3      4611MB  120GB   115GB   primary  ext4
    
     
  • joevt

    joevt - 2024-05-19

    Does the MBR have boot code? This is block 0 of the disk.
    Is the Linux partition marked as active in the MBR?
    Does the PBR have boot code? This is block 0 of the partition that is marked active in the MBR.
    You may need to use the Linux CD to setup legacy boot.
    Basically, the PBR needs boot code that knows how to load and run legacy GRUB.

     
  • William Morris

    William Morris - 2024-05-19

    Here's the MBR

    sudo od -Ax -a /dev/sda1 
    000000   k   X dle   m   k   f   s   .   f   a   t nul stx  bs  sp nul
    000010 stx nul nul nul nul   x nul nul   ? nul del nul nul  bs nul nul
    000020   h   _  ht nul   X stx nul nul nul nul nul nul stx nul nul nul
    000030 soh nul ack nul nul nul nul nul nul nul nul nul nul nul nul nul
    000040 nul soh   )   J   g   j   ]   B   O   O   T  sp  sp  sp  sp  sp
    000050  sp  sp   F   A   T   3   2  sp  sp  sp  so  us   >   w   |   ,
    000060   "   @   t  vt   V   4  so   ; bel nul   M dle   ^   k   p   2
    000070   d   M syn   M  em   k   ~   T   h   i   s  sp   i   s  sp   n
    000080   o   t  sp   a  sp   b   o   o   t   a   b   l   e  sp   d   i
    000090   s   k   .  sp  sp   P   l   e   a   s   e  sp   i   n   s   e
    0000a0   r   t  sp   a  sp   b   o   o   t   a   b   l   e  sp   f   l
    0000b0   o   p   p   y  sp   a   n   d  cr  nl   p   r   e   s   s  sp
    0000c0   a   n   y  sp   k   e   y  sp   t   o  sp   t   r   y  sp   a
    0000d0   g   a   i   n  sp   .   .   .  sp  cr  nl nul nul nul nul nul
    0000e0 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
     *
    0001f0 nul nul nul nul nul nul nul nul nul nul nul nul nul nul   U   *
    000200   R   R   a   A nul nul nul nul nul nul nul nul nul nul nul nul
    000210 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
    *
    0003e0 nul nul nul nul   r   r   A   a   !   # soh nul   ,  si nul nul
    0003f0 nul nul nul nul nul nul nul nul nul nul nul nul nul nul   U   *
    000400 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
    
     
  • William Morris

    William Morris - 2024-05-19

    And for sda3, the linux partition:

    od -Ax -a /dev/sda3
    000000 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
    *
    000400 nul nul   k nul nul   |   - soh   L del nak nul etb   e stx soh
    000410   D etx   c nul nul nul nul nul stx nul nul nul stx nul nul nul
    000420 nul nul nul nul nul nul nul nul nul  sp nul nul   H   v   H   f
    000430   G   v   H   f  bs nul del del   S   o soh nul soh nul nul nul
    000440   ~   v   D   f nul nul nul nul nul nul nul nul soh nul nul nul
    000450 nul nul nul nul  vt nul nul nul nul soh nul nul   < nul nul nul
    000460   F stx nul nul   k eot nul nul nak etb  vt   x   Y   0   L   ;
    000470 dc4   o  so   %   # nul  gs   8 nul nul nul nul nul nul nul nul
    000480 nul nul nul nul nul nul nul nul   / nul nul nul nul nul nul nul
    000490 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
    *
    

    The first kb is zero.

    Would the active partition be shown in the partition table at the top? I vaguely remember setting partitions active from DOS days...

     
  • joevt

    joevt - 2024-05-19

    Isn't sda1 partition 1? I think sda is the entire disk which has the MBR?

    I would use xxd instead of od to view hex. All those control character names are distracting.

    parted says sda1 has the boot flag. Does that mean it's the MBR's active partition?

    The fdisk command should be able to show the partition table of the MBR including which partition is active.

    sda3 doesn't seem to have any boot code since it's all nul characters.

    What is the contents of sda1 (list of files)? I think it's just the EFI stuff?

     
  • Roderick W. Smith

    To boot in BIOS/CSM/legacy mode, you must install a BIOS-mode boot loader on the disk. This is normally the BIOS version of GRUB; and to install that, you'll need to boot a Linux recovery tool or OS installer and then issue appropriate commands to do the installation. The easiest way to do this is likely to be to use the Boot Repair tool:

    https://help.ubuntu.com/community/Boot-Repair

    That said, in this case your ultimate end state will be to use BIOS-mode GRUB 2 to boot a single OS (Linux Mint), so rEFInd isn't really providing any benefit; you might as well bypass rEFInd and boot directly to GRUB, thus simplifying things. A Mac should boot directly in BIOS/CSM/legacy mode when it's given an MBR disk without an EFI System Partition (ESP). Offhand, I don't recall how it'll boot if it has an MBR disk with both a BIOS-mode boot loader in the MBR and an ESP.

     
  • William Morris

    William Morris - 2024-05-19

    Thanks, I'll try that. I tried the boot-repair tool under the running system and it looks easy, right at my level :-) It wouldn't do the job from the running system so I'll put it on a USB and see if it works.

    I've added the boot info generated by boot-repair before taking any action, just for reference.

    @joevt thanks. Yes I should have given sda, not sda1.

     
  • William Morris

    William Morris - 2024-05-19

    Hmm, seems like I need help to repair the boot-repair image :-(

    I burned boot-repair to a good USB stick and tried booting by holding Alt and the power button on the iMac. This gave me two options 'Windows' (which refers to the internal HD) and EFI boot. The latter is the USB boot-recovery. I booted from the latter and after a short period it said something like Error: '/boot' not found

    Looking at the USB, it does have a boot directory. Any suggestions?

     
  • joevt

    joevt - 2024-05-20

    I don't know if you can boot legacy BIOS using USB on a 2008 Mac. I would stick with a CD to be sure.

    Legacy BIOS boot for old Macs is usually limited to internal disks and built-in CD/DVD.

    BootCamp Assistant.app from a version of macOS that supports your Mac will instruct you to make a CD or USB or something, depending on what that Mac supports.

     
  • joevt

    joevt - 2024-05-20

    The fdisk output in your Boot Info says the EFI partition is marked as the active partition. That seems strange but it might work. xxd the PBR of sda1 to see if it has boot code (before and after you repair boot to see how things get modified). From the output of od, it looks like it does have boot code. xxd output will make it more clear. Also do xxd for the mbr as well.

    dd if=/dev/sda count=1 | xxd
    dd if=/dev/sda1 count=1 | xxd
    dd if=/dev/sda3 count=1 | xxd
    

    Normally I would expect the boot code to be installed on the OS partition.

    The boot info says the suggested/default repair is for EFI, but you want to do legacy/BIOS boot.

     
  • William Morris

    William Morris - 2024-05-20

    I tried it again by burning the ISO to a DVD instead of USB. This succeeded, notwithstanding various errors and warnings that suggested it wouldn't boot. The iMac now boots in legacy mode and suspends/recovers without a pink screen, so job done,

    It does still use rEFInd, which surprises me. Is that expected? I thought the boot-restore process would use just legacy GRUB.

    Attached are the xxd dumps and the new Boot Info generated after booting in legacy mode.

    On waking from suspend the wired network connection no longer works. I added a WIFI setup and that comes back on correctly. This is ironic because I originally switched to an iMac after having endless problems in Debian Linux trying to get the WIFI to come back on automatically after waking from suspend. And back then I had a much better idea of what I was doing.

     
  • joevt

    joevt - 2024-05-20

    The boot restore process is doing legacy/BIOS boot restore, so its not going to affect the EFI boot settings.

    You have to change EFI boot settings to make it boot legacy BIOS boot by default (select the Windows startup option in Startup Disk preferences panel or hold option key at boot to enter the Startup Manager EFI app, select the Windows option, hold control key and press enter, or use the bless command).

    Doing any of those three will set the EFI boot nvram variable to the Boot Camp EFI program in firmware, and the BootCampHD nvram variable to the EFI device path of a disk that has legacy BIOS boot code in the MBR.

    Since the EFI settings weren't changed, rEFInd continues to boot. When you select the legacy boot option in rEFInd, it will set the BootCampHD nvram variable to the disk you selected, then it launches the BootCamp EFI program that is in the firmware.

    rEFInd also sets the active partition flag if you selected legacy boot from a specific partition, rather than the whole disk. Startup Disk preferences panel and Startup Manager don't let you select a specific partition for legacy BIOS boot.

    Your new xxd output shows boot code in the MBR (sda) and the PBR (sda1).
    I don't know if the code in the PBR gets executed? Maybe not. I don't know exactly how Grub Legacy (v0.97) works. Your new boot info log says the stage 2 legacy BIOS boot is loaded from sda3 for /boot/grub/stage2 and /boot/grub/menu.lst . I suppose there could be enough code in the MBR to load the blocks containing grub stage2 (it just needs block numbers which should remain valid as long as the partition and files being loaded don't change location).

     

Log in to post a comment.