Wednesday, January 31, 2018

How to create a partition using fdisk in Linux.

In this article we would use fdisk to create and manage partition. This article assumes that you have a new hard disk (or at least empty space on a current hard drive where you can add a new partition).

Create a new partition of 100 MB using fdisk, format it with ext4 filesystem, and configure it on the /test1 directory in /etc/fstab so that the new partition is properly mounted the next time you boot Linux.


As you have learnt from previous article fdisk command need hard disk mount point as argument. Check hard disk mount point


Start fdisk command.


At the fdisk command line prompt, start with the print command (p) to print the partition table. This allows you to review the current entries in the partition table. As discuss in previous article it is not necessary to switch off DOS mode. So it is up to you whether you want to follow the recommendations or not. If you want to follow the recommendations execute following command or if you want to ignore the recommendation skip this


you could have up to four primary partitions, which would correspond to numbers 1 through 4. If you need more partitions you could re designated one partition as an extended partition. After re designated you could create logical partitions form extended partition. fdisk now supports the creation of more than 16 partitions on a drive. The remaining partitions are logical partitions, numbered 5 and above.

To create new partition type n press enter
If free space is available, fdisk normally starts the new partition at the first available sector or cylinder. The actual size of the partition depends on disk geometry. Press enter of First cylinder line


give the size of partition. Keep notice of format size. it is a + sign followed by size . K = Kilobyte M = Megabyte, G= Gigabyte . We want to create 100MB partition so give +100MB and press enter


to save and exit type w and press enter
You may get temporary fail error if another partition on that drive has been formatted and mounted.


From command prompt you could try with partprobe command if linux is able to unmount existing partition it would return with success or if it is failed it would return with busy error message.


If you got failed message reboot system to take effect.


After reboot login back with root and use fdisk command with -l switch


After new partition  created successfully /dev/sda6 but we would not be able to use it. Because it does not contains any filesystem. To make it useable we need to format it first. ext3 was the default filesystem of RHEL5. From RHEL6 ext4 is the default filesystem. with ext4 means that filesystems can be as large as 1 exabyte (EB). with ext3 it was just 16 terabytes (TB). The ext4 filesystem reduces fragmentation, guarantees space for files, supports faster checks, and more. It even supports file timestamps in nanoseconds. it is proven technology. Given its speed and reliability, Red Hat even uses ext4 as the default filesystem for partitions dedicated to the /boot directory. you can format it to the ext4 filesystem using one of the following commands:

# mkfs -t ext4 /dev/sda6
# mke2fs -t ext4 /dev/sda6
# mkfs.ext4 /dev/sda6


Now create a mount point as per the requirement. Mount partition and test it. 
#mkdir /manish

To mount this partition permanently open /etc/fstab make a entry for this partition in end of file
#/dev/sda6 /manish ext4 defaults 0 0

 Now we can reboot system to test and check mounted partition

1 comment:

Configure NFS Client

This example is based on the environment below. +----------------------+           |           +----------------------+ | [...