Monday, December 3, 2012

A Method to Boot Linux from Flash Drives via EFI on Macs and Why I Hate the EFI Support in Linux

Linux and Macs are like estranged cousins who are always a little antsy around each other. While they can trained to play together, deep down there is a deep resentment of each other. This relationship is not inherently by fault of either Linux or Apple; rather, the issues seem to lie with the hardware and firmware on Mac computers.

Sadly, the situation does not look like it will fix itself anytime soon. Macs require booting via EFI, which for all intents and purposes is horrible on the Linux platform. The only real way to boot Linux via EFI is unfortunately by hacks: GRUB 2, the rudimentary and ubiquitous Linux boot loader used on practically every installation, has working but poor EFI support, and other software like ELILO is not much better.

EFI is going to be way more common now than it was in the past largely due to Microsoft's decision to require UEFI firmware on all new PCs shipping as Windows 8 certified. So the Linux community finds it necessary to get a working EFI boot solution going quickly, but, as the video below demonstrates, everything is not all roses and unicorns:


So, what is to be done with PCs (and Macs) that are now booting via EFI? Well, I have one solution for   a common issue faced by Mac users: booting a Linux distribution from a USB drive without using rEFIt or rEFInd. Fedora seems to have something going, as shown by the following video below, which demonstrates Fedora booting natively on a Mac via EFI:

Sadly, Ubuntu and its derivatives do not have any native or supported way to boot via EFI on Mac platforms. So, I have created a tool called Mac Linux USB Loader to do just that! Open source (license pending) and on GitHub, Mac Linux USB Loader is a free application that copies a selected Linux distribution's ISO file and copy it and an EFI boot loader to the thumb drive of your choice. Best yet, it is non-destructive, which means that unlike other tools, you do not have to erase your thumb drive: all your data is preserved and untouched.

The tool has been successfully used to boot Linux Mint 14.1 from a 2 GB thumb drive. In theory, this shouldn't be restricted to Ubuntu; the only real requirement is that the distribution supports loopback. If you want to try the tool, fork the repository on GitHub and then compile the code in Xcode (binary releases will be released when the code is cleaned up a bit). Please note that the tool is in beta, is buggy, and may not work. You have no warned.

Give it a try and leave your comments/questions/thoughts in the comments below.

22 comments:

Igor said...

First of all thanks a lot for your effort and your work,

however the programm returned me an error "could not copy the EFI bootloader to the usb device"

I tried to format the usb again but not luck.

Could you give me any advice?

Thanks a lot....If this work my macbook pro (late 2006) will run linux!!!

SevenBits said...

@Igor: As I said the program is rather buggy at this stage. Please ensure the following:

1) Your USB device is actually mounted and plugged into your USB port. There is an option in the menu to update the list of USB devices. Press that before you do anything and don't un mount the disk from the Finder or anything.

2) You are running the latest version. If you downloaded the binary from the GitHub page, try compiling the code yourself. I fix bugs in practically every release and so that problem may already have been fixed.

3) Make sure the drive is formatted as FAT and has 2 GB of space available. I do believe I stated this in the requirements but do double check. Remember it must have enough space to hold both the ISO and the EFI software (~200 MBs).

4) You have opened an ISO file with the program. A bug in older versions let you see the program window without having downloaded an ISO, and this resulted in the above error, among other things.

If you would post additional info (OS version, type of USB device, etc) that would also help in determining what your problem is.

Igor said...


Ok, I must work now but tonight I will try and test again following your suggestions.

I'll give some feedback as soon as posible.

Thanks a lot and have a nice day!!!!!

Igor said...


Hi,

I tried it, but not luck. the same error for me. Let me explain what I tried:

1.- I've a USB mounted and plugged into the USB port. I 've tested two USB sticks. One 4GB and the other one 2 GB. Both are formated with FAT32 with the native Disc Utility of Mac os Lion.
In the menu I have update the list of USB devices as you suggest.

2. I'm using the latest version available in https://github.com/features/projects . My skills are not enough to compile the program. :-(, so I used the last one available.

3.- Double checked that the drive is formated as FAT and the USB is at least 2GB.

4.- I have openned ubuntu-12-10-desktop-i386.iso with the program. I can see "Select Drive Drive type msdos at /Volumes/Linux" and I click "Make Live USB". At this moment the program prompt me an error:

Failed to create bootable USB.

Could not copy the EFI bootloader to the USB device.

This is what I tried.

My computer is a macbook pro 2,2 (late 2006). 3GB ram. It is running Lion (updated).

I don´t know if I can help you in some other test.

Anyway...thanks a lot!!!!!

SevenBits said...

@Igor: Hm, how odd. Is there already an EFI folder on the thumb drive? Because the copy fails if the files already exist.

I uploaded an updated version of the program about an hour ago to the GitHub repository. If you go back to the Downloads section you should see another build uploaded. Please try running that and seeing if your luck changes. I made a lot of code changes.

I'm very sorry you're having issues. I hope I can get the program working for you. FYI, please try an ISO with a 64-bit Linux distro as 32-but OSes sometimes fail to boot on OS X when using EFI.

Igor said...


I don't want to annoy you but, in the github repository where can I donwload the updated program?.

I download the zip with the source code but this time I am not able to find the compiled program...:-(...

Thank you very much

Igor said...


I have found it...sorry!!!!


I am going to try it!!!

I will give you some feedback!!!


Igor said...

Hi SevenBits,


The program run properly, BUT:

1.- it creates a file in /Efi/boot/bootX64.efi and copies the *iso to the same folder with the name boot.iso.

2.- The used space in the USB drive is similiar to the size of the original iso, is it ok?

3.- Once I reboot the macbook pro I press "alt" but it did not recognized the usb. I couldn't boot ubuntu from the usb stick.

4.- The cd drive of my macbook is broken so I tried to do this some time ago. I must say that my macbook has a 32 bits firmware and not of 64 bits as the file bootX64 depicts.

5.- Fedora seems to do something with 64 bit firmware but it does not work on 32 bits firmware. I believe that my computer is 32 bits. Do you think that this should work?
I don't know if I did something wrong or just this method does not work in this laptop.

Anyway, Thanks a lot...I hope to be able to install a linux distribution in this computer but without a CD drive (external ones does not work) it seems imposible.

Thanks a lot

Igor

SevenBits said...

1) Yes, that is deliberate. The name boot.iso is hard coded into the EFI loader and so that is why the ISO is given that name.

2) It wouldn't be concerned. As long as the copy completed then you should be okay.

3, 4) That is likely the reason why you cannot boot. As 64-bit is the traditional architecture used by EFI, the EFI firmware is 64-bit. To boot it on your Mac, you need a 32-bit distro and the 32-bit EFI firmware. This is called bootx86.efi and is located in the app's resources folder. Replace bootx64.efi with that file and a 32-bit distro and you should be good to go.

FYI, I hope to automate this in the future.

5) I'm sorry, I don't know enough about Fedora's EFI implementation to answer that. Maybe talk to someone with the Fedora project? I may work if Fedora 32-bit ships with EFI support but I can neither confirm nor deny this.

I hope you have luck getting Linux to boot on a Mac. I wish you luck. Please keep me informed via the comments.

Igor said...


Ok, good and bad news.

I've changed the bootX64.efi with the bootXA32.efi (at the moment I do not remenber the name of the file).

I rebooted my macbook and the USB drive was there!!!!!

I choosed the USB drive and linux started booting but when the screen showed the message "Fasten your seatbelts, we are loading the kernel" it stopped the booting process and the computer freezed.

I think that your programm worked properly. But I don't know why my computer doesn't want to boot linux:-(

If you have any clue about this last problem I would thank you any suggestion...anyway, your program seems to work.

Thanks a lot

Igor

SevenBits said...

I have only two suggestions this time. Make sure that you have a 32-bit distribution on the USB, as older Macs don't like to boot 64-bit Linux.

Also, what video card is in your MacBook? That very well could be the issue; if the MacBook ships with a non-free driver that does not ship with Ubuntu, the computer may not boot.

BUT, my tool did at least work. From here on in it's the fault of Linux. :)

Igor said...


Hi,

Yes I tested with a 32 bit distribution and a 64 bit distribution. In both cases the same problem.

My video card is an ATI Mobility Radeon X1600 256 MB. It could be a clue, I am going to try it tonigh with another distribution....I will tell you if there is any change....

And yes, your tool did work!!! Thanks a lot...I believe that many users will be find it very useful!!!

;-)

Igor said...


No luck,

I 've tried with debian iso-s, but it didn't work.

Ok, I've been reading about the ATI video card and it is definetely unsupported.


Anyway, thanks a lot, hopefully a lot of people will find this program usefull. Very weel done.



Igor

Joe said...

Hi,

I managed to create a USB stick of linux mint which will boot when I hold down alt when turning on the machine. I used tools from pendrivelinux.com to do this. The problem is that I don't want to just create a live USB, I want to actually install the OS on a USB and boot it this way. But try as I might I can't figure out how to do it. Any ideas if/how it may be possible?

SevenBits said...

Hello there,

I suggest going booting into Linux Mint and instead of installing on the hard drive, install on the USB instead. Boot into the USB and install an EFI boot loader such as ELILO onto it. To do this your disc will need to be formatted as GPT. To boot on both PCs and UEFI based systems, you'll need both an MBR and an /EFI/BOOT folder.

There are many websites which will demonstrate how to do this.

Joe said...

Yeah exactly, I'm trying to install it on the USB in order to create an offline only bitcoin wallet that I use from a bootable linux USB. Cool, I'll try and work out how to install ELILO on it!

raffahacks said...

you have to format it using a GUID partition table using Disk Utility

Gibbles said...

Hey SevenBits, Thanks for this very useful program. I'm trying to put Tails Linux Distro on a LiveUSB and boot it from a mac, but this distro doesn't seem to be supported by your program. So my question is, if this is true and there is no work around, do you know of any other ways of installing Tails on a LiveUSB with an EFI boot as you were explaining in the OP?

Thanks

P.S. Every time I've tried installing tails using other software, my mac recognizes the LiveUSB, but when it's loading the distro, it goes to a black screen and says "Missing Operating System". I believe this error has something to do with not having a EFI Bootloader, but I'm not sure. (I'm not very savvy in this area, sorry If my terminology is off) Any help would be appreciated.

Thanks Again,

Gibbles

olki said...

i also need support for tails , damn mac!

Anonymous said...

Don't suppose there is anyone who has yet tried to recompile this for pre-Lion OSX? Would be nice.

Bachas said...

Works like a charm, Thanks a lot !!!

Anonymous said...

The flash drive will be 4 GB, 8 GB, 16 GB or thereabouts in size! Selecting an 80 GB or 300 GB partition from the list would definitely fall outside the scope of these instructions. As per the OS it difficult to boot flash drives.
bulk flash drives