How To Create Partition In Linux Step By Step Centos/Redhat/Rhel

In the following steps i will show you how to create partitions in centos or rhel with fdisk command. Before creating partitions in Linux/centos/redhat/rhel, First know your hard drives information with lsblk command. lsblk command will show you all your hard drives details like their partitions size, type and their mount points.

Here you can see sdc hard drive doesn’t having any partitions and the size of sdc is 5G.

or you can use cat /proc/partitions command it will also display your hard drive details.

Create Partition With Fdisk Command:

To create partitions in your hard drive we use fdisk command.

syntax is fdisk   <hard-disk> and hit enter

after hitting enter it will ask you  commands to create partitions.

To create a new partitions we use the command ‘n’. So type n and hit enter. In the next step It will ask you partitions type like primary or extended, enter p or dont enter anything, just hit enter by default it will take primary. in the next step it  will ask you partition number, enter 1 or dont enter anything, just hit enter it will take 1 as by default. In the next step it will ask you first sector value, just hit enter or dont enter any values, by default it will take 2048.

in the next step it will ask you last sector size . Here we will mention size of our partitions. in my case i have 5 gb hard drive and making my first partition, so i will create 1 gb partition for that i need to enter +1G.

the syntax is      +numberG

if you want 2gb partition just enter +2G and hit enter.

Now we have created partition. To verify is our partitions created or not by typing p and hit enter. It will show you all partitions in your hard drive. Here my hard drive is /dev/sdc. Just now we have created one new partition,  you can see new partition /dev/sdc1 . We have created partition but it is not saved for that we need to enter w command. So type w and hit enter. Now we have successfully created partition /dev/sdc1 in hard-drive /dev/sdc.

Partprobe:

part probe command informs the OS kernel to re read the partitions in hard drive. Then our newly created partitions will become active.

partprobe <hard-drive>

Format partition: Making a filesystem

Now we have to format our partition. To format partition we use mkfs command

syntax is    mkfs.<file-system-type>   <partition>

We have formatted our newly created partition with ext4 file system.

Create Mount Point:

Now we have to mount our partition on any directory. For that i am creating one directory called decodingdevops.

you can create any directory.

Get UUID of Partition:

To mount our partition we have to edit /etc/fstab file. To edit that file first we need uuid of our newly created partition. To find uuid of any partition we use blkid command. ot will give you uuid of your partition and file system type.

blkid   /dev/sdc1

Add uuid Of Partition In /etc/fstab File:

Now we got our uuid of newly created partition.

syntax is  uuid=<uuid-number>   <mount directory>   <fileystme-type>   defaults   0 0

vi /etc/fstab

copy above line and add at the end of /etc/fstab file

last line you can  see i added uuid of of our newly partition /dev/sdc1

Mount The Partition:

now use mount -a command to mount.

mount -a command mounts all file systems from fstab file. Now verify the newly created partition with lsblk command.

You can see sdc1 is having 1 Gb space and mounted on /decodingdevops directory.

 

 

  • fdisk create partition,
  • fdisk linux
  • how to create partition in rhel 7
  • centos 7 create partition
  • redhat partition disk command line
  • centos create partition fdisk
  • how to create partition in centos 7