3

I accidentally deleted every single partition of my computer except the one that Windows is installed on it. I thought it was a good idea. But it was not.

I have no more MSR or EFI partition, so when I boot it gives an error. I have two disks, one remained untouched and the other disk has Windows on it and had MSR and EFI partitions.

Is there is a way to rebuild those ? There's no problem if it takes time or something; it's not my main computer. I just don't wanna lose the data that are on all the partitions. (since I only deleted partitions where I thought there nothing)

WHAT I'VE TRIED:

  • Boot into Windows (Tiny10, actually) installation media
  • Get a CMD working by Shift+F10
  • Run some bootrec commands I got from the web

  • Boot into Linux (MX Linux exactly) live media
  • Run GParted
  • Recreate a partition in FAT32/FAT16 (I tried both) with flags ESD

  • Install a new Linux system on a second partition (didn't worked as the EFI partition is gone)

Thanks in advance.

Similar question (if not the same): windows efi and system reserved partition mistakenly deleted (posting this to hope there's a solution with no reset)

Also, I don't much care if I can no longer use Windows

HGStyle
  • 71

2 Answers2

4

If you want to restore your data, then start by trying to restore the data partitions, not by taking a detour somewhere else. Recovering the EFI partitions will not help you with recovering data partitions – more likely it will only be harmful, in case the process ends up creating a new EFI partition right on top of where data was.

Deleted partitions can be re-created as long as the new partition has exactly the same start sector (and as long as the tool doesn't "helpfully" erase contents). The testdisk Linux tool can be used to scan for deleted partitions.


To make the disk bootable, you'll first need to manually create and format the EFI partition using GParted or diskpart; then it can be filled in with files using bcdboot (from the Shift-F10 console), which will copy the original bootloader files from \Windows\Boot and will generate a new BCD config. See official Microsoft docs.

The MSR partition is meaningless; you can also create it using diskpart but it only exists to reserve space and not to store anything. [Not to be confused with the "System Reserved" partition of similar name that Windows uses on BIOS disks!]

  1. C:\> diskpart
    DISKPART> sel disk ...
    
  2. Create the EFI partition (efi makes DISKPART automatically set the correct GPT type guid):

    create partition efi size=100
    format quick fs=fat32 label="System"
    assign letter="S"
    
  3. Create the MSR partition if you want:

    create partition msr size=16
    
  4. Assuming the system disk is accessible at C:\Windows:

    bcdboot c:\windows /s S: /f UEFI /v
    

    /s S: tells it to specifically use the recently created partition instead of guessing; and since I don't trust "Tiny10" to properly boot in UEFI mode, /f UEFI tells bcdboot to specifically copy the EFI files even if that's not what the installer is booted through.

The procedure is almost the same for BIOS (legacy) boot as well – except instead of "EFI System" FAT32 partition you have a "Microsoft System" NTFS partition, and the DISKPART commands are slightly different, but it is still populated using the same bcdboot (/f BIOS) in the end. See Microsoft docs.

  1. Create the system partition:

    create partition primary size=100
    format quick fs=ntfs label="System"
    assign letter="S"
    active
    
  2. There is no MSR partition on BIOS/MBR disks.

  3. Use bcdboot with /f BIOS.

(There would be an additional "boot sector" step when starting from a clean disk, but the MBR boot sector was not deleted – it exists outside of any partition – so you probably don't need to reinstall it.)

grawity
  • 501,077
1

Linux tools are not needed to fix Windows and are inefficient to use to do so:
WinPE/WinRE: Resolve boot issues via BootRec/BcdBoot, partition issues via DiskPart/mbr2gpt



Per OP's comment under grawity_u1686's answer, info not included within OP's question:

...[W]hile my computer is UEFI, I always kept it in Legacy mode, and my disks aren't GPT... so I don't really know what kind of partition did I deleted, but my computer... won't boot.



To Resolve:

  1. Enter the UEFI Firmware Settings:

    1. Disable: CSM Mode
      • CSM Mode's sole purpose was to enable distros lacking EFI boot the ability to boot circa <2017 (Windows ≥7 supports EFI boot)
      • CSM Mode results in performance degradation, forcing UEFI [64bit] to emulate BIOS [16bit] in a 32bit environment
    2. Enable: Secure Boot

  2. Boot a Windows Install USBOpen a terminal: Shift+F10

  3. Convert OS drive to GPT via Mbr2Gpt:

    ::# Ascertain OS drive #:
        DiskPart
    
    ::# List drives:
        Lis Dis
        Exit
    
    

    ::# Convert OS drive from MBR to GPT: Mbr2Gpt /Convert /Disk:#

    1. Verify Mbr2Gpt created the requisite Boot and MSR partitions:
      DiskPart
      

      ::# List drives (ensure OS drive has GPT asterisk next to it): Lis Dis

      ::# Select OS drive number: Sel Dis #

      ::# List partitions Lis Par

    2. If drive has EFI and MSR partitions: Skip to Step 5

  4. Create Boot and MSR partitions at the front of the drive:

    ::# If Dual-Booting:
        ::# Windows requires a 100MB EFI partition, whereas distros 
        ::# require different sizes, with max being ~750MB; sum both
        ::# to avoid issues
    

    Cre Par EFI Size=100 Format Quick Fs=FAT32 Label="EFI" Assign Letter=Y Cre Par Msr Size=16


  5. Re-create WinRE partition at the end of the drive if it was deleted:

    ::# Verify if WinRE partition still exists:
        Lis Par
    
    ::# WinRE partition can't be deleted without an override due to
    ::# its attribute flag, so it could still exist
    
    

    ::# If it doesn't, select last partition on the drive: Sel Par #

    ::# Recreate WinRE partition: Shrink Desired=1024 Minimum=1024 Cre Par Pri Id=de94bba4-06d1-4d40-a16a-bfd50179d6ac Format Quick Fs=NTFS Label="WinRE" Gpt Attributes=0x8000000000000001

    ::# Get OS partition mount point: Lis Vol Exit


  6. Rebuild boot files and Resolve boot issues:

    1. If Step 4 was skipped, mount EFI partition at Y: first:
      DiskPart
      

      ::# List volumes: Lis Vol

      ::# Select and mount the EFI partition: Sel Vol # Assign Letter=Y Exit

    2. ::# EFI boot files cannot be rebuilt directly via BootRec /FixBoot
      ::# unless the EFI partition is mounted and "EFI\Microsoft\Boot" is
      ::# entered first, otherwise an Access Denied error will occur
      

      ::# C: is the OS partition from Step 5: BcdBoot C:\Windows /s Y: /f UEFI

      ::# Resolve any other boot issues: BootRec /FixMBR && BootRec /RebuildBCD

      ::# Remove EFI mountpoint: DiskPart

        Sel Vol Y
        Remove
        Exit
      


  7. Reboot to Windows → Open an Admin terminal:
    WinKey+ROpen: powershellCtrl+Shift+OK

  8. Enable WinRE:

    # Ensure WinRE is disabled:
      ReAgentC /Disable
    

    Verify if Winre.wim exists:

    ls "C:\Windows\System32\Recovery" | FindStr /I "Winre.wim" ; ls "C:\Windows\System32\Recovery" -Hidden | FindStr /I "Winre.wim"

    If Winre.wim:

    1. Exists:
      # Enable and verify:
        ReAgentC /Enable ; ReAgentC /Info
      
    2. Doesn't Exist:
      Extract it from a mounted Windows install ISO's install.<esd|wim>
      • ESD:
        ESDs can't be mounted, so use 7zip to extract instead
        # Get list of images [indexes] within the ESD:
          Dism /Get-ImageInfo /ImageFile:"E:\sources\install.esd"
        

        Replace '<#>' with the Windows version index # (usually index 1: Home | 6: Pro):

        & "C:\Program Files\7-Zip\7z.exe" e '-i!<#>\Windows\System32\Recovery\Winre.wim' 'E:\sources\install.esd' -o'C:\Windows\System32\Recovery'

        Enable WinRE and verify:

        ReAgentC /Enable ; ReAgentC /Info

      • WIM:
        Built-in way to do so, although same 7zip command can be used
        # Get list of images [indexes] within the WIM:
          Dism /Get-ImageInfo /ImageFile:"E:\sources\install.wim"
        

        Mount WIM (usually index 1: Home | 6: Pro):

        MkDir "C:\Mount" ; Dism /Mount-Image /ImageFile:"E:\sources\install.wim" /Index:1 /MountDir:"C:\Mount" /ReadOnly

        Copy over Winre.wim:

        Xcopy "C:\Mount\Windows\System32\Recovery\Winre.wim" "$env:WinDir\System32\Recovery\Winre.wim"

        Unmount image, discard changes:

        Dism /Unmount-Image /MountDir:"C:\Mount" /Discard

        Cleanup:

        RmDir -Recurse "C:\Mount"

        Enable WinRE and verify:

        ReAgentC /Enable ; ReAgentC /Info

JW0914
  • 9,096