DEV Community

Ahmad
Ahmad

Posted on

How I Broke My Dual Boot, Lost Both Windows and Linux, and Clawed My Way Back With Just a Terminal

The Setup

Like a lot of Linux users, I was running a dual-boot system — Windows on one partition, Linux on another, with GRUB handling the boot menu between them. It had worked fine for months. Then one day, I lost root access on my Linux install.

(Fill in here: how did you lose root? Did you forget the password? Did sudo stop working? Did you mess up /etc/sudoers? This detail matters a lot for the story — readers will want to know how it started.)

The Mistake That Made Everything Worse

Instead of trying to recover root access properly (booting into recovery mode, using a live USB to chroot in and reset the password, etc.), I decided to just get rid of the Linux partition entirely from Windows Disk Management.

That was the real mistake — and here's the technical reason why:

When you dual-boot Windows and Linux with GRUB, GRUB becomes the primary bootloader sitting in the disk's boot sector (or EFI partition), and it holds references to both operating systems' partitions. When I deleted the Linux partition from inside Windows:

  • The Linux OS files were gone, obviously.
  • But GRUB was still installed as the boot manager, and it still tried to load — except now it couldn't find the Linux partition it expected, and in many setups this leaves the system unable to boot into either OS cleanly, because the boot sector / EFI boot entries are now pointing at partitions that no longer exist or have shifted.
  • Windows Boot Manager (bootmgr) either got overwritten by GRUB earlier during Linux installation, or the boot configuration data (BCD) no longer matched the disk layout after the partition deletion.

The result: no GRUB menu, no Windows boot, just errors like grub rescue> or a black screen with no OS loading at all.

The Only Way In: Windows Recovery Environment

The only access I had left was a terminal — and this would have been the Windows Recovery Environment (WinRE) command prompt, reached by:

  1. Booting from a Windows installation USB (or holding Shift + Restart if the machine could still partially boot)
  2. Choosing Repair your computer → Troubleshoot → Advanced Options → Command Prompt

(Confirm: is this how you got your terminal? Or did you use a different rescue/live USB?)

From here, I had raw diskpart and command-line access to the disk — but no working OS to log into yet.

Step 1: Confirming the Damage

First, I used diskpart to check what the disk actually looked like now:

diskpart
list disk
select disk 0
list partition
Enter fullscreen mode Exit fullscreen mode

This confirmed the Linux partition was gone and showed me the current partition layout — important for knowing whether my Windows partition (and its data) was still intact.

Step 2: Rebuilding the Windows Bootloader

With the partition table confirmed, the next job was to repair Windows' ability to boot at all. This is where the bootrec tool comes in — it repairs the Master Boot Record, boot sector, and Boot Configuration Data (BCD):

bootrec /fixmbr
bootrec /fixboot
bootrec /scanos
bootrec /rebuildbcd
Enter fullscreen mode Exit fullscreen mode
  • /fixmbr writes a fresh, Windows-compatible Master Boot Record (this is what overwrites GRUB and hands control back to Windows).
  • /fixboot writes a new boot sector.
  • /scanos scans the disk for installed Windows OS instances.
  • /rebuildbcd rebuilds the Boot Configuration Data store so Windows Boot Manager knows where to find your Windows installation.

If /rebuildbcd doesn't find anything (common when BCD is severely corrupted), the fallback is manually rebuilding it against the Windows partition:

bcdboot C:\Windows
Enter fullscreen mode Exit fullscreen mode

(assuming C: is your Windows partition letter, which you can confirm inside diskpart)

(Was this roughly your sequence, or did you need bcdedit as well to manually rebuild boot entries?)

Step 3: Getting Back Into an Actual User Account

Fixing the bootloader gets you to a Windows login screen — but you mentioned you'd also lost access and had to "attach" your username back. This is almost certainly done one of two ways from that same recovery command prompt, using the offline SAM database:

Option A — enable the hidden built-in Administrator account:

net user administrator /active:yes
Enter fullscreen mode Exit fullscreen mode

This flips on the built-in admin account (disabled by default), letting you log in without a password and fix things from inside Windows.

Option B — reset your own account's password directly:

net user YourUsername NewPassword123
Enter fullscreen mode Exit fullscreen mode

Once logged in through either method, if your original account had lost its admin rights or gotten decoupled somehow, you'd restore it with:

net localgroup administrators YourUsername /add
Enter fullscreen mode Exit fullscreen mode

(This is the part I'm least sure about — do you remember if you enabled the built-in Administrator account, or reset your own account's password? That changes the exact commands in this section.)

Lessons Learned

  • Never delete a partition from the "other" OS without understanding the boot chain first. Deleting Linux from Windows Disk Management doesn't clean up GRUB — it just orphans it.
  • Always keep a live USB (Linux) and a Windows installation/recovery USB on hand. Both saved me here, or would have, sooner.
  • If root access is lost on Linux, the fix is almost always safe/recovery mode + single-user shell to reset the password — not nuking the partition.
  • Consider using Windows Boot Manager as the primary bootloader (with GRUB added as an entry via os-prober or manually) instead of the reverse — it tends to survive Windows updates and partition changes more gracefully.

If you've broken your dual boot in a different way, I'd love to hear how you recovered — drop it in the comments.

Top comments (0)