Linux OS will consider every thing as files even hardware too, for example if there is one hard disk in a Linux system then it is represented as hda(harddisk “A”)under /dev folder

For example if we have 2 Hard disks then the representation is like below
/dev/hda
/dev/hdb
Where /dev/hda is primary master HDD and /dev/hdb is primary slave HDD

If we want to represent floppy drive then the representation is as below
/dev/fd0

If we want to represent second floppy drive then the representation is
/dev/fd1

If we want to represent cdrom
/dev/cdrom

If we want to represent DVD-writer
/dev/dvdwriter

If we want to represent special devices such as SATA,USB-mass storageetc then the representations are as below
/dev/sda
/dev/sdb
/dev/sdc till up to /dev/sdz

Suppose if we ant to represent partitions on HDD it goes as below
/dev/hda0 for first partition in primary master HDD
/dev/hda1 for second partition in primary slave HDD
/dev/sdd5 for forth partition in special device 4

 

Before creating any partitions we should remember the following things.
a.
 Check for what purpose we want to create the partitions(for example for creating swap)
b. Check weather any free space left by using fdisk -l command

So if there is any free space then we can directly create partitions

step1Check there is any free space or not
#fdisk -l
Disk /dev/hda: 20.0 GB, 20060651520 bytes255 heads, 63 sectors/track, 2438 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/hda1 1 1024 8225248+ b W95 FAT32/dev/hda2 * 1025 2438 11357955 c W95 FAT32 (LBA)Disk /dev/hdb: 80.0 GB, 80060424192 bytes255 heads, 63 sectors/track, 9733 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/hdb1 * 1 2432 19535008+ 83 Linux/dev/hdb2 2433 2554 979965 82 Linux swap / Solaris/dev/hdb3 2555 6202 29302560 83 Linux/dev/hdb4 6203 9733 28362757+ 5 Extended/dev/hdb5 6203 9733 28362726 83 Linux

fdisk is a command which will show all the disks present in the system weather it is partition or free space. From the above out put we can clearly know that the system is having 2 harddisks one with 20GB and the other with 80GB(with red mark). This is an interview question how to find Harddisk size in linux.

Step2Use fdisk command on the disk in order to create the partitions
#fdisk /dev/hda

Here it will show full details of /dev/hda Disk /dev/hdb: 80.0 GB, 80060424192 bytes255 heads, 63 sectors/track, 9733 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/hdb1 * 1 2432 19535008+ 83 Linux/dev/hdb2 2433 2554 979965 82 Linux swap / Solaris/dev/hdb3 2555 6202 29302560 83 Linux/dev/hdb4 6203 9733 28362757+ 5 Extended/dev/hdb5 6203 9733 28362726 83 Linuxcommand (m for help):

So press m to explore your self .

Step3Creating new partition.

Press n with out quote to create new partition. So specify your size in prbytes/kb/mb with + preseeding to the value suppose if you want to create a new partition of 23mb you have to say +23MB then press enter

One more example create a new partion of 538kb? thinking????????? still thinking?????? yes you are right it is +538KB

Step4 : So what next? Suppose you donot want to create this partition so delete it. At this point the partition table changes are not updated to partition table to do this one just type q.

Step5 : Updating the created partition to partition table just press w with out quotes thats it you are almost done.

Step6 : So you have updated the changes to partition table then you have to say this change to Kernel so for doing that there are two ways

A. Just restart the system(so you are thinking this is easiest way ha? never do this on live servers because you have to give 99.999% uptime to your servers. so always do second way.

B. Just execute partprob command this will update the partition table changes to kernel #partprob /dev/hda