UEFI to BIOS"">UEFI to BIOS
Berend De Schouwer
Introduction
For those of you who have followed the Samsung Laptop UEFI brick bug at Matthew Garrett’s blog, you may want to change the way your laptop boots from UEFI to BIOS.
If you’ve been Google-ing this, you’ll notice a number of posts for changing BIOS to UEFI, but not the other way round. This post is about UEFI to BIOS.
Why
UEFI is complicated. UEFI is buggy. The BIOS is buggy too, but at least it’s not so complicated.
If you’ve been paying attention, Samsung has a serious UEFI bug. It was first detected in Linux, but it also happens in Windows. Basically you can brick your laptop with valid UEFI calls to a broken Samsung implementation of UEFI. This bricks your laptop. Send it back to the manufacturer.
At the moment, only the Linux samsung_laptop driver triggers the bug in the wild. It’s highly conceivable that more software will be found that triggers this bug.
Problem
I’ve got a Samsung laptop running Fedora 18. It was installed with UEFI, and Fedora duly installed Grub2 with UEFI options. I’d like to change this to a BIOS boot.
Solution
Install Grub2 for BIOS.
Requirements
Live CD
For these instructions, you do not need a live CD. You will always be able to reboot into UEFI mode to fix any problems.
However, if you’re paranoid (like me), you’ll have a Live CD or USB handy. I recommend you come prepared.
Grub2
Fedora 18 splits Grub2 into two packages: one for UEFI and one for BIOS. We need to install the BIOS version.
These can exist side-by-side: yum install grub2
Partitions
Grub needs space for grub stage 1.5. Basically the Grub boot binary is too big for the traditional boot record for BIOS (the MBR) That boot record is only 512 bytes.
For traditional partition tables, Grub just used some scratch space, and the user never had to worry. For UEFI, the partition table is now a GPT partition table, and the user does need to worry. You need to create a BIOS Boot Partition. This is UEFI’s backwards compatible partition.
This partition only needs to be a few KB big. 1 MB is already too big. Depending on how Fedora was installed you might have to re-size your LVM volume. However, Fedora installs partitions aligned to MB boundaries for performance reasons, so you can usually squeeze one in the middle.
Use parted to do this. You want to end up with something like this:
(parted) print Model: ATA LITEONIT LMT-256 (scsi) Disk /dev/sda: 256GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 4 17.4kB 1049kB 1031kB 4 bios_grub 1 1049kB 211MB 210MB fat16 EFI System Partition boot 2 211MB 735MB 524MB ext4 3 735MB 256GB 255GB lvm
Here I created partition 4, and squeezed it in the beginning. Toggle the partition flag to bios_grub.
(parted) mkpart 4 0 1MB (parted) toggle 4 bios_grub (parted) quit
You do not need to format this partition. Therefore you also do not need to mount this partition. Grub will dump a binary to the beginning of this partition.
Bootable Partition
I didn’t need to do this, and I haven’t done this. However, some older BIOS-es will require a bootable partition.
You can’t use parted for this. You must use fdisk, and mark the GPT partition as bootable. I think it’s the ‘a’ option in fdisk (from memory)
Config File
Grub needs a configuration file. For BIOS this is /boot/grub2/grub.cfg For UEFI this was /boot/efi/EFI/fedora/grub.cfg
Grub2 wants you to use /sbin/grub2-mkconfig, and not manually edit a config file. This is what Grub2 wants, and it’s wrong.
/sbin/grub2-mkconfig will create a configuration file for the current boot environment. If you booted UEFI (like you would have), you end up with a UEFI grub.cfg, and not a BIOS grub.cfg.
So first make it: grub2-mkconfig -o /boot/grub2/grub.cfg, then edit it.
- Replace all instances of linuxefi with linux
- Replace all instances of initrdefi with initrd
Boot Record
Now we’re ready to install Grub on the MBR:
grub2-install --target=i386-pc /dev/sda # replace sda with your disk
The --target=i386-pc tells Grub to install BIOS files; and not UEFI files. It has nothing to do with 32bit vs. 64bit kernels.
BIOS setting
Reboot. Go to the boot menu, and find the option for OS type. This will be set to UEFI OS. Change it to CMS OS.
Reboot.
Troubleshooting
- Grub-install moans about --target
- You need the grub2 package. You only have grub2-efi.
- Grub boots to grub>
Grub boots, but doesn’t have a configuration file. Run
grub2-mkconfig -o /boot/grub2/grub.cfg
I often forget the ‘-o’ option, so grub2-mkconfig writes the configuration to stdout.
- Grub moans about linuxefi
- Remember to edit your grub.cfg, and replace linuxefi and initrdefi with the plain versions.
- Grub2-install moans about BIOS Boot Partition
- You need to create an addition partition in your GPT partition table. You need to mark that partition as type bios_grub. Read the parted section again.