Hi Guys, today we will learn how to create a new partition on a Linux Server using fdisk command.
We have added the HDD in the Oracle Virtual Box, you can find the screenshot of that.
So, now we will start the server and use the “fdisk -l” command to check whether the Hard drive is added or not.
So, we can see the added disk in our server now which is of 4 GB, as we can see that the disk is mentioned like “/dev/sdb”.
Now we will use “fdisk /dev/sdb” command to make the partition.
Now we will press the “m” option to check the available options into the fdisk commands.
So, we can see a lot of options in the fdisk command, let’s discuss some of them.
- n: To create a new partition.
- p: To print the partition on the table.
- q: To quit without saving the changes.
- t: To change the file system types, there is a different ID for the different file systems.
- w: To write changes in the disk and exit from the fdisk terminal.
- d: To delete the partition of the disk.
Lets see how we can use this following options to create a partition.
STEP 1: We have used “n option” to create a new partition.
STEP 2: We have to select the partition type by pressing “p”.
We can create a 4 primary partition only, 3 primary and 1 extended, and in extended we can create many partitions.
STEP 3: Select the Partition Number as “1”.
STEP 4: Select the First Sector of the drive which is by default 2048.
I have just press enter while for the First Sector of the Drive and it takes the default value is 2048.
We can also mention our first Sector.
STEP 5: Select the Last partition of the disk, in that you can select the size in KB, MB, and GB.
In the above example we have select +2 GB, So, from the first sector, it will take till that sector which has the size till 2 GB.
STEP 6: We will write the changes in the Disk by using “w” option.
So, you can check that by using p option which is mainly used to print disk partitions.
While using the print option you guys can see that our first sector is 2048 and the last sector is 4196351.
So, guys we can say that the 2 GB size contains 2097152 blocks.
STEP 7: We will format the created Partition /dev/sdb1
Command: #mkfs.xfs /dev/sdb1
So, we have used the above command to format the partition and the file system type that we have chosen is xfs.
STEP 8: We will mount the partition so, that we can use the created partition.
# mount /dev/sdb1 /mnt
So, now I have mounted my created partition into the /mnt folder.
If we have to use this drive we will go to /mnt folder and keep our required data
We can check our mounted partition by using following commands.
Command: # lsblk
Command: # df -h
Now we have successfully created our new partition in Linux
Suppose, we have restarted the server then this mount partition will disappear, so for the permanent mounting, we have to do the entry in the /etc/fstab file.
fstab entry in Linux
So, Let’s learn about the fstab entry in Linux, to make the Entry we need the block ID we will use blkid command.
Command: # blkid /dev/sdb1
So, by this command, we will get the UUID (Universally Unique Identifier) that we will use in our /etc/fstab file
#vim /etc/fstab and make entry of the new created partition.
There are six entries in fstab file in Linux.
- Device: The device that you have to be mounted on a mount point, you can also use block name (/dev/sda) or the remote filesystem to mount the disk instead of UUID.
- Mount Point: This field defines where your device will be mounted. So that you can access the disk and keep your required data.
- File System Type: These fields require the file system type like ext3, ext4, xfs, and many more file systems like this.
- Mount options: Mount options are like rw, suid, dev, auto, exec, nouser, and async. All options come under the default category and you can use one also.
- File system dumped: This field defines, whether we have to take the dump of the file system. There is only two option 0 and 1. 0 means don’t dump and 1 is to take the Dump, this work when we have any dump program is installed.
- fsck: Check the file system at the time of booting. There are three options 0, 1, and 2. 0 means it will not perform the operation of fsck, 1 means it will be defined for the root only, and 2 is for others file system check.
fdisk change partition id
We will use “t option” to change the ID of partition for the Disk. After that use the L option to see more options for the File System.
We will choose 7 from this list because it is for the NTFS file system type which is used for windows.
So, by type 7 we have to change the type of the file system from 83 to 7. 83 is for the Linux.
So, by using option p we can see that our ID has been changed.
After that just save the file and format the partition by mkfs command
Command: # mkfs.ntfs /dev/sda1
Cheat Sheet to Creating a Partition
Find more detail regarding fstab.
Thank you Guys to read this article keep supporting.
create a partition in linux, create a partition in ubuntu, create a new partition in Linux