[ale] replacing disk sda

Derek Atkins warlord at MIT.EDU
Wed Apr 23 13:48:12 EDT 2014


Paul Cartwright <pbcartwright at gmail.com> writes:

>         then I guess I misunderstood what is in an MBR:)
>         there is nothing there about grub, or what OSes can be booted, just
>         the partition start/end/sizes.. I guess I'm getting edumacated:)
>         where does the grub info go in the MBR??
>
>     GRUB is a boot loader and is in your /boot directory (/boot/grub/).
>    
>     From what little I remember, your MBR just lists the device, starting
>     point, number of sectors, partition type, and whether it is bootable.  It
>     doesn't include logical partitions as they are described within the
>     extended partition.
>    
>     So your MBR just tells your machine to look at the bootable partition and
>     from there GRUB takes over.

Sorry, but you're only partly right.  The MBR (Master Boot Record)
contains not just the partition table but also a small piece of code
that gets loaded by the BIOS that gets used to boot the boot loader.  To
simplify the boot process:

* BIOS loads MBR (which includes the partition table)
* MBR code then loads the boot loader
* boot loader does its thing

When you run "grub-install" it installs itself into the MBR (stage1),
which is set to load stage-1.5 which then loads stage2.  Generally you
can move stage2 around in the file system because stage1.5 knows how to
read the filesystem.  However if you move stage1.5 around then you need
to reset the MBR to point to it properly.

What the script (removed from the quoting above) does is backup your
partition table.  It is *NOT* backing up the MBR.  If you want to
actually back up the MBR you should do it with dd:

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

Restoring the MBR from this is easy... but it only works if you've
restored the rest of the disk from a sector-by-sector copy.  Your other
option is to restore the partition table, rebuild your filesystems,
restore your data, and then re-install the boot loader into the MBR.

> well that sorta makes sense, except mine shows:
>
> /dev/sda1 : start=       63, size=    80262, Id=de
> /dev/sda2 : start=    81920, size= 30191616, Id= 7, bootable
> /dev/sda3 : start= 30273536, size=1595568128, Id= 7
>
> and my windows 7 is sda3. sda2 is the dell recovery partition.. sdb shows no
> bootable partitions, yet I have 2 linux OS partitions..

The only reason you need a 'bootable' partition is because some OSes
(like Windows) have the MBR boot the "Boot Sector" off the bootable
partition..  So you can change which install of windows gets booted by
changing out the bootable partition.

Grub may or may not necessarily need this, which is why you don't
necessarily need "bootable" partitions on /dev/sdb.  Grub is on /dev/sda.

Hope this helps clear up any confusion,

-derek

-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available


More information about the Ale mailing list