Accidentally deleted efi partition

403

In my opinion the best course of action would be to:

  1. Take back up of all your data using Ubuntu.
  2. Delete all partitions on Disk 0 (the one with Windows installed).
  3. 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:

  1. 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)

  2. Mount the EFI partition

    sudo mkdir /mnt/efipart
    sudo mount /dev/sda2 /mnt/efipart
    
  3. 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/
    
  4. 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

Share:
403

Related videos on Youtube

Rutik Patil
Author by

Rutik Patil

Updated on September 18, 2022

Comments

  • Rutik Patil
    Rutik Patil over 1 year

    Trying to install fastapi:

    (venv) D:\api>pip install fastapi[all]
    

    Getting the following error:

    ERROR: Command errored out with exit status 1:
         command: 'D:\api\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\LENOVO\\AppData\\Local\\Temp\\pip-install-od3lrye2\\httptools_c5b546c7a9f54ea0831a3639b44e79da\\setup.py'"'"'; __file__='"'"'C:\\Users\\LENOVO\\AppData\\Local\\Temp\\pip-install-od3lrye2\\httptools_c5b546c7a9f54ea0831a3639b44e79da\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\LENOVO\AppData\Local\Temp\pip-record-x1m88nnc\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\api\venv\include\site\python3.10\httptools'
             cwd: C:\Users\LENOVO\AppData\Local\Temp\pip-install-od3lrye2\httptools_c5b546c7a9f54ea0831a3639b44e79da\
        Complete output (25 lines):
        running install
        running build
        running build_py
        creating build
        creating build\lib.win-amd64-3.10
        creating build\lib.win-amd64-3.10\httptools
        copying httptools\_version.py -> build\lib.win-amd64-3.10\httptools
        copying httptools\__init__.py -> build\lib.win-amd64-3.10\httptools
        creating build\lib.win-amd64-3.10\httptools\parser
        copying httptools\parser\errors.py -> build\lib.win-amd64-3.10\httptools\parser
        copying httptools\parser\__init__.py -> build\lib.win-amd64-3.10\httptools\parser
        running egg_info
        writing httptools.egg-info\PKG-INFO
        writing dependency_links to httptools.egg-info\dependency_links.txt
        writing requirements to httptools.egg-info\requires.txt
        writing top-level names to httptools.egg-info\top_level.txt
        reading manifest file 'httptools.egg-info\SOURCES.txt'
        reading manifest template 'MANIFEST.in'
        adding license file 'LICENSE'
        writing manifest file 'httptools.egg-info\SOURCES.txt'
        copying httptools\parser\parser.c -> build\lib.win-amd64-3.10\httptools\parser
        copying httptools\parser\url_parser.c -> build\lib.win-amd64-3.10\httptools\parser
        running build_ext
        building 'httptools.parser.parser' extension
        error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
        ----------------------------------------
    ERROR: Command errored out with exit status 1: 'D:\api\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\LENOVO\\AppData\\Local\\Temp\\pip-install-od3lrye2\\httptools_c5b546c7a9f54ea0831a3639b44e79da\\setup.py'"'"'; __file__='"'"'C:\\Users\\LENOVO\\AppData\\Local\\Temp\\pip-install-od3lrye2\\httptools_c5b546c7a9f54ea0831a3639b44e79da\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\LENOVO\AppData\Local\Temp\pip-record-x1m88nnc\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\api\venv\include\site\python3.10\httptools' Check the logs for full command output. 
    
    • Ashhar Hasan
      Ashhar Hasan over 8 years
      Try using a Windows installation disk, it will be able to make the required partitions. You may try to manually remake the EFI partition if you are willing. Not a difficult task. I'll add instructions as an answer if you say so. And before using the Windows disk, make sure to turn on SecureBoot otherwise Windows will say something about GPT disks. (That Legacy is why Windows was complaining)
    • Ashhar Hasan
      Ashhar Hasan over 8 years
      Look in the documentation for your system's motherboard. They usually have a key to directly go to boot menu (bypassing the BIOS). F12 on new Dells and F2 on recent ThinkPads. I'll add the instructions soon.
    • Mike Menart
      Mike Menart over 8 years
      I got back into the bios and disabled secure boot. For some reason in legacy mode I had to use a different key at boot. I went to my windows 10 usb installer, and now it seems to at least recognize my D drive as a valid install target (for some reason it still doesn't let me use my C drive, maybe because its raid?). However, it wouldn't let me install windows 10 on it because it was ntfs configured instead of fat32, so I guess I'm going to try messing with that a bit. I'd still much rather prefer to install the os on the C drive though, as its msata instead of solid state.
    • Mike Menart
      Mike Menart over 8 years
      Correction, its the efi partition of the d drive that needs to be formatted as fat32. How do I do that? Better yet, how do I put an actual efi partition on my C drive as that would be much better in the end.
    • Ashhar Hasan
      Ashhar Hasan over 8 years
      When you will tell Windows to proceed with the installation it will tell you that it needs to create certain extra partitions to function properly. Try deleting a partition (preferably the small first partition on your disk). But it would be much better if i could see a photo maybe of what you are seeing.
    • Ashhar Hasan
      Ashhar Hasan over 8 years
      Looking at the gdisk output, the easiest way for you is to delete all partitions on /dev/sda. Start the Windows setup (with secure boot enabled) and create a partition through the Windows setup. It will then set up all required partitions. Btw, if you are using the Windows setup from a live USB, make sure it is GPT compatible otherwise it may give you the same error about GPT disks.
    • Mike Menart
      Mike Menart over 8 years
      @Hasan, Looking back at the gdisk output, it doesn't seem to even acknowledge my C drive partitions, just the partitions on my d drive. I'm a little bit worried about reconfiguring the entire partition table due to the fact that my entire C: drive partition is msata RAID0, which makes it rather complicated and I'm not sure I'd be able to reconfigure it. As far as GPT compatible, how would I make sure the setup is GPT compatible? Is there something I can do to make it GPT compatible? Also, I'll try to get a picture posted soon with the error I'm seeing.
    • Ashhar Hasan
      Ashhar Hasan over 8 years
      To ensure that the Windows installation media is GPT compatible, try seeing if the installation media has an efi subdirectory and that secure boot is on. The above two together mean you are running GPT compatible.
    • Ashhar Hasan
      Ashhar Hasan over 8 years
      As a shot in the dark solution, try copying the efi folder onto the EFI partition using Ubuntu.
    • Mike Menart
      Mike Menart over 8 years
      The installation media has an efi subdirectory, and I'm running in secure boot so that should be taken care of. I don't know how I would copy the file to the efi partition, as I can't find the efi partition (if there actually is one), because it doesn't show up in the windows install partition list and gparted won't work... Also I added some pictures above.
    • Ashhar Hasan
      Ashhar Hasan over 8 years
      See the answer below.
    • Ashhar Hasan
      Ashhar Hasan over 8 years
    • ozacha
      ozacha over 2 years
      Do you have Microsoft Visual C++ installed?
  • Mike Menart
    Mike Menart over 8 years
    You basically got it. In the end the right thing to do was just recreate the entire partition table, make an efi partition, and install windows 10 from there. For some reason this took a few tries... but it worked eventually.
  • Ashhar Hasan
    Ashhar Hasan over 8 years
    I am glad your problems were resolved. But still I was hoping to be able to save you the effort of configuring stuff again.
  • Rutik Patil
    Rutik Patil over 2 years
    thank you It worked
  • Tal Folkman
    Tal Folkman over 2 years
    can you vote and accept my answer? @RutikPatil