Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an Ubuntu OS installed on my laptop. I want to install Windows 7 as well to another disk partition (I will do it by recovering it from a special partition on my laptop).

After installing Windows, I want to recover my hard drive MBR to be able to load Ubuntu. I have a plan to use linux dd program:

1) (Before installing, perform this command in Linux) dd if=/dev/sda of=/home/user/mbr_backup bs=512 count=1

2) (after installing, load Ubuntu Live CD and launch this) dd if=/home/user/mbr_backup of=/dev/sda bs=512 count=1

3) Load Ubuntu on PC and re-configure the GRUB2 to be able start Windows

I need your advice, I want to be sure I won't damage the disk (it's partition table).

share|improve this question

migrated from stackoverflow.com Sep 16 '12 at 7:14

This question came from our site for professional and enthusiast programmers.

1  
Why not just reinstall the bootloader from your live CD? –  nneonneo Sep 16 '12 at 6:30
    
There're several steps, I don't remember them. –  Graduate Sep 16 '12 at 6:31
    
    
Thanks, but at least, say me, will my method work, I need to know this for the future. –  Graduate Sep 16 '12 at 6:33
    
Yes, unless you partition (or potentially format) your drives at some point during the Windows install. This may not work if your partition configuration changes between the backup and restore. –  nneonneo Sep 16 '12 at 6:37

3 Answers 3

up vote 2 down vote accepted

You are correct that the first 512 bytes of the drive contains the MBR and your method will restore it to the previous state but that is probably not the best course of action. Ubuntu should leave your MBR intact. As long as the partition table is still good and you can still see your partitions, just install grub as a bootloader. If you are using a modern Ubuntu version than you will probably have grub 2 which is great, it automatically detects Windows partitions and adds them to your grub list. Just run update-grub2. If you didn't install a boot loader with Ubuntu it might be a bit harder. Something like this would help.

share|improve this answer
1  
To emphasize: the MBR contains not only boot code, but also the partition table of the drive. DO NOT tamper with it unless you know EXACTLY what you're doing. For instance, if you changed the partition layout during setup, restoring the MBR after installation would render the system unusable. Any self-respecting boot manager (like GRUB or even LILO) will update the boot code in the MBR for you. Ubuntu even has documentation for the OP's scenario. –  Ansgar Wiechers Sep 16 '12 at 10:58

First you must use fdisk to be sure that you will save the right MBR from the right hard disk specially if you are using two or more hard drives

second you must make a backup for your hard drives and if you can make clone to another hard drive that will be better [you can use dd to make that but it talk time ]

third save your MBR backup and Backup at safe place like external hard drive or a USB Flash or another Internal hard drive or another safe partition (not recommended )

fourth use dd and save MBR to an .img file like mbrBackup.img

share|improve this answer
  1. The special partition--if it still exists after the prior Ubuntu install--is on your hard drive. you need to not destroy it in partitioning. From Ubuntu, use sudo sfdisk -l to see what partitions are on the drive.
  2. Most windows versions do not play well if they are not the first partition [other than the special partition] on the hard drive.
  3. If you want to save your current Ubuntu system, use tar to back it up to an external drive. If it is a LVM Ubuntu install, that might be a bit difficult, as accessing the LVs to back them up might require mounting the LVs separately while booted off a Ubuntu CD or boot stick, then using tar to back them up, and later recreating the LV structure after the Windows7 install to do the tar reinstall. Do not tar a running linux OS from the OS itself, you need to boot off a CD or flash boot stick to back up the cleanly shutdown linux OS. Alternatively, you may be able to resize a LVM linux partition down to the smaller size and then use dd on that partition to back it up to an external drive. Alternatively LVM may be smart enough to be able to migrate the whole Ubuntu install to a separate drive, and later migrate it back--so study LVM if your Ubuntu install is on a LVM partition and you want to save it.
  4. When you have saved your Ubuntu install--if you wish to save it, you may optionally delete the Ubuntu partition (and all others except the special partition). Make sure you delete the right ones.
  5. Invoke the windows7 restore on the laptop--if the hidden partition still exists.
  6. Now you have an original Windows7 laptop, with windows where it wants to be. Download the Windows Ubuntu partitioner tool and chop the end off the Windows partition to allow space for Ubuntu and your other partition.
  7. Now either install a new Ubuntu as the second OS on the disk, or use tar (and LVM) or dd or LVM migrate to recover your old Ubuntu install.
  8. As noted above, if you are recovering your prior Ubuntu install, you will need to manually install grub (earlier Ubuntu) or grub2 (later Ubuntu) on the MBR in a way that plays nice with Windows7 in order to be able to dual boot.

The technique for original grub(1) is given here , but later versions of Ubuntu use grub2.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.