Every computer owner will come across the street road called Partitioning. Partitioning simply means dividing your physical hard drive into 2 or more logical (or virtual) drives. In Linux there are different kinds of applications that can help you do this, and one is fdisk.
For this example, I will demonstrate how to use fdisk.
The basic command goes like fdisk <device-name> like:
# fdisk /dev/hda
The number of cylinders for this disk is set to 14596.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)Command (m for help):
To display the help menu or if you want to list all of available commands:
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Now for the action. Let’s say we need to see how many partitions are in the disk.
Command (m for help): p
Disk /dev/hda: 120.0 GB, 120060444672 bytes
255 heads, 63 sectors/track, 14596 cylinders, total 234493056 sectors
Units = sectors of 1 * 512 = 512 bytesDevice Boot Start End Blocks Id System
/dev/hda1 * 63 30716279 15358108+ 83 Linux
/dev/hda2 30716280 81915434 25599577+ 83 Linux
/dev/hda3 81915435 82975724 530145 82 Linux swap / Solaris
/dev/hda4 82975725 234484739 75754507+ 5 Extended
/dev/hda5 82975788 234484739 75754476 83 Linux
So there are 4 primary partitions - hda1, hda2, hda3 and hda4. The last partition, hda4, is the Extended Partition or the Logical Partition which contains the hda5 partition.
Now that we have seen all the partitions, let us say that we are going to delete the /dev/hda1partition and create a new one.
But before we can create a new one, we should delete the old one first. These steps does not execute the commands at once. If you made a mistake, you can just quit the program without committing any changes.
To delete a partition, just type d on the prompt. For this example, what I want to do is delete the first partition, /dev/hda1:
Command (m for help): d
Partition number (1-5): 1
The partition number means that /dev/hda1will be deleted. To check if we have typed in the correct partition number (I hope I did!) just do:
Command (m for help): p
Disk /dev/hda: 120.0 GB, 120060444672 bytes
255 heads, 63 sectors/track, 14596 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System
/dev/hda2 1913 5099 25599577+ 83 Linux
/dev/hda3 5100 5165 530145 82 Linux swap / Solaris
/dev/hda4 5166 14596 75754507+ 5 Extended
/dev/hda5 5166 14596 75754476 83 Linux
Voila! /dev/hda1 is no longer there. But no worries, it is still there. We just need to create a new one.
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Selected partition 1
First cylinder (1-14596, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1912, default 1912):
Using default value 1912Command (m for help): p
Disk /dev/hda: 120.0 GB, 120060444672 bytes
255 heads, 63 sectors/track, 14596 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System
/dev/hda1 1 1912 15358108+ 83 Linux
/dev/hda2 1913 5099 25599577+ 83 Linux
/dev/hda3 5100 5165 530145 82 Linux swap / Solaris
/dev/hda4 5166 14596 75754507+ 5 Extended
/dev/hda5 5166 14596 75754476 83 Linux
The n command will create a new partition, in this case, replacing the old /dev/hda1 that we have deleted and the p command will display that we have successfully created a new one (yay!).
To commit the changes, type w on the prompt.
Command (m for help): m
Command action
w write table to disk and exit
But for now we will exit fdisk without saving the changes.
Command (m for help): q
That’s all for fdisk for now. There are other commands available on fdisk, just do not forget the use the man pages and the m command. If you have deleted a big chunk of important files, well, experience is the best teacher ![]()
Popularity: 5% [?]



















Leave a comment