How to create a partition in linux

How to create a partition in linux

In this post i am going to explain a basic task of linux administration, (i.e) how to create a partition in linux operating system. Every Linux/System admin should know how to create a partition in linux. I have explained how to do that with step by steps and screenshots. In earlier post we have learned about Changing Mount Point In Linux and how to mount a pen drive / External hard disk in linux.

Creating partition is common in most of the linux flavors like Redhat, CentOS, fedora, Ubuntu and etc. I have created partition in Redhat linux flavor.

How to create a partition in linux

 

Step 1: Check mounted and currently created partitions

It is very good habit to check what are the mounted and currently available partition’s before creating a new partition. Use df -Th or mount command to check the currently mounted partitions. Use fdisk -l command to view the currently created partitions in linux.

#df -TH
#fdisk – l

From the output of fdisk -l command we can conform that we are having one hard disk “/dev/sda” with 500GB of space in it and it’s currently having 7 partitions.

How to create a partition in linux

Step 2: create a partition and save the changes.

Now the actual part begins. we are going to create a partition in “/dev/sda” 500 GB Hard disk(HDD). My task is to create a 10 GB of partition in /dev/sda and mount it in folder /Database.

Give fdisk /dev/sda in the command prompt. If it is a new hard disk it will ask you to like “press e for extended (or) p for primary partition” keep in mind that a hard disk can only have 4 partition if all the 4 are primary partitions and a hard disk can have n number of partitions if it is having 3 primary partition and 1 extended partition. In the one 1 extended partition we can create n number of partitions.

Okay let’s back in to the track.After hitting command /dev/sda press ‘n’ to create a new partition. Then it will ask for starting and ending cylinder value blindly hit enter for that. Then give partition size as like +<size>G or +<size>M or +<size>K, G stands for GB, M stands for MB and K stands for KB. Once it is done press enter then press w and enter to save the changes. Hit partprobe to update OS regarding the changes happened in the partition table. If you have downtime approved reboot your machine to update every thing properly.

How to create a partition in linux

Step 3: Make filesystem and mount in a folder.

To make ext3 filesystem use mkfs.ext3 or if you want to create ext2 filesystem use mkfs.ext2. Here i am creating ext3 filesystem for the partition /dev/sda8.
#mkfs.ext3 /dev/sda8

Once the filesystem is created for the the partition /dev/sda8. Create the desire folder and mount the partition in it.

#mkdir /Database
#mount /dev/sda8/DatabaseHow to create a partition in linux

Step 4: Mount the partition /Database permanently

To mount the partition and make the changes permanently (i.e) even after reboot add the partition details in /etc/fstab file. Give reboot command and check whether the partition is mounted permanently or not.

#vi /etc/fstab

How to create a partition in linux




Leave a Reply

Your email address will not be published. Required fields are marked *