jump to navigation

Backing Up the MBR October 20, 2005

Posted by Carthik in guides, ubuntu.
trackback

I found myself in the situation of helping a friend reinstall windows on a system which also has Ubuntu on it. In other words, it was a dual boot system, and we were both afraid that re-installing Windows will overwrite the Master Boot Record (MBR) and make it impossible to boot into Ubuntu in the short term. So we devised a plan, with a little help from google to backup his MBR before reinstalling windows, and then restoring it after reinstalling windows.

Create a backup of your MBR by doing a:

$dd if=/dev/hdx of=MBR-backup bs=512 count=1

That should read “create a disk dump of the input file, which is /dev/hdx (change to hda, or hdb or sda, depending on where the MBR is on your computer), and save it in the output-file MBR-backup in the directory from where the command is issued. Backup the first sector only, while you are at it”.

Now that is the backup of your MBR. Restore it later using:

$dd if=MBR-backup of=/dev/hdx bs=512 count=1

Again, change hdx to hda, or hdb or wherever the MBR needs to be restored to. You may have to use a live cd to restore the backup since you will be unable to login to Linux after you reinstall Windows.

As with all other advice, take this with a pinch of salt, and search on google for a solution to your problem, understand the solution and then embark on your mission!

Comments»

1. Michael Manning - October 20, 2005

If you are going to need to use a Live CD to recover the backup MBR then you could have booted into rescue mode from the install CD (of any linux distro you choose) and mounted the linux partition, chrooted to the root partition and typed grub-install /dev/hdx.

mkdir /mnt/temp
mount /dev/hda3 /mnt/temp ## if hda3 was the linux partition
chroot /mnt/temp
grub-install /dev/hda

That would install the grub first stage boot loader to you the MBR of the hard disk and presented you with the same options you had before the Windows reinstall. no need for backup MBR records!

Just my two bobs worth – there is always more than one way to skin a cat.
Michael Manning

2. ubuntonista - October 20, 2005

Thanks Michael!

3. zenith - October 20, 2005

Very useful post, like so many here. Thanks for putting together a great Ubuntu blog. :)

4. Jason - October 20, 2005

Note that the grub-install method has the added protection of not inadvertantly overwriting your partition table if it had been modified since your last MBR backup.

This is because the 512byte MBR sector is actually two parts:
1) The first 446 bytes is the grub stage1 bootloader (or the windows bootloader after you’ve reinstalled windows and it “helpfully” overwrites grub).
2) The last 64 bytes is where your partition table is stored.

So, if you only want to backup the bootloader in the MBR, remember to change the bs=512 to bs=446.

5. kOoLiNuS - October 21, 2005

this is one of the “problems” of the single disk ubuntu … they actually don’t have a real rescue mode so you need a live-cd or another distro 1st cd …

they know it, since there are some posts on this subject dated some month ago in the archives …

6. Anonymous Coward - October 30, 2005

If you are only going to backup the bootloader section of the MBR, please do it right and use 448 in the “bs” parameter (since 512 – 64 = 448, not 446).

So, the command would be something like,
$dd if=MBR-backup of=/dev/hdx bs=448 count=1

This is one of those times where those two little bytes DO matter… ;-)

7. Anonymous Coward - October 30, 2005

Nevermind, the last two bytes of the MBR are always a constant, so it is 446…

disregard previous post!

8. Adam Dorsey - November 11, 2005

Actually, there is a way to do this with the standard Ubuntu CD:

1) Go through the installer as normal. However, when it gets to the screen asking for options for partitioning, STOP. Don’t go any further or you are likely to screw Ubuntu (at least).

2) Press ALT+F2. It’ll bring up a command line, press Enter to activate it if it asks.

3) Make sure you are in the root of the filesystem.
# cd /

4) Make a directory to mount your hard drive in.
# mkdir target

5) Mount your Ubuntu partition to the directory.
# mount /dev/hdax /target
where hdax is your Ubuntu partition (hda1 for those that run Ubuntu only, likely hda2 for those of us that dual-boot, possibly sdax for SATA/SCSI/RAID/etc.)

6) Change the root directory to your hard drive.
# chroot /target

7) Reinstall grub.
# grub-install /dev/hdax

8) Reboot. If everything goes well, you should be good to go.

9. foolosophy - December 26, 2005

I can’t re-install my Windows2000. I have a hda1 partition of 10GB (fat32) free, and Ubuntu in other three partitions. GRUB is installed on the MBR and the /boot partition.

Even if I do a “fdisk /mbr” command before installing Win2k, after copying the files from the CD-ROM to the hard-drive, the windows installer won’t boot. With, or without grub, it doesn’t work. What can I do?

10. Anonymous - December 28, 2005

Ubuntu 5.10 has a rescue function which is very helpful after the reinstallation of windows.
1. Use the Ubuntu 5.10 installation CD to boot the computer.
2. Under “boot:” type rescue.
3. Wait the screen to bring up a list of all the partitions.
4. Choose the Ubuntu partition.
5. A command line will pop up.
6. Type grub-install /dev/hda.
7. Reboot.

11. Jesus Escolar - December 29, 2005

Hi,
I have the same problem. I’ve installed Windows before Ubuntu, and now I’m stuck because i get a message in the screen that is very annoying:
something about a bug in xfs_freeze and stops the installation telling me that because /boot/grub is not an XFS filesystem it cannot continue the installation…

My configuration is:
one HDD:
hda1 linux
hda2 windows xp
hda3 linux
hda5 linux

No linux MBR, only windows MBR and it works.

Please help me to know what means this…

12. _DeXteR_ - January 3, 2006

me restart computer and mount HDD
not mounted…. :((((((
i don’t know :(((
D partition Empyt not mounted C not mounted… :(

fucking restart

this is a command maybe don’t know pls help

\etc\rc.d\rc.local /dev/hda3 /mnt/temp ## if hda3 was the linux partition
and computer start this command start ?!

13. Arno - March 8, 2006

Their is a dirty way of doing this:
http://doc.gwos.org/index.php/Restore_Grub

Just make some faults in installeren when mounting the harddrives and skip all steps to GRUB and then just reboot!

Worked fine for me :)

Arno

14. Carundi - July 21, 2006

I’ve also found another way, as the previous didn’t work for me…
With your solution I got:

root@ubuntu:/# grub-install /dev/hda1
/dev/hda1: Not found or not a block device.
root@ubuntu:/# grub-install /dev/hda
/dev/hda: Not found or not a block device.

So I did following to get it to work:

sudo grub // Start Grub
grub> root (hd0,6) // Partition with the Boot image
grub> setup (hd0) // Install Grub into the MBR
grub> quit

15. Didier - August 12, 2006

Très bonne explication !
J’ai guidé un ami par téléphone, en suivant cette page,
et il y est arrivé.

Merci

Very Good explication
I help a friend by phone, following this page
and he succeed to reinstall Grub

Ubuntu 6.06 LTS

Really Thanks,

16. Miroslav Damjanoski - August 23, 2006

After reinstalling windows, if you have a backup of your MBR, you could use dd for windows instead of using a live cd.
http://www.chrysocome.net/dd
http://unxutils.sourceforge.net/

17. Richard Clark - October 6, 2006

The reason that you get a “Not found or not a block device.” when trying to run grub-install /dev/hdx or sdx is because after you chroot to /mnt/temp, the /dev you are referring to is on your defunct filesystem, therefore it is not active. I just threw Vista on my machine that already had XP and Kubuntu 6.06.1 LTS and after fixing GRUB, it works perfectly. To access either vers. of Windows, I just select the “Microsoft Windows XP Professional” link in GRUB and it actually takes me to Vista’s loader to choose which. Here is my successful procedure:
1. Boot to an available Linux prompt (live CD? Terminal.)
2. Make sure you are root or sudo your commands.
3. (sudo) mkdir /mnt/temp
4. (sudo) mount /dev/hdx (or sdx) /mnt/temp
5. (sudo) grub-install /dev/hdx –root-directory=/mnt/dev/boot/grub
That allows GRUB to access the device, yet it will store its settings and components where you want them, on your linux partition. Hope this helps.

18. Richard Clark - October 6, 2006

Sorry, please note in that last message that line 5 should read:

5.(sudo) grub-install /dev/hdx — root-directory=/mnt/temp/boot/grub

make sure you use two dashes in front of root-directory. They look run together.

19. John - December 11, 2006

This was not written for Ubuntu, but also covers Grub and a Dual Boot scenario. You could use this if you wanted to use a Windows Boot Loader to boot Ubuntu. Obviously change the Fedora references to Ubuntu

http://www.johnspencer.org.uk/LinuxTutorials/DualBoot/dual_booting_windows_xp_and_fedora.htm

20. mohammed - December 28, 2006

wher does fedora 5 saves the mbr of windows ? I suppose that the stage 1 ist in the first 446 bytes of MBR. I actually want to restore the mbr to contain the window loader an start fedora 5 from diskette not from hard disk?

21. Silver Chandrakant - January 5, 2007

Please disregard post 6. Anonymous Coward – October 30, 2005
since the command line written there is incorrect (actually will do a restore of MBR) and can prove FATAL!!!
$dd if=MBR-backup of=/dev/hdx bs=448 count=1

Instead it should be (for backup of MBR)
$dd if=/dev/hdx of=MBR-backup bs=448 count=1

22. Stefan - February 22, 2007

Sorry, please note in that last message that line 5 should read:

5.(sudo) grub-install /dev/hdx — root-directory=/mnt/temp/boot/grub

make sure you use two dashes in front of root-directory. They look run together.

Please note that this is wrong again. The root-directory should be only /mnt/temp and NOT /mnt/temp/boot/grub. So the (succesfull) command is:
(sudo) grub-install /dev/hdx (or sdx) –root-directory=/mnt/temp

23. Vikram - February 23, 2007

Help!
I was running a dual boot machine with Windows XP(my original OS) and Ubuntu 5.10 ( i installed it later) on a 40GB HDD, I also have an old 2GB HDD … all worked well till i added another 40GB HDD, now only ubuntu Boots, when i select the option for windows xp under grub menu at startup i get this:
Booting ‘Microsoft Windows XP Professional’
root(hd0,0)
Filesystem type unknown, partition type 0x7
savedefault
makeactive
chainloader+1

and then two ASCII characters one of them ASCII 212 and the other one a vertical box shaped smiley I cudnt find the ASCII code to…followed by a blinking cursor.

I have not made any changes whatsoever apart from adding the new hard disk, ubuntu shows it under disks.

thanks a ton for having this blog, any help on this is welcome

24. fionnnuala.net thoughts » Windows Reinstall - March 10, 2007

[...] Figure out how to fix Lilo/Grub when I break it with the Win install. [see here] [...]

25. koshari - March 14, 2007
26. Michael - March 18, 2007

For what its worth – thanks for your update on the ways of doing the grub fix… almost sorted the problem out with my FC5.

This is what I did:

Boot FC5 in “linux rescue” mode.
Don’t worry about network interfaces
Click “continue” to mount /mnt/sysimage
DONT do a chroot!
copy grub for /sbin (there seems to be a bug with this one_)
cp /usr/sbin/grub* /sbin
grub-install /dev/sda –root-directory=/mnt/sysimage

reboot – problem fixed!

27. MEW - June 1, 2007

I have grub installed on an external USB hard disk (but it would work just as well on a floppy, cd, or USB thumbdrive). Whenever Windows decides to break grub for me, I just boot grub off the external disk. From there it’s simple:

grub > root (hd1,5) #My Ubuntu root partition; the usb drive is (hd0) because I booted from it
grub > setup(hd1)

And grub works again. It only takes about a minute.

28. Kenny - June 4, 2007

In reply to 14. Carundi – July 21, 2006:

do not forget to empty /etc/mtab or insert relevant rows :)
After this step is funktional command grub-install /dev/xxx

29. Jonathan - June 7, 2007

Chain Load from the start and save the headaches…

Install GAG boot manager to the MBR, before or after, OS installs when ever you need to – if you….

Install Linux’s boot loader “grub” into /boot or / partition, NOT the MBR

Install Windows where ever but setup boot.ini correctly

re-install GAG boot manager if needed etc…

30. ECartman - September 8, 2007

I use and recommend Super Grub, no matter how bad I trashed the mbr I can load the os of my choice (linux) and repair from there

Cart

31. How I installed Windows XP onto an SD card (on my EeePC) « ewolf blog - December 21, 2007

[...] i copied the windows boot sector from the internal SSD to the boot sector of the SD using dd. See here. Then i mounted the SD card’s FAT partition in linux and modified the boot.ini file so it [...]

32. CodeWiZzard - February 24, 2008

nice little tutorial. imo the easiest way to backup the mbr (or any other part of devices) and way more fast and reliable to noobies than chrooting.

33. WindRider2017 - July 6, 2008

Thank you Carundi, your solution for re-creating a new MBR worked great, and I was able to get my new copy of Ubutu booting on my new HD. I use a program called PartImage to do the partition copy and Grub is still a challenge on a new HD, which never had Linux on it before.

34. santosh - July 23, 2008

sir,

how can i take a backup mbr in windows and how can i restore

35. Free Biao » Blog Archive » Ubuntu: grub - December 15, 2008

[...] http://ubuntu.wordpress.com/2005/10/20/backing-up-the-mbr/#comment-204 Note that the grub-install method has the added protection of not inadvertantly overwriting your partition table if it had been modified since your last MBR backup. [...]

36. Clone your Ubuntu machine into abstraction « Indlovu - July 4, 2009

[...] 1. Back-up MBR Method One [...]

37. Clone your Ubuntu machine into abstraction | Indlovu - July 13, 2009

[...] 1. Backup MBR Method One [...]

38. sikiş - July 14, 2009

thnXxss

39. Prefabrik - August 7, 2009

The data presented below were first published after Halloween in 2006, here at The World’s Fair. After further (non-anonymous) peer review, we pushed into the second phase of the research in 2007, as published here. We are proud to acknowledge that these earlier efforts–pilot studies, both–led to further funding. We’ve now been able to pursue the third phase of the work. Difficult work, yes. Labor-intensive, to be sure. Gut-wrenching, perhaps. But huge breakthroughs were in the offing. The hierarchy below includes the results of our continuing work.

40. konteyner - August 10, 2009

For what its worth – thanks for your update on the ways of doing the grub fix… almost sorted the problem out with my FC5.

1) Go through the installer as normal. However, when it gets to the screen asking for options for partitioning, STOP. Don’t go any further or you are likely to screw Ubuntu (at least).,

Thank you embraceubuntu

41. sikiş - November 13, 2009

thanks nice blog

42. Steve - November 23, 2009

Really useful discussion with lots of alternative approaches to a common problem. I’ll pipe in with one more.

1. Keep each OS in its own area. While Linux is flexible about boot locations, Windows variations aren’t, so keep them apart.
a. Let Windows have the MBR & make all of the changes it wants to it.
b. Create a separate partition for Linux’s /boot directory (should be a ‘primary’ partition)
2. Install grub to the Linux /boot partition
3. From Linux (installed on the hd OR rescue disk OR liveCD), as root:
a. df -h shows which partition is mounted as /boot
b. fdisk -l lists drive partitions AND which one has the ‘boot’ flag
c. If the Linux /boot partition has the ‘boot’ flag, skip to step 4. If not, step 3d.
d. parted gets you into the partition editor, then from in parted:
(1) print again, lists partitions AND ‘boot’ flag
(2) toggle NUMBER boot where NUMBER is the current (‘non-Linux’) boot partition
(3) toggle NUMBER boot where NUMBER is now the /boot partition’s number
(4) print verify that the ‘boot’ flag is set where you want it (the /boot partition)
(5) quit gets you out of parted
4. Check your grub.conf file’s content.
a. Make sure the hard disk installation of Linux’s /boot is mounted, then change to the grub directory in that boot directory
b. cat grub.conf (or open it in an editor) make sure both your Linux distro and Windows are listed
c. If all of the op systems you want to access are listed, you are good to go, so reboot & enjoy.
d. If you are missing a system, follow your choice of grub instructions from earlier posts, just remember to install it to your Linux /boot partition.
5. As long as you keep each OS in its own area, updates to Windows or Linux should not cause any problems.

43. escort ilan - January 1, 2010

Just because people didn’t have tea didn’t mean they weren’t drinking boiled drinks– tisanes

and infusions of camomile, linden blossom, and so on. This is a better example of how hard it

is to pin down cause and effect in social science research than it is a scholarly argument.

44. Mike Rofone - January 14, 2010

Cheers man,

backing up MBR and restoring it (with bs=446) worked like a charm while installing Windows 7 onto a partition previously containing Windows XP. Although I activated the bootsector write-protect feature in my BIOS, the installer of 7 just replaced the MBR and so turned off grub. After the installation, I copied back the backup (only the first 446 bytes, thanks Jason!) and there it was again. No glitches, no problems, and no need to adjust the Grub settings. The old “Windows” entry in menu.lst works perfectly! :)

Keep up the good work!
Cheers
Mike Rofone

45. escort bayan - February 26, 2010

thanks so mucn all admin

46. My Diigo bookmarks (weekly) « Oldschool-Abschluss - March 2, 2010

[...] Backing Up the MBR « Ubuntu Blog [...]

47. Sağlık Bilgilendirme portalı - April 2, 2010

Thank you for the opportunity you gave

48. bolu - June 28, 2010

thanks so mucn all admin

49. travesti - June 28, 2010

blog channel show

50. travesti - June 29, 2010

simple year escort in nera.

51. travesti - June 29, 2010

blog obi year noo

52. travesti - June 29, 2010

gay invile post chen

53. porno sikiş - September 27, 2010

disregard previous post!

54. sex sikiş - September 28, 2010

I have the same problem. I’ve installed Windows before Ubuntu, and now I’m stuck because i get a message in the screen that is very annoying:
something about a bug in xfs_freeze and stops the installation telling me that because /boot/grub is not an XFS filesystem it cannot continue the installation…

55. Nod32 Güncel Serial Key - November 27, 2010

blog obi year noo

56. travesti - March 8, 2011

gooday thank you

57. travesti - March 8, 2011

gooday thank you…

58. antalya böcek ilaçlama - August 7, 2011

antalya ev ilaçlama

59. рецепти - August 24, 2011

Worked fine for me, thank you

60. sikiş - August 29, 2011

thanks for this useless post

61. türk porno - August 29, 2011

süper sikişme

62. sikiş - August 29, 2011

sikisportali.com sikişin adresi

63. Shay Winningham - September 14, 2011

The star singer, Lady GaGa has gone traveling in various regions of the world, doing performances on Tv shows shows, and additionally performing

64. michaelmarks - November 25, 2011

thanks for your post can come in useful

65. ankara travestileri - March 27, 2012

star singer, Lady GaGa has gone traveling in various regions of the world, doing performances on Tv shows shows, and additionally performing

66. ankara travestileri - April 3, 2012

star singer, Lady GaGa has gone traveling in various regions of the world, doing performances on Tv shows shows, and additionally

67. ankara travestileri - April 3, 2012

ankara travesti ceren

68. landscape gardening quotes - August 15, 2013

Wow that was odd. I just wrote an extremely long comment
but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing
all that over again. Anyways, just wanted to say excellent blog!

69. dual-cyclonic vaccum cleaner - October 17, 2013

When the tape is full of hair simply throw away and start over if needed.
This assists you to save costs on bags and also this is also ideal for people who are battling allergies and other respiratory problems.
Contributions include not only a value for time, small investment, intellectual property, equipment and supplies,
but also a premium for risk given the likelihood
individuals may not get paid.

70. b& - March 26, 2014

I’ve been surfing online more than 3 hours today, yet I never found any interesting article like
yours. It’s pretty worth enough for me. Personally, if all webmasters and bloggers
made good content as you did, the internet will be much more useful than ever
before.

71. Moving Company Info - March 28, 2014

Very nice write-up. I definitely love this site. Keep
it up!

72. teen sex live cam - March 30, 2014

This is very interesting, You’re a very skilled blogger.
I have joined your feed and look forward to seeking more of your magnificent post.
Also, I have shared your website in my social networks!

73. hotel - April 4, 2014

I really love your blog.. Very nice colors & theme.
Did you develop this site yourself? Please reply back as I’m trying to create my own site and would like
to know where you got this from or what the theme is named.
Kudos!

74. health benefits - April 10, 2014

What a stuff of un-ambiguity and preserveness of precious knowledge about unpredicted emotions.

75. damp proofing Sunderland - April 18, 2014

If you would like to improve your know-how only keep visiting this web page and be updated with the most recent gossip posted here.

76. barmekin.co.uk - April 25, 2014

Of all domesticated animals, dogs are the most loyal and loving of
all. From this designer, you’ll find classic polo shirts
with embroidered designs, simple yet fun tank tops and tennis dresses, and sweaters in
both classic and playful colors, including the luxurious heathered cashmere sweaters.
This article has been flagged as spam, if you
think this is an error please contact us.

77. vitamin d sources - May 6, 2014

The good news is that this type of deficiency is
an easy thing to fix. Then, at a routine doctor’s appointment, I happened
to casually mention the constant muscle and joint aches, exhaustion,
and headaches. The milestones of development such as walking
and teething are delayed.

78. www.netsoftcompany.com - May 16, 2014

Thiѕ is a topic thɑtt is closе to my heart… Cheers!
Where are youг contact details though?

79. ces d賡ils - May 22, 2014

ces d賡ils

Backing Up the MBR | Ubuntu Blog

80. accommodation belgrade - May 26, 2014

I do not even know how I ended up here, but I thought this post was good.
I do not know who you are but definitely you’re going to a
famous blogger if you aren’t already ;) Cheers!

81. pakaian - June 1, 2014

Tremendous things here. I am very glad to peer your post.

Thank you so much and I’m taking a look ahead to touch you.
Will you please drop me a e-mail?

82. basement renovation costs brampton - June 3, 2014

Hey there would you mind sharing which blog platform you’re working with?
I’m going to start my own blog soon but I’m having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.

The reason I ask is because your design seems different then most blogs and I’m
looking for something unique. P.S Apologies for being off-topic but I had to ask!

83. site - June 11, 2014

Excellent blog! Do you have any tips and hints for aspiring
writers? I’m planning to start my own website soon but I’m a little lost
on everything. Would you suggest starting with a free
platform like WordPress or go for a paid option? There are so many
choices out there that I’m completely confused .. Any tips?
Bless you!

84. best weight gainer for skinny men - June 12, 2014

best weight gainer for skinny men

Backing Up the MBR | Ubuntu Blog

85. Frank Kern - June 18, 2014

As a result, he has become extremely successful over the last several years.
An example of such strategy would be to dominate the search results
from Google, build some links, find some highly profitable niches, extract
lots of commission, and attract lots of traffic from different search
engines. • Once stored, can be taken to anywhere, anytime and
in any number to be accessed as per the need.

86. oostende - June 19, 2014

The World Wide Web is an important marketing medium and to gain success in this arena a marketer should have well
planned online marketing strategy. Before engaging an online marketing consultant therefore,
make sure they have all of these skills and more, in order
for them to offer you a great value proposition. On the
other hand, someone driving a car who sees a billboard, will at best be interested and might decide to get more information at some time.

87. Scott - July 24, 2014

No matter if some one searches for his necessary thing, so he/she needs to be available that in detail,
so that thing is maintained over here.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 518 other followers

%d bloggers like this: