Skip to main content

Partition Management

What do you mean by a partition?

A partition is a way to compartmentalize a hard disk i.e create different compartments of hard disk so that different parts of hard disk can be formatted as different file systems as per requirement or can be used for different purposes.

Types of partitions

There are three different types of partitions with different pros and cons (prospects and consequences). The names are:

1. Primary partition.

2. Extended partition.

3. Logical partition.

Now that we know about the different type of partitions so let us learn how to create a partition in Linux. Just remember that way or procedure to create a partition in Linux is completely different from the way or procedure partitions are created in Microsoft Windows. The simple steps to create a partition in Linux are as follows (all commands are typed in command prompt only): 

1. Start with listing the available hard disks for partitions. The command to list the available hard disks is:
  
fdisk<space>-l

2. Choose the hard disk to partition like sda or sdb. The command to choose sda is:

fdisk<space>/dev/sda ↲

3. Use 'n' to create new partition. After that select 'p' or 'e' for creating a primary or extended file system. The second 'p' is to print/show the partition table and 'wq' is to save the information and quit the fdisk command-line. The example commands are:

n ↲e ↲Cylinders informationp ↲Sizewq ↲

4. List the system partition table of the particular disk and add the specified partition to partition table of the disk. The command is:

partx<space>-a<space>/dev/sda ↲

5. Create new filesystem for the partition. The command is:

mkfs.ext4<space>/dev/sda<partition number> ↲

6. Create a mount point i.e directory for disk mounting. The command is:

mkdir<space>/<name> ↲

7. Mount disk partitions during system boot up in /etc/fstab file. The command is:

vim<space>/etc/fstab ↲

8. Add the following entry in /etc/fstab file at the end of the file:

/dev/sda<partition number>          /<directory name>         ext4           defaults     1    2

9. Mount all the file systems mentioned in /etc/fstab file as indicated. The command is:

mount<space>-a ↲

Make sure you do not get any error after the above command is entered.
 
10. Check whether disk is mounted successfully or not. The command is:

df<space>-h ↲

Important notes:

1. All the above commands must be typed in root directory.

2. 'cu' command can be used to solve the out of range problem or disable the D.O.S requirements at step 3.

3. mkfs.ext4<space>-l<space><label name><space>/dev/sda<partition number> command can be used to give partition a name.

4. Always remember to follow the above mentioned steps as-it-is without any deviation for successful end result.

5. 'fdisk" refers to fixed disk or format disk. 

6. 'w' command can be used in place of 'wq' command.

Deleting a partition

Let us learn how to delete a partition in Linux. Just remember that way or procedure to delete a partition in Linux is completely different from the way or procedure partitions are deleted in Microsoft Windows. The simple steps to delete a partition in Linux are as follows (all commands are typed in command prompt only): 

1. Start by checking the mounted space and partition.

2.  Unmount the partition to safely delete it. This is necessary to delete a partition. The command to unmount is:

unmount<space>/dev/sda<partition number> ↲

3. Choose the hard disk to delete from like sda or sdb. The command to choose sda is:

fdisk<space>/dev/sda

4. Print/show partition table. The command is:

p ↲

5. Start deleting a partition. The command to  delete a partition is:

d ↲

6. Select the partition by partition number. The command to select a partition number is:

Partition number<number> ↲

7. Print/show partition information. The command is:

p ↲

8. Save the information. The command is:

w ↲

9. List the partition table. The command is:

partx<space>-a<space>/dev/sda ↲

10. Delete entry from /etc/fstab file. The command is:

vim<space>/etc/fstab ↲

Important notes:

1. All the above commands must be typed in root directory.

2. Always remember to follow the above mentioned steps as-it-is without any deviation for successful end result.

Comments