Installing GRUB in a dual-boot
Assuming you're partitioning with MBR
and not GPT
.
First, you can backup and eventually restore your mbr (assuming hda is the target disk):
dd if=/dev/hda of=/path/mbr-backup bs=512 count=1 # backup
dd if=/path/mbr-backup of=/dev/hda bs=512 count=1 # restore
Obviously would be hda1
if you installed grub in the partition and not the disk.
Note if it is in the disk (hda) don't change your partition table between backup and restore.
Second, if your Debian is currently installed, just boot a Live CD and mount the Debian root somewhere:
mkdir /tmp/x
mount /dev/hda1 /tmp/x # Debian root partition
# mount some needed filesystem
mount proc /tmp/x/proc -t proc
mount sysfs /tmp/x/sys -t sysfs
mount --bind /dev /tmp/x/dev
Chroot into the partition and reinstall grub
chroot /tmp/x
grub-install /dev/hda # or hda1 for the partition
Don't know yet if you need an update-grub
also (should verify)
The grub's os-prober
should find your Windows, then if it doesn't boot there's some other problem in the chain loader.
update
If your disk is partitioned as GPT
see this FAQ
in particular this one:
Can Windows 7, Windows Vista, and Windows Server 2008 read, write, and boot from GPT disks?
Yes, all versions can use GPT partitioned disks for data. Booting is only supported for 64-bit editions on UEFI-based systems.
If you have BIOS
use MBR
partitioning, if you have UEFI
then use GPT
.
Related videos on Youtube
Oebele
Updated on September 18, 2022Comments
-
Oebele over 1 year
I've just installed my OSes on a new HDD: Windows 7 and Debian 7. As usual I first installed Windows, then Debian.
At the first attempt, GRUB seems to not have been installed properly, because my computer would just boot into Windows. I found this on debian.org, so I followed its advice:
When there is more than one disk available during installation (for example one hard disk and one USB stick, as it is commonly the case when booting the installer from a USB stick), grub-install may run into problems: it was reported several times, that the GRUB bootloader was installed onto the USB stick instead of the hard disk containing the newly-installed system.
To avoid running into this, make sure to answer "No" when the following question is asked during the installation process: "Install the GRUB boot loader to the master boot record?"; it should be possible to specify the right device at the next step: "Device for boot loader installation".
After I did this, GRUB would show up on boot, but when I selected Windows, the screen would go black and immediately pop back to the GRUB menu. I installed GRUB into the first partition, as that was the one with the boot flag.
My partitions are as follows:
- 100MB System Reserved
- 195GB Windows
- 2GB Swap
- 40GB Linux
I managed to fix the MBR with the Windows CD afterwards, but of course, now Debian is unavailable.
Should I have installed GRUB somewhere else, or is it a different problem ?
-
Pavel Šimerda almost 10 yearsI don't think a separate
/boot
has any relation to the risk of corrupting Windows. Plus, the recommendation of separate/boot
is void without a proper rationale. -
Oebele almost 10 yearsThanks for your answer, I finally found the time to try it out. I think the mistake I made was to install GRUB into the first partition (sdb1) instead of in the disk. When I tried to fix it,
mount proc /tmp/x/proc -t procfs
failed with the message:mount: unknown filesystem type 'procfs'
. When I retried without specifying the type it saidmount: special device proc does not exist
. I am using Knoppix 7, but I don't think that should matter. -
Alex almost 10 years@AleStrooisma my fault, I've edited the answer, it is
-t proc
(or you could use--bind
as for/dev
) -
Oebele almost 10 yearsI should've figured that out myself. Anyway, I am writing this from Debian, so it worked. Feels good to be back in Linux! One issue I ran into, which might be worth mentioning in your answer, was that the live cd needed to be 64 bit in order to be able to chroot to my 64 bit debian installation.
-
Alex almost 10 years@AleStrooisma glad it worked, enjoy your Debian! +1 for mentioning about the arch.
-
Alex almost 10 yearsI'm not sure having a 64 and chrooting into a 32 would fail, probably an argument for another question.
-
Oebele almost 10 yearsI have had my PC installed like this for years, there's nothing wrong with the set-up. Normally however, GRUB installs correctly automatically, but this time I had to do it manually, because it had trouble picking the correct disk.