How to Create Linux Disk Partition [3 Proven Methods]

Written by

Reviewed by

Last updated: June 26, 2024

Expert verified

SVG Image

TL;DR

To create Linux disk partition, follow these steps:

  1. Identify the target disk with sudo fdisk -l.
  2. Start modifying the disk’s partition table with sudo fdisk /dev/sda.
  3. Create a new partition, specify its type and size with n and configure as prompted.
  4. Define file system type and save the new partition table with t and then w to write changes.

Managing disk space on Linux can be tricky, but you’re in the right place to get it sorted. This post will show you how to create partition in Linux step-by-step, boost your system’s performance, and organize your data better. I’ll guide you through step-by-step methods using tools like fdisk, parted, and GParted. I’ll also tackle common errors and best practices to keep your partitions in great shape. By the end, you’ll have the confidence and knowledge to manage your disk partitions like a pro. Let’s get started!

What is Linux Disk Partitioning?

Disk partitioning is the process of dividing a hard drive or solid-state drive into smaller, separate sections called partitions. Each partition acts like a separate disk, allowing you to manage and organize your data more effectively.

Purpose of Disk Partitioning Linux:

  1. Organize Data: You can store different types of data in separate partitions. For example, keep your system files in one partition and your personal files in another.
  2. Improve Performance: By separating the operating system, applications, and data, you can reduce the read/write head movements on the disk, which can enhance performance.
  3. Increase Security: If you store sensitive information in a separate partition, it becomes easier to apply security measures like encryption. It also isolates the sensitive data from potential system crashes.
  4. Simplify Backup and Recovery: You can back up and restore individual partitions without affecting the others. This makes the process faster and more efficient.
  5. Multi-Boot Systems: Partitioning allows you to install and run multiple operating systems on the same disk. Each operating system can have its own partition.

By partitioning your disk, you gain more control over how your data is stored and managed, leading to a more organized and efficient computing experience.

How to Create Linux Disk Partition?

To create Linux disk partition, start by opening a terminal and using the fdisk command with your target disk, such as sudo fdisk /dev/sda. List existing partitions by typing p, then create a new partition by typing n and following the prompts to set the partition type and size.

Once done, write the changes to the disk by typing w. Finally, format the new partition with a file system, for example, sudo mkfs.ext4 /dev/sda1, and verify it using lsblk to confirm the partition was created successfully.

That was the quick answer. Here are the detailed steps for this method and two other methods to create Linux disk partition:

1. Creating Disk Partitions Using fdisk

fdisk is a powerful command-line tool used for creating and managing disk partitions on Linux. It provides precise control over the configuration of storage devices, making it ideal for systems administrators and users comfortable with terminal commands. Here is the step-by-step guide to create Linux disk partitions:

  1. Open Terminal.
open terminal
  1. Use fdisk to list all the disks and their partitions to find the disk you want to partition.
sudo fdisk -l

This command displays detailed information about all disks and partitions, helping you identify the target disk, such as /dev/sda.

listing disk and its partitions
primary disk and its partitions
  1. Start modifying the disk’s partition table by running the following command:
sudo fdisk /dev/sda

This command starts fdisk in interactive mode for the disk /dev/sda, allowing you to modify its partitions.

starting disk modification
  1. Create partition Linux by specifying its type, size, and position. To create a new partition:
n

This command initiates the process to add a new disk partition Linux.

creating new partition
  1. Set the partition number and sectors as prompted.
created new partition with default settings
  1. Define the file system type for the new partition:
t

This command allows you to change the system id of the partition.

changing file system type of partition
  1. Specify the type, like 20 for a Linux partition:
changing partition type to linux
  1. Save the new partition table to the disk:
w

This command writes the changes to the disk and exits fdisk, effectively creating the new partition.

saving the partition table to the disk

3. Creating Disk Partitions Using parted

parted is a command-line utility that allows you to manage disk partitions on Linux. It’s especially useful for creating, resizing, and deleting partitions. parted supports both MBR and GPT partitioning schemes and is ideal for users who need a flexible and powerful tool for disk management. Follow these steps to Linux create disk partition:

  1. Before you start, ensure that parted is installed on your system. This can be done using your package manager:
sudo apt-get install parted 

This command installs the parted utility, which you’ll use for disk partitioning.

installing parted on ubuntu
  1. Next, initialize the disk you want to partition by opening it with parted:
sudo parted /dev/sdX 

Replace /dev/sdX with your disk identifier (e.g., /dev/sda)

opening disk in parted utility

This command opens the specified disk in the parted utility, allowing you to manage its partitions.

  1. Create a new partition table if your disk does not have one or if you want to start fresh:
(parted) mklabel gpt           # Creates a GPT partition table on the disk

This command initializes the disk with a GPT partition table, preparing it for new partitions.

preparing disk for new partition
  1. Now, create a new partition on the disk:
(parted) mkpart primary ext4 0% 50%

This command creates a primary partition using the ext4 file system, spanning from 0% to 50% of the disk space.

creating primary partition using ext4 filesystem
  1. Finally, confirm that the new partition was created successfully:
lsblk 
viewing partition has been successfully created

4. Creating Disk Partitions Using GParted (GUI Method)

GParted is a powerful graphical tool for managing disk partitions on Linux. It provides an intuitive interface for creating, resizing, and deleting partitions, making it ideal for users who prefer a GUI over command-line tools.

  1. First, ensure GParted is installed on your system:
sudo apt-get install gparted

This command installs GParted, a graphical partition management tool.

installing gparted on ubuntu
  1. Launch GParted with root privileges:
sudo gparted

This command opens the GParted application, allowing you to manage your disk partitions through a GUI.

launching gparted with root privileges
  1. When GParted opens, select the disk you want to partition from the drop-down menu in the top-right corner.
opening drop down menu
  1. Navigate to the correct disk to ensure you are partitioning the intended device.
selecting disk to create a partition through gparted
  1. Select the unallocated space on your disk.
selecting unallocated space on disk
  1. Right-click and choose New.
selecting new option to initialize disk partitioning
  1. Specify the size, type (primary or logical), and file system (e.g., ext4) for the partition. Click Add.
specifying partition properties

These steps create a new partition in the unallocated space with your chosen settings.

  1. Select the partition you want to format. Right-click and choose Format to. Select the desired file system (e.g., ext4).
formatting the disk partition
  1. These steps format the selected partition with the specified file system.
  2. Confirm the new partition in both the GParted interface and using command-line tools:
lsblk
viewing partition has been successfully created 1

5 Common Partitioning Errors and Solutions

Partitioning a disk can sometimes lead to unexpected issues. Here are five common problems you might encounter while partitioning your Linux system, along with straightforward solutions to help you resolve them effectively.

  • 🛑 Unallocated Space Too Small: To create new partitions where space is insufficient, resize existing ones using GParted. This tool effectively shrinks other partitions, freeing up necessary space without losing data.
  • ⚠️ Cannot Write to Table: Errors such as “cannot write to partition table” occur when partitions are active. Use a live USB to manage partitions, which allows editing without interference from the system’s operations.
  • 🔄 Overlapping Partitions: Overlapping partitions cause data errors and loss. Adjust or resize these partitions using a partition editor to ensure that each has its distinct and non-overlapping segment on the disk.
  • 🛠️ File System Errors: For file system issues when formatting or accessing partitions, use the command fsck /dev/sda1. This checks and repairs the partition, ensuring it is free from errors and accessible.
  • 📊 Partition Table Full: On MBR disks limited to four primary partitions, convert one primary partition into an extended partition. This change allows for more logical partitions within the extended partition, expanding your capacity.

5 Disk Partition Maintenance Tips

Maintaining the health of disk partitions is crucial for system stability and data integrity. Regular checks and optimizations can significantly extend the life of your storage devices. Here are five effective tips to help you manage and maintain your disk partitions efficiently.

  • 🔄 Regularly Check for Errors: Use tools like fsck for Linux to scan and fix file system errors on your partitions regularly. This preventive measure helps avoid data corruption and system crashes.
  • 🧹 Clean Up Unnecessary Files: Regularly delete unnecessary files and uninstall unused applications to prevent your partitions from becoming too full. This prevents performance degradation due to overly full partitions.
  • 📊 Monitor Disk Usage: Regularly monitor your disk usage with tools like df and du. Keeping an eye on disk space usage helps you manage storage resources more effectively and plan for future expansions or clean-ups.
  • 🔧 Defragment Regularly: For partitions with file systems that tend to fragment (like NTFS), regularly defragment the disk. This optimizes file storage, improves access speed, and extends the life of the drive.
  • 🛡️ Backup Frequently: Always have a backup strategy in place. Regular backups of your important data protect against data loss in the event of disk failure or other hardware issues. Use automated backup solutions to ensure data is backed up consistently.

Linux Create Partition: Final Thoughts

In this guide, I’ve walked you through detailed steps for to create disk partition in Linux, using fdisk command. I’ve also covered how to handle common partitioning errors and shared best practices for maintaining partition health.

If you want to continue expanding your Linux skills, I suggest exploring into these related topics:

Frequently Asked Questions

Can I resize a partition without losing data?

Yes, you can resize a partition without losing data using tools like GParted or the resize2fs command for ext3/4 file systems. However, it’s crucial to backup your data before resizing as a precaution against any potential errors that might occur during the process.

How do I recover data from a deleted partition?

Recovering data from a deleted partition is possible with tools like TestDisk or PhotoRec. These tools scan the disk to find remnants of the deleted partition and attempt to restore files. Success depends on whether new data has overwritten the old data.

How do I choose the right file system for my Linux partitions?

Choosing the right file system for your Linux partitions depends on your needs. For general use, ext4 offers a good balance of performance and reliability. XFS and Btrfs are suitable for large data operations and systems requiring high reliability and scalability.

What is the impact of partition size on system performance?

The impact of partition size on system performance can be significant, especially for databases and applications that require high I/O throughput. Larger partitions can reduce the number of disk seeks and improve caching efficiency, leading to faster access times and overall improved system responsiveness.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

Discord Ping: How to Do it on Linux? [4 Simple Methods]

Next Post

How to Linux Format Disk Partitions? [3 Easy Methods]

Leave a Reply

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

Read next