Fix Windows MBR using Ubuntu Live CD and ms-sys tool
Solution 1
To restore the MBR, the accepted method is to use a Windows CD. We didn’t have that luxury. Fortunately we had a Ubuntu Live USB in hand.
The method to fix the MBR is:
- Boot the machine using the Live USB/CD.
- Install lilo
sudo apt-get install lilo
- Fix the MBR using lilo using the command:
sudo lilo -M /dev/sda mbr
Works like a charm!
Solution 2
First, your partition table appears to have two active partitions, which may prevent your computer from booting even if you fix the problem of the MBR.
Windows's MBR boot is kind of funky because it uses a "default" MBR to load the MBR of the active partition. Before you change the boot records, try unmarking one of the partitions and booting.
If that doesn't work, the package mbr
may be worth looking into. It is able to install the "default" MBR to your disk, which just loads the boot code from the active partition.
As per your question, read/follow these bullet points at your own risk. This stuff has the ability to mess up your partition table. Back it up using dd if=/dev/sda of=table.bin bs=512 count=1
first. I would also recommend backing up all your files. If I understand the docs correctly, doing these commands without -w
may prevent them from writing anything without additional user intervention.
-
ms-sys /dev/sda
will inspect the hard dist partitions - Please read the documentation here. From what I gather,
ms-sys
can be quite dangerous and is designed to obliterate your entire MBR along with the partition table in several situations. It would seem you are using the wrong utility for the job. -
ms-sys --ntfs /dev/sdaX
wheresdaX
is your partition with Windows 7 on it. This might do what you are expecting, but probably not.
I think you have the wrong utility for the job here. This does not "fix" MBR's, it destroys and creates them. You may get lucky and have the new partition table line up with the new one, but I wouldn't count on it. Try booting a grub CD and typing chainloader (hd0,<win7 partition>)+1
at the prompt and seeing if it boots. This will help diagnose where your problem is. If else fails, use your windows installation dist to fix the MBR.
Solution 3
Here are the two solutions that have have worked for me.
Boot Linux and make sure you’ve a working Internet connection and type the following on the terminal.
1. Solution
sudo apt-get install syslinux
If the package got installed, use the following command to write the MBR:
sudo dd if=/usr/lib/syslinux/mbr.bin of=/dev/sda
or (depending on the location)
sudo dd if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sda
2. Solution
sudo apt-get install mbr
If the package got installed use following to write the MBR.
sudo install-mbr -i n -p D -t 0 /dev/sda
Common for both
Replace sda if you want to install the MBR to a different drive. Do not put sda1
,sda2
, or sda3
. Just put it as sda
for the hard disk. Finally reboot and your Windows should boot.
Related videos on Youtube
kova
Updated on September 18, 2022Comments
-
kova over 1 year
I'm trying to fix the MBR using Ubuntu live CD. I already have the ms-sys installed but from the threads that I saw, I'm not completely sure in which /dev I should execute the command:
sudo ms-sys --mbr7 /dev/???
(is it mbr7 the correct option when using Windows 7?)
ubuntu@ubuntu:~$ sudo fdisk -l Disk /dev/sda: 320.1 GB, 320072933376 bytes 255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x1f205b1f Device Boot Start End Blocks Id System /dev/sda1 * 38 38 0 0 Empty /dev/sda2 * 2048 206847 102400 7 HPFS/NTFS/exFAT /dev/sda3 206848 155854847 77824000 7 HPFS/NTFS/exFAT /dev/sda4 155854848 625137663 234641408 7 HPFS/NTFS/exFAT ubuntu@ubuntu:~$
Why is
/dev/sda1
empty?I'm trying to fix the MBR because I'm getting a black screen when trying to load the operating system.
-
Rabbi Kaii over 9 yearsBG-Rescue Linux also has LILO and is only 4 MB
-
Pavel Vlasov about 5 yearsWill
dd
erase the wholesda
disk? -
Pouria Moosavi about 4 yearsfor me it was
sudo dd if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sda