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
/dev/sda1
from boot
to 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 /dev/sda1
to 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 mkdosfs
or mkfs
utility.
- Mount
/dev/sda6
and edit the /etc/fstab
file on it. You must add an entry to this file to mount /dev/sda1
at /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 UUID="XXXX-XXXX"
, where 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 bs=
or count=
, can do serious damage to your disk. That's why I didn't include this in the main recovery procedure.
Good luck!
In my opinion the best course of action would be to:
- Take back up of all your data using Ubuntu.
- Delete all partitions on Disk 0 (the one with Windows installed).
- Install any of Ubuntu/Windows. They will create the required partitions themselves. (Preferably Windows
In case you want to try and salvage (that seems more difficult now) read on.
Try this first:
gdisk t 2 EFOO
gdisk t 4 0700
Then follow only the Steps 1, 2 and 3 below (DO NOT DO 4).
Reboot to see if it works.
IF NOT, then proceed to the below instructions.
The 300MB SYSTEM partition is most likely (99.99%) the EFI partition. You don't need gparted for the operations we need.
Just boot into Ubuntu and run these:
Find you EFI partition's name
sudo fdisk -l
The EFI partition will be the one with size as 300MB as you have mentioned. Note it's name (/dev/sda2 most likely)
Mount the EFI partition
sudo mkdir /mnt/efipart
sudo mount /dev/sda2 /mnt/efipart
Copy the EFI directory to the partition from your windows install media. First find the name for your Windows install media using fdisk
as in step 1. Let us assume it is /dev/sdc1
sudo cp -R /dev/sdc1/efi/* /mnt/efipart/EFI/
Set the EFI partition flags.
gdisk t 2 EFOO
BTW: Looking again at the partition table you just showed, it seems that this may not work (but is still worth a try).
In case this doesn't work, you will have to repartition the disk (start over from scratch)
See these in case:
https://superuser.com/questions/764799/how-to-create-an-efi-system-partition
How do I create an EFI partition
Best Answer
I wasn't able to find a hardcoded list in the ubiquity source code. The documentation says that partitioning is handled by d-i (debian installer) code to avoid duplication and maintenance effort. But I wasn't able to find an answer in the related packages or the Debian documentation.
Fortunately
/var/log/syslog
, respectively/var/log/installer/syslog
post installation, contains useful information about ubiquity and the installation process. Here is an excerpt from a 12.04 install over a 12.04 install in my VM:Basically the directories bin, dev, etc, lib, lib32, lib64, proc, sbin and sys are deleted as are the contents of usr and var (/usr/local and /var/local seem to be an exception, but test folders I had in usr and var were deleted). The boot directory does not seem to be deleted and is just overwritten by the packages related to grub and the kernel.