You've been digging yourself into a deeper and deeper hole. Fortunately, I think you can still recover. Both to warn off others and to help you learn, I want to point out a few of your mistakes:
- Re-installing Ubuntu because of a boot problem is almost always overkill at best, and runs the risk of destroying your user data at worst. You say that your data still exists, so you may have just wasted some time, but I want to point this out because it could have gone very badly, with lost user data to add to your boot problems.
- Attempting to run Boot Repair from a BIOS-mode boot on a computer that was originally set up in EFI mode was a mistake. You probably didn't even realize you were making this mistake, but you did -- the fact that Boot Repair was complaining about the need for a partition with a "
bios_grub flag" was a clue about this mistake. (This complaint from Boot Repair is clearly not very informative to anybody but experts, sadly.)
- Changing the flag on
bios_grub was a mistake. In
parted and GParted terminology, the "
boot flag" identifies an EFI System Partition (ESP), which is a partition that holds EFI boot loaders. A "
bios_grub flag," OTOH, identifies a BIOS Boot Partition, which holds second-stage GRUB boot loader code for BIOS/CSM/legacy-mode boots. When you re-installed GRUB in BIOS mode, it overwrote the first few sectors of
/dev/sda1, thus damaging the data on the partition. It sounds like your problems began with accidentally trashing this partition, so you probably didn't really do any more damage (except possibly to your
/etc/fstab file), but this was definitely the wrong approach to take. If your problem had had a different cause, this mistake would have made recovery even more difficult.
- Telling Boot Repair to treat
/dev/sda1 as a separate
/boot partition was also a mistake. You ended up telling it to treat that partition as two mutually exclusive things: as a separate
/boot partition and as a BIOS Boot Partition. This could have messed things up even further, but it looks like it didn't really have much of an effect.
As further background on EFI booting, you may want to read my Web page on the subject, the Ubuntu community wiki on EFI booting, and/or Adam Williamson's blog explaining EFI issues. All three of these pages provide background information that may help you deal with this type of problem in the future.
As to the solution: There are several approaches, but I recommend you begin by fixing some of the problems that must be dealt with for any solution:
- Boot a Linux emergency disc.
- Use GParted or
parted to change the "flag" on
boot. Alternatively, use
gdisk to change the type code on this partition to EF00.
- Create a fresh FAT32 filesystem on
/dev/sda1. You can do this with GParted or by using the command-line
/dev/sda6 and edit the
/etc/fstab file on it. You must add an entry to this file to mount
/boot/efi. It should look like this:
/dev/sda1 /boot/efi vfat fmask=133 0 0
Alternatively (and preferably, in some ways), you can change
/dev/sda1 at the start of that line to
XXXX-XXXX is the "UUID" (really a serial number) value for the partition, as reported by
blkid. This value will only be valid after you've created a fresh FAT filesystem on the partition, so it's unknowable as I write this answer.
Once you've made these changes, you must install a fresh EFI-mode boot loader. Several choices are available. The two that are likely to be easiest to install are:
- rEFInd -- You can install rEFInd by booting into Linux using whatever method works, verifying that
/boot/efi is mounted, and installing the Debian package, available from the rEFInd downloads page.
- GRUB 2 via Boot Repair -- The Boot Repair tool should re-install GRUB; however, you must run the program when booted in EFI mode. Check for the presence of a directory called
/sys/firmware/efi. If it's present, you've booted in EFI mode and you can run Boot Repair. If it's not present, you've probably booted in BIOS mode and Boot Repair will be useless at best. If you've booted in BIOS mode, go into your firmware setup utility and disable BIOS/CSM/legacy support; or use your firmware's built-in boot manager to select a boot option that includes the string "EFI" or "UEFI." Unfortunately, I can't be more specific because firmware setup utility and firmware boot manager details vary so much from one computer to another.
It might be necessary to wipe the BIOS-mode GRUB code from the first sector of your hard disk. If you complete the repair and still can't boot from the hard disk, try booting to Linux and typing the following command in a Terminal:
sudo dd if=/dev/zero of=/dev/sda bs=440 count=1
Be very careful when typing that command; a slip-up, especially if you omit or specify the wrong value for
count=, can do serious damage to your disk. That's why I didn't include this in the main recovery procedure.