====== What's a partition ======
**Definition:** Hard disk partition is a defined storage space on a hard drive.
Depending of the user needs, it is possible to separate the hard disk into several partitions. In that way, you create several logical devices, from one bigger, physical device.
There is a reserved space on the beggining of the hard drive device, called **partition table**. In that space, all information about the partitioning is stored.
===== The reasons =====
There are a lot of reasons to separate your hard disk into partitions. In any way, the partitions enable you to store data more efficiently. For example, for PCs with multiple Operating Systems on, it is wise to install each OS on different partition.
===== File systems and partitions =====
When you separate your disk into partition, you don't store information in the partitions. Actually, you install filesystem on the partition and store files in it. The partitions are only used to separate your physical device into logical devices, understandable for you.
===== Creating partitions =====
In many Operating Systems, the **fdisk** utility is available. **Disk druide** is always a common choice to some Linux users.
We will give example of partitioning a hard disk, using the fdisk utility.
Let's assume that we want to create the following partition scheme:
/dev/hda1 Boot partition
/dev/hda2 Swap partition
/dev/hda5 Root partition
So, assuming that our main disk is '/dev/hda', we fire up fdisk:
$fdisk /dev/hda
Then, we get the command prompt:
Command (m for help):
From here, there are several possibilities. We can erase ALL disk partitions which have been already created, or we can just reformat them, as we need them. However, we can view the current partition scheme:
Command (m for help): p
Disk /dev/hda: 280 heads, 65 sectors, 2400 cylinders
Units = cylinders of 15150 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hda1 1 14 105808+ 83 Linux
/dev/hda2 15 49 264600 82 Linux
/dev/hda3 50 70 158760 83 Extended
/dev/hda4 71 2184 15981840 5 Extended
/dev/hda5 71 209 1050808+ 83 Linux
Command (m for help):
As you can see, in order to accomplish the starting idea, we must delete these partitions:
Command (m for help): d
Partition number (1-4): 1
In this example, we delete the first partition, note that it is /dev/hda2. The second partition would be /dev/hda2 and so on. Repeat the procedure above to delete all of them.
==== Creating the boot partition ====
Now, the partition table is empty. So, first we will create the boot partition, /dev/hda1.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3967, default 1): (Enter)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-3967, default 3876): (Enter or use +32M, it is enough for boot)
So, we check:
Command (m for help): p
Disk /dev/hda: 30.0 GB, 30005821440 bytes
245 heads, 66 sectors/track, 3967 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
/dev/hda1 1 14 105808+ 83 Linux
Now, to create it as boot partition, we type 'a' in the command line, and select 1. Then, /dev/hda1 will be boot partition.
==== Creating the swap partition ====
Now, we must create the swap partition. We defined it to be in /dev/hda2. So, we must first create it, just like the boot partition. Type 'n', then 'p', for primary partition, then select 2, for /dev/hda2. When prompted for first cylinder, hit enter, for the last cylinder select a size. It is prefferably to be big enough, for example 512 MB. You can create it bigger. However, for the last cylinder type +512M if you like so.
Then type 't' in the command line to set a partition type. Then 2. For partition type, enter 82, which reffers to Linux Swap.
After all this, check the table:
Command (m for help): p
Disk /dev/hda: 30.0 GB, 30005821440 bytes
245 heads, 66 sectors/track, 3967 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 14 105808+ 83 Linux
/dev/hda2 15 81 506520 82 Linux swap
==== Creating the root partition ====
Now, the last part, creating the root partition. It is pretty like every other partition we created so far. Type 'n' to create new partition,then 'p' for primary partition. Then , type 5, because we selected /dev/hda5 to be our root partition. Now, for both , the first and the last cylinder press enter, because we need to take as much space as we can. Check the results again, by hitting 'p':
Command (m for help): p
Disk /dev/hda: 30.0 GB, 30005821440 bytes
245 heads, 66 sectors/track, 3967 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 14 105808+ 83 Linux
/dev/hda2 15 81 506520 82 Linux swap
/dev/hda5 82 3876 28690200 83 Linux
===== Partition types =====
In order to recognize different partitions, when a specific partition is created, a special byte of data is added to it. By that byte, its partition type will be recognized.
Here comes the table of partition numbers:
Partition Number Partition Type
00 Empty
01 DOS 12-bit FAT
02 XENIX root
03 XENIX usr
04 DOS 16-bit FAT <=32M
05 DOS Extended Partition
06 DOS 16-bit FAT >=32
07 OS/2 HPFS, WinNT NTFS
08 AIX
09 AIX bootable
0a OS/2 Boot Manager
0b Win95 FAT32
0c Win95 FAT32 (LBA)
0e Win95 FAT16 (LBA)
0f Win95 Extended (LBA)
35 OS/2 JFS
39 Plan 9
40 Venix 80286
51 Novell
52 Microport
63 Unix System V, Mach, GNU HURD
64 Novell Netware 286
65 Novell Netware 386
75 PIC/IX
80 MINIX until 1.4a
81 MINUX, Linux
82 Solaris X86, Linux swap
83 Linux native
85 Linux extended
93 Amoeba
94 Amoeba BBT
a5 FreeBSD, NetBSD, BSD/386, 386BSD
a6 OpenBSD
a7 NEXTSTEP
b7 BSDI BSD/386 filesystem
b8 BSDI BSD/386 swap
be Solaris 8 bootable
bf Solaris x86
c7 Syrinx
db CP/M
e1 DOS access
e3 DOS R/O
eb BeOS BFS
fb VMWare filesystem
fc VMWare swap
f2 DOS secondary
ff Xenix Bad Block Tab
===== Extended partitions =====
In the standard partition table, defined on the beggining of this document,there is space to record only four partitions. In other words, that means that only four partitions can be created on your HDD. But, to overcome this limitations, **extended partitions** were created.
Every extended partition records partition information about the other partitions. Therefore, the possiblity opens to create more then four partitions.