Page 1 of 2 12 LastLast
Results 1 to 10 of 41

Thread: HOW TO: Backup and clear MBR (uninstall GRUB)

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Location
    Huntsville, AL, USA
    Beans
    7,526
    Distro
    Ubuntu

    HOW TO: Backup and clear MBR (uninstall GRUB)

    Try at your own risk.
    WARNING: The following commands can easily wipe out your entire hard drive if you are not very careful (make a typo). Please make sure you have everything backed up before proceeding.

    If you happen to be one of several people that somehow end up with two different icons in rEFIt that boot GRUB for Ubuntu, then this will show you how to remove one of them.

    Background
    The issue is that the Ubuntu installer by default installs GRUB to the MBR of the Hard Drive. This is OK for most PCs as this will make it easiest to dual-boot with Windows. On Macs, however, We usually use rEFIt or Hold the Option Key at startup to select which partition to boot from, and having GRUB in the MBR means that you have to use both rEFIt and GRUB to get to windows (for a triple-boot), so most guides tend to install GRUB to the Ubuntu partition and that is OK, but with the advent of a installer bug. The MBR becomes corrupted and many users unknowingly reinstall GRUB to the Ubuntu partition after it has already been installed to the MBR, and thus you get two instances of GRUB to boot.

    Before we begin, it is a good idea to make sure that refit is installed and working so that you can access its tools in the boot menu if needed.

    Now, the Good Stuff
    Before you do any of the following, make a backup of the entire MBR and save it to a thumbdrive or other external media so that you can restore it from a LiveCD if anything goes wrong.
    Do this by opening a terminal and running:
    Code:
    sudo dd if=/dev/sda of=/home/username/mbr_backup bs=512 count=1
    replace "username" with your Ubuntu username. This will create the file "mbr_backup" in your home folder. Copy this somewhere safe where you can get to it if you are left with an unbootable machine!

    Now we will write over your current MBR with a new dummy version that has no real information in it, but will still allow you to boot your system. Download the "fakembr80.txt" file attached to this post (thanks pxwpxw) to your home folder.

    Now we will right the binary contents of this file to your MBR:
    Code:
    sudo dd if=/home/username/fakembr80.txt of=/dev/sda bs=512 count=1
    You should get output that looks like:
    Code:
    1+0 records in
    1+0 records out
    512 bytes transferred in 0.350948 secs (1459 bytes/sec)
    If you don't, try this procedure from the Ubuntu LiveCD (no need to backup again).

    If you have issues after clearing a portion of the MBR. This command shows you how to restore it from the backup file that you made:
    Code:
    sudo dd if=/home/username/mbr_backup of=/dev/sda bs=512 count=1
    Anytime you write to your MBR, you should resync the partition tables. You can do this with rEFIt's "Partition Tool" in the main rEFIt boot menu or you can use the gptsync utility in Ubuntu:
    Code:
    sudo apt-get install refit
    sudo gptsync
    Attached Files Attached Files
    Last edited by cyberdork33; December 16th, 2008 at 04:31 PM.

  2. #2
    Join Date
    Apr 2008
    Beans
    3,317
    Distro
    Kubuntu 9.10 Karmic Koala

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    ssudo
    Is this a Mac command or a typo?

  3. #3
    Join Date
    Aug 2005
    Location
    Huntsville, AL, USA
    Beans
    7,526
    Distro
    Ubuntu

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    Quote Originally Posted by meierfra. View Post
    Is this a Mac command or a typo?
    typo... and fixed. Thanks.

  4. #4
    Join Date
    Dec 2006
    Beans
    44

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    Hi, your help is very appreciated, I think you're a great reference concerning the implementation of Ubuntu on Mac. In respect to this issue, maybe it's a good idea to specify that in the first post aren't described a series of steps to follow, rather they are alternatives the user can choose, except the first one which is mandatory. Greetings.

  5. #5
    Join Date
    Dec 2006
    Beans
    44

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    And I should add that the first post works! at least in a Mac Pro 1 (four Xeon nuclei, Nvidia card and Leopard 10.5.3). Thanks once more for your help.

  6. #6
    Join Date
    Feb 2006
    Beans
    13

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    a question for understanding: how can i resync with refit when the mbr is gone? i mean, can the system start refit after deleting the entire mbr? and what use does the backup copy have when i kill the entire mbr? how will you be able to access this backup then? i like the idea, but does it really work?
    Last edited by umbrAtrorum; July 4th, 2008 at 11:01 AM.

  7. #7
    Join Date
    Oct 2005
    Beans
    31
    Distro
    Dapper Drake Testing/

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    Quote Originally Posted by cyberdork33 View Post
    Try at your own risk.

    If you happen to be one of several people that somehow end up with two different icons in rEFIt that boot GRUB for Ubuntu, then this will show you how to remove one of them.

    Background
    The issue is that the Ubuntu installer by default installs GRUB to the MBR of the Hard Drive. This is OK for most PCs as this will make it easiest to dual-boot with Windows. On Macs, however, We usually use rEFIt or Hold the Option Key at startup to select which partition to boot from, and having GRUB in the MBR means that you have to use both rEFIt and GRUB to get to windows (for a triple-boot), so most guides tend to install GRUB to the Ubuntu partition and that is OK, but with the advent of a installer bug. The MBR becomes corrupted and many users unknowingly reinstall GRUB to the Ubuntu partition after it has already been installed to the MBR, and thus you get two instances of GRUB to boot.

    WARNING: The following commands can easily wipe out your entire hard drive if you are not very careful (make a typo). Please make sure you have everything backed up before proceeding.

    Now, the Good Stuff

    Before you do any of the following, make a backup of the entire MBR:

    Code:
    sudo dd if=/dev/sda of=/home/username/mbr_backup bs=512 count=1
    Now complete the appropriate step below to clear the portion of the MBR you need.

    In order to Clear out the MBR except the partition table (Literally, write zeros over the current MBR contents):
    Code:
    sudo dd if=/dev/zero of=/dev/sda bs=446 count=1
    To clear the complete MBR, including the partition table (On a Mac, the partition table can be recovered by syncing your partition tables with rEFIt):
    Code:
    sudo dd if=/dev/zero of=/dev/sda bs=512 count=1
    If you have issues after clearing a portion of the MBR. These commands show you how to restore it.
    To restore only the Bootsector (not including the partition table):
    Code:
    sudo dd if=/home/username/mbr_backup of=/dev/sda bs=446 count=1
    To restore the entire MBR:
    Code:
    sudo dd if=/home/username/mbr_backup of=/dev/sda bs=512 count=1
    I've ended up with not being able to read /dev/sda after clearing the MBR. I've tried running from Ubuntu LiveCD. Is there a way to restore my MBR, or do I have to reinstall OSX and Ubuntu?
    Haakon

  8. #8
    pxwpxw's Avatar
    pxwpxw is offline Chocolate Ubuntu Mocha Blend
    Join Date
    Apr 2006
    Beans
    Hidden!
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    Quote Originally Posted by stillingen View Post
    I've ended up with not being able to read /dev/sda after clearing the MBR. I've tried running from Ubuntu LiveCD. Is there a way to restore my MBR, or do I have to reinstall OSX and Ubuntu?
    If the problem is an unusable MBR sector on sda, there is a procedure which may fix that.
    It was done using Macosx, but can be done from a Ubuntu live cd.
    It just writes a fake MBR to allow the refit partition tool to resync the MBR.
    You can then install the refit package and run gptsync from the Live CD.

    You first need to check the state of the sda MBR sector by doing a hexdump to see if this applies to you, it may not.

    There is a record of a succesful fix using my posts in these links, you need to read around these posts for the full story..

    Re: 8.04 cleared the MBR partition table
    http://ubuntuforums.org/showpost.php...5&postcount=24

    http://ubuntuforums.org/showpost.php...8&postcount=30
    (attached dummymbr.txt)

    http://ubuntuforums.org/showpost.php...0&postcount=37

  9. #9
    Join Date
    Aug 2005
    Location
    Huntsville, AL, USA
    Beans
    7,526
    Distro
    Ubuntu

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    My procedure seems to have stopped working appropriately very recently. I will modify the original post.

    Which command did you run?

    If you created a backup of the MBR (as indicated in the original post) you should be able to restore it as instructed from the LiveCD.

    pxwpxw, What should be modified (if anything) in the original commands so that this does not occur?

  10. #10
    pxwpxw's Avatar
    pxwpxw is offline Chocolate Ubuntu Mocha Blend
    Join Date
    Apr 2006
    Beans
    Hidden!
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: HOW TO: Backup and clear MBR (uninstall GRUB)

    Quote Originally Posted by cyberdork33 View Post
    My procedure seems to have stopped working appropriately very recently. I will modify the original post.

    pxwpxw, What should be modified (if anything) in the original commands so that this does not occur?
    I would just delete reference to clearing the 512 bytes, it makes it unbootable and gptsync refuses to sync it.
    http://ubuntuforums.org/showpost.php...17&postcount=3

    There does not seem to be a need to clear all the MBR partition table unless entries are garbled and stop gptsync from correcting ( message ' suspicious ... not touching that ' ).

    If there is a need, clear 510 bytes leaving the dos mbr signature 55AA, which still wont boot, but gptsync will correct it.
    Preferable to use the 512 byte dummymbr, or 'fakembr' - it clears it but makes it bootable by making a valid entry (doesn't seem to require the correct size, just the valid entry format).
    Might be and idea to attach a fake mbr in the thread for insurance.
    And advise to check with hexdump first.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •