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!
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
Thanks Michael!
Very useful post, like so many here. Thanks for putting together a great Ubuntu blog. 🙂
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.
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 …
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… 😉
Nevermind, the last two bytes of the MBR are always a constant, so it is 446…
disregard previous post!
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.
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?
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.
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…
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 ?!
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
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
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,
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/
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.
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.
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
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?
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
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
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
[…] Figure out how to fix Lilo/Grub when I break it with the Win install. [see here] […]
i think this guide is a lot clearer
http://johnny.chadda.se/2007/02/17/restore-grub-in-ubuntu-after-installing-windows/
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!
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.
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
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…
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
[…] 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 […]
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.
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.
sir,
how can i take a backup mbr in windows and how can i restore
[…] https://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. […]
[…] 1. Back-up MBR Method One […]
[…] 1. Backup MBR Method One […]
thnXxss
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.
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
thanks nice blog
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.
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.
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
thanks so mucn all admin
[…] Backing Up the MBR « Ubuntu Blog […]
Thank you for the opportunity you gave
thanks so mucn all admin
blog channel show
simple year escort in nera.
blog obi year noo
gay invile post chen
disregard previous post!
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…
blog obi year noo
gooday thank you
gooday thank you…
antalya ev ilaçlama
Worked fine for me, thank you
thanks for this useless post
süper sikişme
sikisportali.com sikişin adresi
The star singer, Lady GaGa has gone traveling in various regions of the world, doing performances on Tv shows shows, and additionally performing
thanks for your post can come in useful
star singer, Lady GaGa has gone traveling in various regions of the world, doing performances on Tv shows shows, and additionally performing
star singer, Lady GaGa has gone traveling in various regions of the world, doing performances on Tv shows shows, and additionally
ankara travesti ceren
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!
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.
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.
Very nice write-up. I definitely love this site. Keep
it up!
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!
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!
What a stuff of un-ambiguity and preserveness of precious knowledge about unpredicted emotions.
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.
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.
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.
Thiѕ is a topic thɑtt is closе to my heart… Cheers!
Where are youг contact details though?
ces d賡ils
Backing Up the MBR | Ubuntu Blog
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!
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?
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!
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!
best weight gainer for skinny men
Backing Up the MBR | Ubuntu Blog
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.
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.
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.
Thanks forr sharing your thoughts on latest nokia phones. Regards
Greetings from Ohio! I’m bored to tears at work so I decided to browse your blog on my iphone during lunch break.
I enjoy the knowledge you provide here and can’t wait
to take a look when I get home. I’m amazed at how fast your
blog loaded on my cell phone .. I’m not even using WIFI, just 3G ..
Anyways, awesome site!
I was recommended this blog by way of my cousin. I am now not positive whether this put up is written by means of him
as nobody else understand such distinct approximately
my difficulty. You are incredible! Thanks!
It’s nearly impossible to find educated people in this particular topic, however, you sound like you
know what you’re talking about! Thanks
Hey there, You’ve done an incredible job. I’ll certainly digg it
and personally suggest to my friends. I’m sure they’ll be benefited from this website.
Does your website have a contact page? I’m having a tough time locating it
but, I’d like to shoot you an email. I’ve gott
some ideas for your blog you might be interested
in hearing. Either way,great website and I look forward to seeing
it expand over time.
Hey I know this is off topic but I was wondering if
you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
I’ve been looking for a plug-in like this for quite some time
and was hoping maybe you would have some experience with something like this.
Please let me know if you run into anything. I truly enjoy reading your blog and I look forward
to your new updates.
Howdy, I do believe your site may bee having internet browser
compatibility issues. When I look at your web site in Safari, it looks fine but
when opening in IE, it’s ggot some overlapping issues. I simply wanted to
provide you with a quick heads up! Apart from
that, great website!
of course like your web-site but you need to test the spelling on quite a
few of your posts. Several of them are rife with
spelling issues and I find it very bothersome to inform the truth nevertheless I will surely come again again.
Undeniably consider that that you said. Your favorite justification appeared to be at the
internet the simplest factor to be mindful of. I say to you,
I certainly get irked whilst other folks consider issues that they
plainly do not recognize about. You managed to hit the
nail upon the top and defined out the entire thing without having side-effects , folks can take
a signal. Will likely be back to get more. Thank
you
Hello, I want to subscribe for this website to obtain newest updates,
therefore where can i do it please assist.
Thanks for one’s marvelous posting! I seriously enjoyed
reading it, you’re a great author. I will remember to bookmark your blog and will often come back from now on. I want to encourage you to definitely continue your great posts, have a nice morning!
Do you approve if I quote a few of your content articles as long as I give credit score and sources back to your web site? My website is in the really same location of interest as yours and my site visitors would surely advantage from some of the data you existing right here. Please allow me know if this okay with you. Cheers!
Google’da ararken konunuzu buldum makaleleriniz ilgimi çekti teşekkürler
Hi there mates, its impressive piece of writing on the topic of educationand completely
explained, keep it up all the time. https://lilisharyantoliardia.wordpress.com sukses mantap
That is a really good tip particularly to those fresh to the blogosphere.
Brief but very accurate info… Thanks for
sharing this one. A must read post!