Knowledge Base

Your Go-To Resource for Expert Insights and Solutions

How to Make Partitions on HDD, SSD, or NVMe Using fdisk and Format the Created Partitions Using mkfs Using Command Line

Creating partitions on your storage devices such as HDDs, SSDs, or NVMe drives is an essential task when managing your system's storage. This guide will show you how to use fdisk to create partitions and then use mkfs to format them. We'll cover partitioning with fdisk and formatting with the ext4 file system as an example. Other file systems like ntfs, xfs, and btrfs will also be mentioned.

Step 1: List Available Disks

Before creating partitions, you should first check the available storage devices. To list the devices attached to your system, use the following command:

Code copied to your clipboard!

The lsblk command will display all attached storage devices, including HDDs, SSDs, and NVMe drives, along with their partitions.

Step 2: Start Partitioning the Disk Using fdisk

Once you identify the disk you want to partition (e.g., /dev/sda), use fdisk to create partitions. Run the following command to start fdisk on the chosen disk:

Code copied to your clipboard!

In this case, replace /dev/sda with the actual disk name. Once in the fdisk interactive mode, you can create partitions.

Step 3: Create a New Partition

Inside the fdisk prompt, you can create a new partition by following these steps:

  • Type n to create a new partition.
  • Choose whether to create a primary or extended partition (usually p for primary).
  • Define the partition size.
  • Type w to write the changes and exit.

This process will create a new partition on the disk. You can repeat this process for additional partitions if needed.

Step 4: Format the Partition with mkfs

After creating the partition, you will need to format it with a file system. The most commonly used file systems are ext4, ntfs, xfs, and btrfs. To format the partition with ext4, use the following command:

Code copied to your clipboard!

Replace /dev/sda1 with the appropriate partition name. This will format the partition with the ext4 file system.

Other File System Types

Besides ext4, here are other common file systems you can use:

  • NTFS: Used for Windows systems. To format a partition with NTFS, use sudo mkfs.ntfs /dev/sda1.
  • XFS: A high-performance file system. To format with XFS, use sudo mkfs.xfs /dev/sda1.
  • BTRFS: A modern file system with advanced features. To format with BTRFS, use sudo mkfs.btrfs /dev/sda1.

Step 5: Verify the Partition and File System

To verify the new partition and its file system, you can use the lsblk or blkid commands:

Code copied to your clipboard!

Alternatively, to see detailed information, use:

Code copied to your clipboard!

This will display the partition information, including its file system type.

Step 6: Mount the Partition

Once the partition is created and formatted, you'll need to mount it to a directory in your system. Create a mount point:

Code copied to your clipboard!

Then mount the partition:

Code copied to your clipboard!

Replace /dev/sda1 with your partition name and /mnt/mydrive with your desired mount point.

Step 7: Make the Mount Permanent

If you want the partition to be mounted automatically after reboot, you need to add it to the /etc/fstab file. Open the file with a text editor:

Code copied to your clipboard!

Then add the following line:

Code copied to your clipboard!

Replace the partition name, mount point, and file system type if needed.

Conclusion

Creating and formatting partitions is a crucial step in setting up a new disk. By following these steps, you can create partitions using fdisk, format them with the file system of your choice using mkfs, and make them available for use in your system.

Related Articles

STAY TUNED
Image