Disk Partitioing Using Fdisk Command | RHEL 7


how to create disk partition in linux using  fdisk command

Today we will see how can we create a disk partition in Redhat Linux 7 in command line. We also configure our new partition permanent in our system. For this I am using Redhat Enterprise Linux 8. Please follow the steps mentioned below in order to create a partition in redhat system.

1) First of all we have to check the size of the current mounted hard disk in our Redhat machine. if you dont have enough size in your current hard disk you can add/mount any secondary hard disk to your system.

use below command to check the mounted hard disk & their partitions with available space in it.

$fdisk -l (see pic 1)


Disk Partitioing Using Fdisk Command | RHEL 7
pic 1

As you can see in above picture that I have installed two hard disk in my system , sda & sdb . And you can see that sda have two further partitions sda1 & sda2 and sdb have one partition sdb1. This is the way in linux that the partitions are managed.

I have installed second hard disk (sdb) for our lab test. To create a partition first of all I have to delete the partition (sdb1) from our second hard disk (sdb). For this just follow the instructions as below.

> Run below command  in order to format second hard disk (sdb).

# fdisk -uc /dev/sdb


Disk Partitioing Using Fdisk Command | RHEL 7


> As you see in above pic the command says to press 'm' for help. so just press 'm'

> You will get options as shown in below pic 3.



disk partitioning
pic 3


> Press 'd' for delete the partition & 'w' to write changes & exit.


Disk Partitioing Using Fdisk Command | RHEL 7



Disk Partitioing Using Fdisk Command | RHEL 7



> Now our partitions from sdb drive has been deleted & we are ready to create an new fresh partition on that drive.For this just run below command again.

# fdisk -uc /dev/sdb

Press 'm' for menu options , then press 'n' for create a new partitions.


Disk Partitioing Using Fdisk Command | RHEL 7


As in above pic you can see that we have to options to create partitions 'primary' or 'extended'. basically we can only create 4 primary partitions in our hardisk. right now in our hard disk we have ( 4 free ) primary partitions to create.

- so press 'p' for primary partition.
-then select the partition number between 1-4 or enter for default.
-then enter the first sector value (just press enter for default)
-then we have to enter the last sector value for our partition.
-for this we have to enter the size for our partition.
-enter value followed by KB,MB,GB see below example.


  
-I have entered +1G value for creating 1GB parition.
-Then press 'm' for menu options.
-Type 'w' to write partition to disk & exit.

Now partition has been created to disk sdb drive. Now we have to format our drive. For this follow below steps.

- Run mkfs.ext4 /dev/sdb1 command to format the partition


-Now you can  mount your partition (sdb1) to any where in your system.use mount command to do the same.

#mount /dev/sdb1 /path of folder where to mount partition


But this is the temporary solution to mount if you restart the system your mount partition will be unmounted. To make partition mounted permanent we will add the partition information to /etc/fstab file. below are the steps to do the same.

- First check the UUID of the partition that you want to make it permanent. for this just run block id command as shown below.

#blkid


-Find the partition (sdb1) and copy the UUID of that partition. Here we have to copy the UUID of /dev/sdb1

-Now open the /etc/fstab file with any editor and add new line shown below.


-To edit the label of your system partition, you can use tune2fs command. run below command to edit the label.

#tune2fs -L 'specify the name' /dev/sdb1


Now you can restart the system or use any command to reload the file partition table in system. here i am using partprobe

#partprobe /dev/sdb


That All



Sharing is Caring 😀












Post a Comment

0 Comments