MBR Page
Edited Friday, February 05 2010

            
This web-page is part of a larger site giving examples of how to install Windows+Ubuntu Linux operating systems 'dual boot' in a computer.  Illustrated Dual Boot HomePage


PAGE INDEX

Hard Disk Information - for beginners

What is the MBR?.

What are 'boot sectors'?.

What is the 'IPL' for the boot loader?.

What does an IPL really look like?.

What does the IPL for a bootloader do?.

What does a Partition Table really look like?.

Is the MBR part of the Windows file system (Partition)?.

Can a bootloader's IPL be installed to a partition?.

The partition table and partition numbering.

Managing My Partitions with GParted.

A Birds's eye view of Windows XP... showing the important files needed for booting

Installing a Boot Loader for Ubuntu.

If you choose <Yes> ( to Install GRUB's IPL to MBR)

If you choose <No> ( to Install GRUB's IPL to a custom location)

If you choose <Go Back> ( to Install LILO Boot Loader)

The Ubuntu Installer Main Menu.



WARNING: This web page contains information which is only partially correct

Information that beginners can understand is not technically correct.
Information that is technically correct is difficult for beginners to understand.
(Lao Tzu)

Hard disks, MBRs and boot sectors, disk geometry, partition tables, and file systems are complex technical subjects. The information in this web page is intended to be sufficiently accurate to explain what's happening to someone who wants to install Ubuntu in a computer, and dual boot with some other operating system.  It is beyond the scope of this web page to be technically correct, however I will do as well as I can.  

Care should be taken to check the accuracy of anything in this web page if it will be re-used or quoted for any purpose, (homework, school assignments etc).
This web page contains lots of links to some excellent external websites.
Please accept my apologies for any inconvenience that might be caused by any omissions or errors and check the other websites for more accurate and detailed information.


   

Hard Disk Information


DSCF0470.png
                        DSCF0470.png
A hard disk.
Viewed from the outside just looks like a metal box with a ribbon cable and some wires plugged into it.

It is not recommended for users to open their own hard drives because even microscopic dust particles will get in it and ruin it.
This one's just an old one that's no good anymore so I have opened it to see what's in it.

DSCF0471.png
 DSCF0471.png
On the inside, there are some shiny round 'platters' on a 'spindle'. The hard disk in this picture has only two platters, but many have more than that, possibly three or four platters.

A small 12 volt electric motor underneath turns the spindle and platters at a very fast speed, about 5400 rpm for an older, slower hard disk and up to as much as 10000 rpm or more for some of the fastest, most modern hard disk drives.
 
The arms above and below each platter hold tiny read/write heads and are controlled by precision electronics.

The tiny read/write heads on the end of the arms float on a thin cushion of air just above the spinning disk surface. The arms pivot around to sweep the read/write heads across the spinning disk platters in search of the data you want. 
    
Hypothetically,
Data on the hard disk platters is written in concentric rings (like growth rings on a tree stump), called 'tracks'. 
        
Tracks are divided up into 'sectors'.
There are  63 sectors per track, so they could be imagined to be a little smaller than one minute on a watch face.
One sector on a hard disk can hold 512 bytes of data.
  
When you read the word 'cylinder' when used in reference to hard disk geometry, it means an imaginary cylinder connecting all  the tracks (rings) that are the same size on both the top and bottom of each platter for all the platters in the hard disk.

Now, please click on the following link to a great website whose author has done an excellent job of illustrating and explaining sectors, tracks, cylinders and heads, Disk Geometry   - Elementary Computer Mathematics by Kenneth R. Koehler.
Don't forget to come back to this page when you are finished, in case you start getting interested in the rest of that website!

From here on, things get more and more and more complicated. Are you ready? ...

By now you should know a little bit about what is called 'Disk Geometry', but now I have to tell you there is actually a lot more to it than that.

In Reality, fake disc geometry,
to use all the space in a hard disk properly, it would be just plain silly to have only 63 sectors in the outside tracks and 63 sectors in the inside tracks.
As anyone can imagine, the sectors in the outside tracks would be much bigger than the sectors in the inside tracks, so why not divide up the outside track into smaller sectors too, and make better use of the available space in the hard disk?
Well, that's exactly what happens, and a lot more besides, which results in lots of fancy mathematics and complicated electronic trickery until we end up with 'fake disc geometry'.
The user and the operating system is tricked into believing there are 63 sectors per track, and so on. What is really inside the hard disk is something much more complicated.
The hard disk has firmware in a special electronic card underneath it to translate the real disk geometry into fake disc geometry which is simple enough for the operating system and the user to 'understand'. 
Flash memory takes fake disc geometry a step further, they have firmware to make themselves look like a hard disk as far as the operating system is concerned when in reality there's no disc inside it at all, but blocks of memory eeeproms instead.

Originally, DOS used 'CHS', (Cylinders, Heads and Sectors) to plot the co-ordinates of important locations on the hard drive, like the Windows boot sector, or end of one partition, and the start of another partition.
The main problem with that turned out to be, when hard disk makers learned how to make things smaller so we could fit more information in the same sized disk, the software didn't know how to address the extra disk space, so the extra space couldn't be used.

Linux was able to use the extra hard disk sectors because it didn't think about the hard disk in Cylinders, Heads and Sectors, Linux simply counted each sector starting at the beginning of the disk and gave each sector a number, all the way to the end of the disk. Linux looked at the hard disk kind of like a roll of film.
That's called 'LBA' (Logical Block Addessing).
That meant Linux wasn't restricted to a maximum number of cylinders, heads and sectors, so Linux could be installed in hard disks over 1024 cylinders, or 504 Mb.




DSCF0473.png
  DSCF0473.png
What we call the 'beginning' of a disk means the outside edge, and the 'end' is really the part closest to the center. For LBA (Logical Block Addressing), sector numbers of the disk are counted from the outside in. It make sense doesn't it? That's probably why they call it 'Logical'  (block addressing).
 
When you are partitioning and decide to place a partition at the 'beginning of the free space', you are putting it towards the outside of the disc.
Placing a partition at 'the end of the free space' puts it towards the center of the disk.

Links:

Hard Disk Drive - Wikipedia

StorageReview.com A Brief History of the Hard Disk Drive

Partition types Andries Brouwer, aeb@cwi.nl 2007-10-01

Minimal partition table specification Andries Brouwer, aeb@cwi.nl 1999-09-16

Large Disk HOWTO Andries Brouwer, aeb@cwi.nl v2.5, 2004-11-01 

Linux Planet Tutorial: Adding Additional Hard Drives in Linux
NOTE: Particularly take a close look at that link's excellent illustrations! (On the second and third pages). Recommended!





 



What is the MBR?
 Link: Master Boot Record -Wikipedia
DSCF0478.png
DSCF0478.png

The MBR (Master Boot Record) is located in the first sector of a hard disk, it is also a boot sector, but it is a very special kind of boot sector.
The MBR is the first sector of a hard disk and does not belong to any partitions or the operating systems in them.
Rather, the partitions and operating systems in the hard disk belong to the MBR, because the partition table itself is part of the MBR.
That is why it is called the Master Boot Record.
  • The letters 'MBR' stand for 'Master Boot Record'
  • There can only be one Master Boot Record on each hard disk.
  • The Master Boot Record is always situated in the first sector of each hard disk
  • Every hard disk is given a Master Boot Record when it is formatted.
  • The Master Boot Record contains the hard disk's partition table 
  • The Master Boot Record may contain a small amount of boot loader code
A new hard disk might not have a MBR until it is formatted by using some kind of hard disk partitioning software such as GParted -- LiveCD for example, (that's what I use).
Another word for a MBR is a 'disk label'.  GParted LiveCD can make several kinds of disc labels.
The msdos type disc label is the kind I use, and that is most other people use too, because most new computers come with Windows in them already.
There are also amiga, bsd, dvh, gpt, mac, pc98, s390, sun and loop disc labels.
Ubuntu isn't restricted to use only the msdos disc label, but this website is about dual booting with Windows, so the msdos type disc label is the kind I'm talking about in this website.
'Formatting' the hard disk means giving it a disc label or MBR.

After your hard disk has a MBR, you can make partitions, because the partition table is in the MBR.

The MBR also contains a disc signature, to identify the hard disk. The MBR's disc signature is important for Windows Vista, since Microsoft decided to tie Vista's boot loader to the hard disk signature.

It is not correct to call a MBR "The (insert-name-of-operating-system) MBR".
The MBR does not belong to any particular operating system. The MBR belongs to the hard disk and the hard disk belongs to whoever owns the computer.

The MBR has room in it for a some code for a boot loader, but not enough room for an entire boot loader to fit into, so the code there is mainly just for pointing to the boot loader.
The boot loader codes for the most modern boot loaders does not touch the 'disk signature' in the MBR.
To make sure, Vista users especially may wish to make a backup of thier MBRs before installing Ubuntu, MBR backup and restore.

The MBR of a computer's first hard disk is special because the computer's BIOS normally boots the first hard disk when your computer is being booted. BIOS Page.

The BIOS will be directed by any boot loader's code it finds in the MBR to look up the boot loader in whichever hard disk and partition that boot loader might be in.
If there is no bootloader code in the MBR, the BIOS will go to boot sector of the active partition, (whichever partition is marked with the  'boot flag' in the partition table).

If a computer has more than one hard disk, it is possible to boot a non-first hard disk's MBR by using GRUB or another boot loader to 'chainload' it. The non-first MBR must have boot loader code installed in it for that to work. See Chainloader Boot.

We often say we are 'installing GRUB, LiLo or GAG in MBR', or 'fixing the Windows MBR', but none of those statements are really true.
The MBR is only one sector, and one sector of a hard disc can only hold 512 bytes of data.
The three main areas of code in the hard drive boot sector are the boot loader code, 446 bytes, the partition table, 64 bytes and the 55aa signature, 2 bytes = 512 bytes.

GRUB's stage2 file is about 108 Kb and I think Windows NTLDR is about 244 Kb, so obviously there isn't anywhere near enough room for a whole boot loader to fit inside a MBR. There's just enough room for code to make the MBR point to the boot loader.
Code for making the MBR point to a boot loader is called an 'IPL' (Initial Program Loader), or 'stage1', or 'first stage' of a boot loader.


What is the 'IPL' for the boot loader?
The 446 byte area of the 'boot sector' allowed for the bootloader is really too small for any decent boot loader to fit into. There is enough room for a small amount of code called the 'IPL' (Initial Program Loader). 'First stage' of the boot loader is another name for the same code.

What does the IPL for a bootloader do?
All the IPL or first stage of a bootloader has to do is look at the partition table, and tell the BIOS where on the hard disk  to go looking for the larger part of the boot loader.
The larger part of the bootloader is called the 'second stage'.

If it is the IPL for  Windows bootloader, (NTLDR), it points the BIOS to Windows boot sector and on to the right files in the Windows partition to start the second stage. Then the Windows bootloader takes over and does the real work and actually boots the operating system.

If the IPL for GRUB or GAG is in the MBR, the BIOS goes to the first track of the hard disk, which is normally empty, so some boot loaders use that for an area to put extra code.
GAG Boot Manager pretty near fills up the first track of the hard disk, because it has to fit in there entirely, GAG is 'operating system independant', meaning you can delete any or all operating systems and GAG Boot Manager will still be there.
The  first track of the hard disk, beginning with the MBR, is not formatted with any file system so it doesn't belong to any particular operating system.

GRUB boot loader only uses the first twenty-one sectors of the first track for it's stage1_5 files. GRUB's stage1_5 is optional, but it helps GRUB understand file systems and prints some types of error messages, so it helps to have it.  From there it looks for the stage2 file of GRUB.
Then GRUB's stage2 normally finds /boot/grub/menu.lst and shows the GRUB menu and lets you select which operating system you want to boot. If you select Windows, then GRUB points from Ubuntu to Windows  where it 'chainloads' Windows bootloader.
GRUB can load other operating system by chainloading the boot sector, or for Linux by booting kernels directly, or by finding and using thier configuration files.

If you choose to install LiLo instead of GRUB, LiLo makes a backup of your MBR, and it doesn't write to the first track of the hard disk at all. LiLo can be installed with the 'Alternate' CD. The 'Alternate' CD is the main subject of this web site. If you choose <Go Back> ( to Install LILO Boot Loader).


Is the MBR part of the Windows file system (Partition)?
If you enter the code 'sudo fdisk -lu' in a terminal, you will see that the first sector of the first partition does not begin until sector 63.

Code:
herman@amdxz:~$ sudo fdisk -lu

herman@amd64hh:~$ sudo fdisk -lu
[sudo] password for herman:

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x000ba675

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    42331274    21165606   83  Linux
/dev/sda2        42331275   209905289    83787007+   5  Extended
/dev/sda3   *   209905290   312576704    51335707+   7  HPFS/NTFS
/dev/sda5        42331338   204266474    80967568+  83  Linux
/dev/sda6       204266538   209905289     2819376   82  Linux swap / Solaris

It doesn't matter whether the first partition on the disk happens to be Linux or Windows, the first track of a hard disk (first 63 sectors), are normally empty except for the MBR and not formatted with any filesystems.
So you don't need to worry if you have NTFS in Windows in your first partition and you have heard that Linux can't write to it, if that's scaring you from using GRUB.
Neither the MBR or even the whole first track are part of any filesystem.
(And Linux can write to NTFS now quite safely these days anyway).

 
What does an MBR really look like?

code:
herman@amdhh:~$ sudo dd if=/dev/sda count=1 | hexdump -C
Password:
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000118 seconds, 4.3 MB/s

00000000  
00000010  
00000020  
00000030  
00000040  
00000050  
00000060 
00000070 
00000080  
00000090  
000000a0 
000000b0  
000000c0  
000000d0  
000000e0  
000000f0  
00000100  
00000110  
00000120  
00000130 
00000140  
00000150  
00000160  
00000170  
00000180  
00000190  
000001a0  
000001b0  
000001c0  
000001d0  
000001e0 
000001f0  
00000200
 eb 48 90 d0 bc 00 7c 8e  c0 8e d8 be 00 7c bf 00 
 06 b9 00 02 fc f3 a4 50  68 1c 06 cb fb b9 04 00  
 bd be 07 80 7e 00 00 7c  0b 0f 85 0e 01 83 c5 10 
 e2 f1 cd 18 88 56 00 55  c6 46 11 05 c6 46 03 02 
 80 00 00 20 01 00 00 00  00 02 fa 90 90 f6 c2 80  
 75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc 
00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 be 7f 7d 
 e8 34 01 f6 c2 80 74 54  b4 41 bb aa 55 cd 13 5a 
 52 72 49 81 fb 55 aa 75  43 a0 41 7c 84 c0 75 05  
 83 e1 01 74 37 66 8b 4c  10 be 05 7c c6 44 ff 01  
 66 8b 1e 44 7c c7 04 10  00 c7 44 02 01 00 66 89 
 5c 08 c7 44 06 00 70 66  31 c0 89 44 04 66 89 44 
 0c b4 42 cd 13 72 05 bb  00 70 eb 7d b4 08 cd 13  
 73 0a f6 c2 80 0f 84 ea  00 e9 8d 00 be 05 7c c6  
 44 ff 00 66 31 c0 88 f0  40 66 89 44 04 31 d2 88 
 ca c1 e2 02 88 e8 88 f4  40 89 44 08 31 c0 88 d0 
 c0 e8 02 66 89 04 66 a1  44 7c 66 31 d2 66 f7 34
 88 54 0a 66 31 d2 66 f7  74 04 88 54 0b 89 44 0c 
 3b 44 08 7d 3c 8a 54 0d  c0 e2 06 8a 4c 0a fe c1 
 08 d1 8a 6c 0c 5a 8a 74  0b bb 00 70 8e c3 31 db 
 b8 01 02 cd 13 72 2a 8c  c3 8e 06 48 7c 60 1e b9 
 00 01 8e db 31 f6 31 ff  fc f3 a5 1f 61 ff 26 42  
 7c be 85 7d e8 40 00 eb  0e be 8a 7d e8 38 00 eb 
 06 be 94 7d e8 30 00 be  99 7d e8 2a 00 eb fe 47  
 52 55 42 20 00 47 65 6f  6d 00 48 61 72 64 20 44  
 69 73 6b 00 52 65 61 64  00 20 45 72 72 6f 72 00 
 bb 01 00 b4 0e cd 10 ac  3c 00 75 f4 c3 00 00 00  
 00 00 00 00 00 00 00 00  75 a6 0b 00 00 00 00 01  
 01 00 83 fe ff ff 3f 00  00 00 4c ec 85 02 00 fe 
 ff ff 05 fe ff ff 8b ec  85 02 ff f9 fc 09 80 fe 
 ff ff 07 fe ff ff 8a e6  82 0c 37 a4 1e 06 00 00 
 00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa
 |.H....|......|..|
 |.......Ph.......|
 |....~..|........|
 |.....V.U.F...F..|
 |... ............|
 |u....Y|..1......|
 |. ..@|<.t...R..}|
 |.4....tT.A..U..Z|   
|RrI..U.uC.A|..u.|
 |...t7f.L...|.D..|
 |f..D|.....D...f.| 
 |\..D..pf1..D.f.D|
 |..B..r...p.}....|
 |s.............|.|
 |D..f1...@f.D.1..|
 |........@.D.1...|
 |...f..f.D|f1.f.4|
 |.T.f1.f.t..T..D.|
 |;D.}<.T.....L...|
 |...l.Z.t...p..1.|
 |.....r*....H|`..|
 |....1.1.....a.&B|
 ||..}.@.....}.8..|
 |...}.0...}.*...G|
 |RUB .Geom.Hard D|
 |isk.Read. Error.|
 |........<.u.....|
 |........u.......|
 |......?...L.....|
 |................|
 |..........7.....|
 |..............U.|

The bootloader's IPL code must fit in less than the first 446 bytes of the Master Boot Record.

The area of black text includes GRUB's
stage1 or IPL code.
This code is to point to stage1_5 GRUB in the next 21 sectors of the
normally unused first track, and to stage 2
in the Ubuntu partition.

The pink highlighted area is the 
'disk identifier' that shows up in my fdisk -lu output.
It's also known as the
'NT drive serial number'. That needs to be preserved for Windows Vista and Windows 7 to boot.

The other highlighted lines are the four 16 byte
entries of the partition table. (64 bytes total).

The aa55  bootable disk signature is shown in blue.
(2 bytes)
Here is a link to a web site that explains more about the MBR code, and lots of other interesting subjects as well, The Starman's Realm.

The Starman has way more information about MBRs and boot sectors than I can learn or fit in my website, here is a link to the Starman's MBR pages, MBR (Master Boot Record): Specific Types of Code/Structures.

Here's The Starman's take on Grub and the way we install it in Ubuntu, GRUB - The GRand Unified Boot Manager!  This link also contains a much more detailed examination of the MBR with GRUB's Stage1 code than I have.

The Starman has lots of information on Hexadecimal code too, 'All About Hexadecimal'.

I find The Starman's site very interesting reading. It will be a while before I manage to digest it all.

You can, if you wish, make a backup copy of the IPL that is in your Master Boot Record now, before installing a new bootloader (or rather the new bootloader's IPL). Then if you decide you are not happy with the new bootloader, you can restore your MBR to the way it is now.  Click on the following link, Back up your MBR    

Warning:
If you make a backup copy of your MBR you can copy the entire 512 bytes, which means the entire MBR including the partition table and 55 aa signature.
That may be useful sometimes, but be sure you destroy that copy of your MBR if you decide to re-partition your disk later. If you accidentally restore your MBR with an out of date partition table, it will not match your new filesystems. It will cause your disk to be unreadable.  Unless it is very important data you will probably have to give it up and reformat and repartition your disk and loose all your data and have to start again.

If you only want the to make a backup copy of the bootloader code, you only need the first 466 bytes of the MBR, so it will not include the partition table. That is much safer. That is what I do.

Warning:
The first 466 bytes of the MBR includes the 'Disk Identifier', which is important to Vista and Windows 7's BCD boot loader. It might be a good idea to back that up most of the time and restore it again, but sometimes it might not be so good, depending on other circumstances. You must use your own judgement about that.

The following code will install GRUB to MBR of the first hard disk, from a hard disk installed Ubuntu operating system.
Code:
herman@amdxz:~$ sudo grub-install /dev/sda
Where: 'sda' is the first hard disk if you have more than one.
You can install Grub to MBR on a non-first hard disk with 'sdb' for second hard disk MBR, or 'sdc' for third hard disk MBR, and so on. 

The Windows FIXMBR command writes Windows XP's boot loader code to MBR. See this website's Un-install Page for details, and for more ways to restore Windows boot code to a hard disk's MBR.



What are 'boot sectors'?

This first sector of a partition is known as the 'boot sector'.

A boot sector is not to be confused with an MBR, they are two different things.
A MBR and a boot sector both may contain code for a boot loader, but a boot sector is not a MBR.
'MBR' stands for 'Master Boot Record', there can only be one Master Boot Record per hard disk, but there can be many partitions. There can be as many 'boot sectors' as there are partitions.

There are backup copies of the boot sector in some file systems.

In a FAT32 file system, the backup of the boot sector is in sector 6 of the file system. The FAT32 boot sector can be restored from its backup with Linux commands, see When the bootsector is not the same as its backup - FAT32. We can also use TestDisk for restoring the FAT32 boot sector from it's backup, Advanced FAT Repair - CGSecurity.

An NTFS file system has the backups of it's boot sector in the last sector of the file system. We can restore the boot sector of a partition containing an NTFS file system with TestDisk.
TestDisk is a program you can install in Ubuntu, and TestDisk can easily restore the boot sector in an NTFS partition from the backup, or even rebuild an NTFS boot sector, TestDisk has their own page with illustrations, here is a link, NTFS Boot Sector Recovery.

Windows operating systems has the bootloader's code written there by default,so we can always chainload Windows by its boot sector. (Well, almost always).
Linux operating systems do not necessarily have any boot code in their first sectors, but a boot loader, (or rather the IPL for one), can be installed there by the user, and in my opinion that's a good idea.


Can a bootloader's IPL be installed in a partition?
The following code will install GRUB to the first sector of a Linux partition, when issued from a hard disk installed Ubuntu operating system.
Code:
herman@amdxz:~$ sudo grub-install /dev/sda2
Where 'hda2' is the right partition number for the Linux partition you want GRUB installed on.

Note: this can be done without affecting the MBR or bootloaders on other partitions.
Unless that operating system also owns the bootloader installed to MBR, you would not be able to boot to that partition unless you use another boot manager or a bootloader to chainload it, (point to it).

An alternative idea is to install LiLo to the first sector of a Ubuntu partition, rather than Grub, as it can provide you with an auxiliary means of booting my system, in case something goes wrong with my MBR-installed bootloader, GRUB.

The Windows FIXBOOT command writes Windows XP's boot loader code to the Windows boot sector. 




The partition table and partition numbering
00 fe ff ff 05 fe ff ff ab 81  d1 01 c3 1c 20 00
00 01  01 00 83 fe 7f e5 3f 00  00 00 27 22 77 00
80 00 41 e6 83 fe ff ff 66 22  77 00 45 5f 5a 01
00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
These are the four entries for my partition table. There are web pages that explain how to decode these, but normally it is easier to read and edit our partition table with our partition editor software.

3parted
    partition 1                       partition 2                  partition 3                      partition 4

For a while, in times of olde, a disk could only have four partitions. The partition numbers 1,2,3 and 4 are reserved for the partitions which occupy an entry in the Master Boot Record's partition table.


Then, someone managed to discover a way to sub-partition one of these four primary partitions, but only one of the four primary partitions is allowed to be divided up in this way.

The sub-partitioned primary partition is called an 'extended' partition. It can have the number 1,2,3 or 4.

The partitions that are inside it are called 'logical' partitions.
They must be 'contiguous', (in a series). They can be separated by free space, but a primary partition is not allowed to be be placed in between logical partitions. 

4parted
      partition 1                   partition2                     partition 3                     partition 4
                                                                               
                                                                                partition 5
                                                                                partition 6
                                                                                partition 7
                                                                                partition 8
                                                                                partition 9

Because the numbers 1,2,3 and 4 are reserved for the four primary partitions (or three primary and one extended partition), the partition numbering for logical partitions always begins with number 5.
Even if there is only an extended partition and no other primary partitions, the logical partitions can never have a number lower than 5.
Logical partition numbering begins at five and counts upwards from there.
On an IDE disk, we can make as many as 63 logical partitions inside an extended partition. 

Each partition we add is given the next available partition number in the order that the partition are created in. They don't have to be numbered in disk order.
In other words, I could make partition number 1 first, and place it anywhere on my disk (furthest to the right for example).
The next partition I make will be given the number 2, and it can be anywhere, the next, number 3 can be anywhere, and number 4 can be located wherever there is space left over.

If I were to delete partition number 1, the number 1 would then be the lowest available partition number.

That means time I make a new primary partition, it will be given the number 1, because the number 1 is vacant, and it is the first available number.







Managing My Partitions with GParted

GParted Web Forums:
http://sourceforge.net/forum/forum.php?forum_id=396063

GParted General Documentation "LarryT's Docs":

 
http://gparted.sourceforge.net/larry/generalities/gparted.htm

How to resize partition, step by step

The livecd-howto
   
1gparted
fig 1 partioning
Most of us brought our computers home from the store with Windows already installed on one big primary partition like this, with Windows taking up the whole hard disk.
Most Windows users would call this their 'C' drive.  
It is also partition number 1.
In Linux it is designated /dev/hda1, or hda1 for short.
In Grub terms this is hard drive 0, partition 0, or (hd0,0).

2parted
partition 1partition 2 partition3
partition5

                                                                                                                                                                                                                           

Now I have installed Ubuntu. The default Ubuntu install makes a new primary partition which is assigned the next available partition number for primary partitions, which is number 2, or /dev/hda2.
In Grub's numbering scheme this will be (hd0,1).

The swap area (red), is inside another partition. The partition that the swap area is in is called an 'extended' partition. An extended partition is a special type of primary partition and it will be given the next available partition number for primary partitions which in this example will be number 3.

The swap area will be partition number 5.

Why did we skip the number 4?
Because the number 4 is reserved for primary partitions and we have not yet made four of those. Logical partitions always begin counting from 5.

Why is all this partition number stuff so important?
It isn't very important to most computer users until they decide to start playing around with their partitions.
If you don't know what you are doing, it would be easy to cause yourself a quite a lot of trouble by telling your disk partitioning software to perform operations that will change the number of one or more of your partitions.
Changing the partition number of an operating system will make the operating system unbootable, or a data partition inaccessable, unless you know how to fix that again.

Many new users will not know what to do and might even get impatient and frustrated and feel like formatting their entire disk and starting again.














   
A Birds's eye view of Windows XP

The boot.ini file in Windows XP is the file that controls the next part of the process for booting Windows. I will show you how find it and have a look at it from Ubuntu. You will need to have Ubuntu installed in your computer to do this, or you can use the Live CD and mount your Windows partition manually.

fig4mbr
                 fig 4 mbr

Open your hda1 partition  with this icon (above illustration) to see boot.ini and other files that are associated with booting Windows. 


fig 5 mbr
fig 5 mbr                  
Here's a view of what my Windows system looks like looking down on it.
 
I opened my boot .ini  with our text editor, 'gedit', too see what's inside. (below)
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Home Edition" /fastdetect /NoExecute=OptIn
This is what the boot.ini file looks like.

fig 6 mbr
NTLDR, boot.ini, and ntdetect.com are the three most vital files needed for booting Windows XP.

If your partition number for the Windows partition ever happened to be accidentally changed, by messing around with disk partitioning software, for example, Windows won't boot. It just needs boot.ini to be edited with the new partition number to fix the problem. But, -- when Windows won't boot, you can't edit boot.ini, and you can't edit boot.ini to boot it, so you would be stuck...        Unless...

The best solution to the problem of finding your Windows unbootable after using disk partitioning software is to make your own Windows XP boot floppy disk.
A Windows XP boot floppy disk contains three vital files, boot.ini, ntdetect and NTLDR.
That would even get you out of trouble if you had Windows on NTFS, which is still considered dangerous to write to from Linux. However, you can edit the boot.ini on the floppy disk any time you like, and as often as you like, without hurting anything.  
How to create your own boot disk for Windows XP

As far as I know, the floppy disk must first be formatted in Windows, exactly the way the instructions say, so you might need to use another Windows XP computer.
I have not yet tried to make a CD like that, but it might also work, I don't know.

If your computer has no floppy disk drive, and you are lucky enough to have the FAT32 filesystem in Windows XP, and you are planning ahead, you can relax the file permissions for boot.ini, so that you can edit it from Linux.

To relax the security attributes for the boot.ini file, boot Windows XP,
1) Click Start
2) Click 'Run'
3) Type CMD in the 'Run' box,  
 Open:       CMD                            
4) Click the 'OK' button

Next. you can expect to see a black terminal with prompt like illustrated below:
Microsoft Windows XP [Version 5.1.2600]
<C> Copywrite 1985-2001 Microsoft Corp.

C:\Documents and settings\Herman >_
C:\Documents and Settings\Herman >_

5) type cd\ after this prompt.

C:\Documents and settings\Herman >cd\

C:\>_
C:\_                                           (New prompt looks like this)


C:\> attrib -s -h -r boot.ini
6) Type the above command,     C:\>attrib -s -h -r boot.ini     and press 'Enter'.

Then you can make changes to your partitions a little more safely, knowing that if you do accidentally have your Windows partition number changed, at least you can edit boot.ini from Linux and still boot it again.

7)
C:\>exit


8) To re-assert the security attributes for the file after you finish your partitioning work,
C:\>attrib +s +h +r boot.ini
Type the following command,     C:\>attrib +s +h +r boot.ini        and press 'Enter'.

C:\>exit
C:\>exit






 Installing a Boot Loader for Ubuntu (when installing with the 'Alternate' CD).

GRUB      the GRand Unified Bootloader

 
[!] Install the GRUB boot loader on a hard disk

The following other operating systems have been detected on this computer: Microsoft Windows XP Home Edition.

If all of your operating systems are listed above, then it should be safe to install the boot loader to the master boot record of your first hard drive. When your computer boots, you will be able to choose to load one of these operating systems or your new system.

Install the GRUB boot loader to the master boot record?
<Go Back>                                    <Yes>      <No>
                 fig 7 mbr
If you choose <Yes> ( to Install GRUB's IPL to MBR)
The wording on the panel illustrated above, is brief and practical. There isn't time or room for a page as big as this one to explain exactly what happens. 

All of GRUB doesn't really get installed on your 512 byte MBR, that's just a kind of an abreviated way of saying things to avoid taking the time to explain what really happens.

All bootloaders come in two or three stages.  The reason for this is because the space allowed in the MBR is so small, less than 446 bytes are allowed for the bootloader's code. No bootloader could possibly fit in such a tiny space. Instead, only the 'stage1' or 'IPL' (Initial Program Loader), which is the first part of any bootloader goes there. The job of the bootloader's 'IPL' or 'stage1' is to either point to the bootloader files in the operating system's partition or else point to the first sector of the partition, which in turn points to the bootloader's stage2 files.

Windows NTLDR works that way too, and so does Lilo.
Those both come in two stages, 'stage1' and 'stage2'.
'Stage1' fits in the MBR, and 'Stage2' lives in the operating system.
Grub comes in three stages. First, 'stage1' is the bit that fits inside the MBR, 'stage1_5' (optional) is written to the next fifteen sectors of the unused first track of the hard disk, and 'stage2' (the important part) is installed in a partition.
Normally, this will be the operating system's partition, (Ubuntu)  but it can be installed in a dedicated /boot partition if one has been made.

So really what this sign is asking is:
"Do you want the first 446 bytes of grub (stage1) written to the MBR ?"
'stage 1' will be copied to the master boot record if you choose 'Yes'.
This will overwrite the 'IPL' code for the bootloader you had installed before.

stage1_5 of GRUB, will also be written to the next 15 sectors following the MBR. The advantage of grub's stage1_5 is that it 'understands' many filesystems, and Grub can perform quite a number of useful tricks because of that. The first track of the hard disk is not formatted with any filesystem and so does not belong to any partition or operating system. It is normally empty and is left vacant for this sort of use.
In rare instances there can be other types of special programs installed there. There shouldn't be, but you should remember if you have installed any. You should have been notified if someone else installed something there, as it is unusual. Some older BIOSes disks needed 'disk manager' software to see larger hard disks than they were designed for, but those would be rare nowadays.
Some models of Toshiba Satellite Notebooks that have the Express Media Player are known to have difficulties with GRUB. LiLo is recommended for those instead.

stage2, the second stage boot loader is the part that does the real work. The second stage of a boot loader brings up our new grub menu (below) and later does the real work of loading an operating system's kernel.  




 Ubuntu, kernel 2.6.20-15-generic                        
 Ubuntu, kernel 2.6.20-15-generic (recovery mode)
 Ubuntu, memtest86+
 Other operating systems:
 Microsoft Windows XP Home Edition







    Use the | and | keys to select which entry is highlighted.
    Press enter to boot the selected OS, or 'e' to edit the
    commands before booting, or 'c' for a command-line.


     The highlighted entry will be booted in 10 seconds.


             fig 8 mbr
The user gets a chance to decide what operating system to load, Windows or Ubuntu, and any others when the GRUB menu shows on boot-up.  
If the user selects Windows, or a Linux system that doesn't have Grub (LiLo maybe), then GRUB's second stage, in /boot/grub , on the Ubuntu partition, points to the other operating system's partition's first sector and chainloads it. The term chainloading means it passes control to the other system's bootloader. If it's NTLDR, then NTLDR in turn loads Windows. 
If the user selects Ubuntu, or another Gnu/Linux operating system with Grub, then GRUB loads the kernel for it into the computer's memory and boots the computer with that operating system.

 
If you choose <No> ( to Install GRUB's IPL to a custom location)

[!] Install the GRUB boot loader on a hard disk

The following other operating systems have been detected on this computer: Microsoft Windows XP Home Edition.

If all of your operating systems are listed above, then it should be safe to install the boot loader to the master boot record of your first hard drive. When your computer boots, you will be able to choose to load one of these operating systems or your new system.

Install the GRUB boot loader to the master boot record?
<Go Back>                                 <Yes>      <No> 

                 fig 9 mbr
Choosing 'No' doesn't mean GRUB will not be installed, it just means you don't necessarily want to install GRUB's IPL to MBR and GRUB's stage1_5 in the next fifteen sectors. Maybe you want to install GRUB's IPL somewhere else?

[!!] Install the GRUB bootloader on a hard disk

You need to make the newly installed system bootable, by installing the GRUB boot loader on a bootable device. The usual way to do this is to install GRUB to the master boot record of your first hard drive. If you prefer, you can install GRUB elsewhere on the drive, or to another drive, or even to a floppy.

The device can be specified using GRUB's "(hdn,m)" notation, or as a device in /dev. Below are some examples:
- "(hd0)" or "/dev/hda" will install GRUB to the master boot record of your first hard drive (IDE);
- "(hd0,1)" or "/dev/hda2" will use the second partition of your first IDE drive;
-"(hd2,4)" or "/dev/hdc5" will use the first extended partition of your third drive (SCSI here);
-"(fd0)" or "/dev/fd0" will install GRUB to a floppy.

Device for boot loader installation

 (fd0)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 
<Go Back>                                              <Continue>
       fig 10 mbr
This panel comes next, you can type in a custom location on the dotted line to specify where exactly you do want GRUB to be installed.
                                           NOTE: Without the inverted commas!                                               
If you want GRUB's IPL installed to your second hard disk's MBR instead of your first one, type (hd1) or /dev/hdb here. Some computers have a BIOS that allows the user to easily choose which hard disk to boot. Mine does, click hard disk boot priority to see what I mean. Then you can either enter your BIOS to set which MBR to boot or use another system's GRUB to chainload your second hard disk's MBR.

If you want GRUB's IPL installed to the first sector of your Ubuntu partition, type (hd0,1) or /dev/hda2 here (where hd0,1 or /dev/hda2 is the correct designation for your Ubuntu partition.
That means you will have to chainload GRUB from another bootloader or boot manager like GAG Boot Manager in MBR or from a floppy disk or a CD.

We can install GRUB to floppy disk by typing (fd0) on the line. Grub works very well from floppy disks. You should make extra copies of the floppy disk in case the floppy gets corrupted somehow (like you spill coffee on it or your dog chews it up or something like that). Here is a link to a great website about 'dd' commands in Linux, it explains how to replicate floppy disks, and much more besides, http://www.linuxquestions.org/questions/showthread.php?t=362506
Or, if you are not comfortable with Linux commands yet, you can use the 'Alternate' install CD in 'rescue mode'

If you use 'Tab' to select <Continue>, you'll probably get a red warning screen.
You can choose <Go Back> if you want. That will bring you back to the panel show in fig 11 below again.


If you choose <Go Back> ( to Install LILO Boot Loader)

[!] Install the GRUB boot loader on a hard disk

The following other operating systems have been detected on this computer: Microsoft Windows XP Home Edition.

If all of your operating systems are listed above, then it should be safe to install the boot loader to the master boot record of your first hard drive. When your computer boots, you will be able to choose to load one of these operating systems or your new system.

Install the GRUB boot loader to the master boot record?
 <Go Back>                                 <Yes>      <No> 
            fig 11 mbr
 
[?] Ubuntu installer main menu

Choose the next step in the install process:

Choose language
Configure the keyboard
Detect and mount CD-ROM
Load debconf preconfiguration file
Load installer components from CD
Detect network hardware
Configure the network
Configure the clock
Detect disks
Partition disks
Install the base system
Set up users and passwords
Configure the package manager
Select and install software
Install the GRUB boot loader on a hard disk
Install the LILO boot loader on a hard disk          
Continue without a boot loader
Finish the installation
Change debconf priority
Check the CD-ROM(s) integrity
Save debug logs
Execute a shell
Eject a CD from the drive
Abort the installation
fig 12 mbr
This is the Ubuntu Installer Main Menu that I keep referring to.
If you want to install LILO boot loader, you just select that line and press 'enter', (of course, what else?).

Well there is the line titled 'Continue without a boot loader'.
I wouldn't recommend that one, I don't know why anyone would want to do that.  Well you could, but you would need to boot it with Super Grub Disk.
Or you would have to have Grub already installed in another operating system and know how to use GRUB from the Command Line to boot your new Ubuntu installation.
Then you would manually edit the /boot/grub/menu.lst in the other Linux operating system with an entry for Ubuntu.  Operating System Entries for Multiple Booting More Linux Systems.

In this example I have shown 'Install the Lilo boot loader on a hard disk', and below is the resulting panel from that selection.

[!] Install the LILO boot loader on a hard disk

The LILO program needs to be installed to make your new system bootable. By installing it onto your disk's Master Boot Record, LILO will take complete control of the boot process, but if you want to use a different boot manager, just install LILO on the new Ubuntu partition instead.

If unsure, install LILO into the Master Boot Record.

LILO installation target;

          /dev/sda: Master Boot Record
          /dev/sda2: new Ubuntu partition    
          Other choice (Advanced)

  <Go Back>                                             


                fig 13 mbr
This panel gives three options, as you can see.

LiLo is the polite Linux boot loader, it only writes to the MBR, and not to any other sectors in the first track of the hard disk.

LiLo makes a backup of your MBR before it installs there. The MBR backup will be called boot.####, (where # (hash symbols) represent a four digit number), and it will be stored in your /boot directory.

If you install LiLo to MBR, your OS should boot right up with LiLo directly off the MBR.

I have shown highlighted the one I want to use this time, '/dev/hda2: new Ubuntu partition.' This means the IPL for LILO will be installed in my first sector (boot block) of my new Ubuntu partition.
Since I'm not installing to MBR, I will need  some other boot loader or a boot manager to boot Lilo with, and Lilo will boot Ubuntu.
This other boot loader can be one with an IPL in the MBR already, that can be configured to boot Lilo and Ubuntu.
GAG Boot Manager is one I use, GAG can boot Lilo and Ubuntu from a GAG floppy disk, or from a GAG CD-ROM. More info on how to use GAG Boot Manager: GAG Page.
This option will not touch your MBR.
Or you can use a Super Grub Disk.


fig 14 mbr
                 fig 14 mbr
This is an illustration of the panel you'll see if you select 'Other choice (Advanced)' from the panel shown in fig13, above.
This allows a user to select a custom location to install LILO to, such as (fd0) perhaps. (Floppy disk). Or some other more exotic location.

For more about LiLo, please feel free to go to the LiLo Page of this web site.

============================================================







Links    

The Boot Process: http://www.linux-tutorial.info/modules.php?name=Tutorial&pageid=64
    
Here's a link to the Wikipedia page on boot loaders: http://en.wikipedia.org/wiki/Boot_sequence
    
Here's an excellent website which explains a lot about how Linux boot loaders (LILO and GRUB) work: 
http://www-128.ibm.com/developerworks/library/l-bootload.html?ca=dgr-lnxw01LILOandGRUB
    
And here's another good one:     http://www.syrlug.org/contrib/boot-loaders.html


barrier_board




Back to Top