Linux – Deleted Linux Partition and now Grub Rescue Shows Up

linuxmulti-bootwindows

I had dual-booted my Win7 computer with Ubuntu 12.04 a few months ago, but no longer wanted Ubuntu so I deleted that partition using Windows last night. When I booted my computer this morning a black screen came up that said:

error: unknown filesystem

Entering rescue mode…

grub rescue>

The available filesystems are:

(hd0) (hd0,msdos5) (hd0,msdos4) (hd0,msdos2) (hd0,msdos1) (hd1)

I tried looking online and everywhere but it kept on saying to use the Windows 7 installation CD to boot into that and choose "Repair Windows" or something like that. However, I don't have the installation CD because the computer I bought didn't come with it.

So I guess what I'm asking is (1) How do I get into Windows 7? (2) How do I get it so that grub rescue never appears again? (3) Why did it appear just now?

Best Answer

You have a serious problem

You'll need to take great care when proceeding.

When you deleted the partition, you destroyed the data that grub uses to configure itself. That's why you got rescue mode.

It's not about "getting rid" of the grub rescue prompt but is about repairing the damage you did to your system when you altered the partition without fully realizing the implications. Using a windows utility to do this didn't help matters, either.

Restoring your system to a correct state will take some time, patience, and, as I said, care. It's a process with multiple steps, so brace yourself ...


Backing up windows

The first step is to get a backup of all your windows partitions. If windows were booted [and I realize you can't yet--we'll get to that below], windows has a standard backup program. It can create a "system recovery disk", which is a bootable CD/DVD. After creating that, you can use backup to create a "system image" and backup all file data onto a separate USB hard drive. Be sure to enable enough options to create the system image and back up all your partitions.

With both of those, you can fully restore a blown windows partition [you don't have one yet, but ...]. The combo can serve as a installation disk for windows that reimages everything with the latest data you had.

This is a critical step. Do not attempt to "repair" anything before you've done this. You have been warned.


Booting windows automatically

There may be a quick and easy way, if you're lucky.

If the grub.cfg file is intact, grub may have been working normally. That is, the boot menu was available but you didn't hit a key to override, and after the timeout period, grub did the default boot, which was ubuntu, and couldn't find/use it.

If you override [hit any key--spacebar recommended], you will get a menu and can select windows boot [usually at the bottom]. With a short timeout value, you may have to be very quick and try this multiple times.

If you're able to do this, things can be a lot simpler.


Booting windows manually

If the above didn't work ...

You'll have to boot windows manually from the grub rescue prompt. You'll have to enter some detailed commands.

The first step is to determine which device to use from the list you gave. At a guess, I'd say (hd0,msdos1). This is particularly true if you installed windows before ubuntu or windows came pre-installed.

Note that the above is a guess. The definitive way is to create a livecd of gparted [or possibly use your ubuntu livecd] to get a list of the partitions with filesystem types. This should give you a clue as to the correct device.

It wouldn't hurt to write down [or print] this partition information on paper for later reference.

But, you could just try a boot with the guess--caveat emptor.


Sample grub commands

Here is a sample grub.cfg snippet from my system for chainloading to windows. The AABCC56FBCC5369B is a uuid specific to my system, so ignore that.

menuentry 'Windows 7 (loader) (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-AABCC56FBCC5369B' {
    insmod part_msdos
    insmod ntfs
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  AABCC56FBCC5369B
    else
      search --no-floppy --fs-uuid --set=root AABCC56FBCC5369B
    fi
    chainloader +1
}

The relevant commands to be entered manually are:

insmod part_msdos
insmod ntfs
set root='hd0,msdos1'
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'
chainloader +1

You may have to fool around with the options a bit. You may need insmod part_gpt instead of insmod part_msdos

As should be obvious, you may need to adjust hd0,msdos1 to one of your other disks.

Once windows has booted, go back to the previous step and take a backup.

Note: Record the commands [that finally work] on paper. You may have to reenter them.

I'd recommend ignoring any requests by windows to perform updates as you'll [probably] have to reenter the boot commands here when windows requests a reboot.


Repairing the boot

Once again, do not try this until you have a windows backup.

The above methods to boot windows, just allowed windows to be booted once. They did not repair anything related to the boot. If you power off your system or reboot, the above boot steps would have to be repeated.

It is unclear to me what exactly happened when you deleted the partition. Did you simply remove it from the partition table [meaning the space it occupied is now listed as free] or do you also move partitions higher up on the disk to occupy the space of the old partition [something that gparted can do]?

If you were able to use the automatic boot process above, you can simply edit /boot/grub2/grub.cfg and change the set default="0" to point to the windows boot [menu entries are numbered from 0]. This can be done from the ubuntu livecd. You get a shell and your hard drives should be [or can be] cross-mounted under [e.g.] /mnt/sysimage/...

If you had to boot manually, you may be able to boot the ubuntu livecd, get the shell, and run grub2-install on the cross-mounted hard drive. You may need to use other grub2-* utilities. For this, you really should consult detailed grub2 documentation. And, for you, I don't necessarily recommend this.

A simpler, easier way, may to be to use the ubuntu livecd to reinstall ubuntu [temporarily]. This will handle the grub reinstall. You can then boot ubuntu from your hard drive as before and edit /boot/grub2/grub.cfg to change the default.

If, when deleting the partition, if you did a "move", you may have to reverse that operation. Don't do this [or any such operations, IMO] under windows. Use gparted


The /boot partition

On some systems/distros, most usually, /boot resides on its own small partition that is ~2GB or so. That's the standard [and, IMO, recommended] way.

Because you got a grub rescue prompt, that's probably what you have. That's the easy way.

Less likely, but still possible [particularly if you overrode the default], /boot may merely be a directory under the root partition. But, if that were the case, I don't believe grub would have come up at all--YMMV

With a small, separate /boot partition, you can afford to shrink/remove the large ubuntu partition [again] but use a credible tool like gparted. More on this below.


Restoring the boot [alternate]

If you're lucky enough to have the small /boot partition, I recommend leaving grub as the boot loader, even if it only boots windows.

With only the large root partition, you may want to restore windows boot. I do not recommend this for you, based upon your current system state.

There may be a windows based method to do this, which should be easy enough from a booted windows. But, I would have the repaired grub boot going first, as windows likes to reboot during such operations.

How to get windows to do this is beyond my expertise.

If you've got grub running from a large root partition, you can remove most files that are not in /boot.

After that, using gparted, you can shrink the root partition. gparted is smart enough to be able to change all the filesystem index blocks, etc. to maintain integrity. It will also adjust the partition table.

This gives you free space, and gparted can create another partition with the free space, which you could use as a windows (e.g.) D: drive

Related Question