how to create a partition in linux

Mastering Partitions: A Step-by-Step Guide to Creating Linux Partitions

By Hannah Thompson
AD

In the world of Linux, partitions are essential facets that help manage and control your system's file structure and storage. Creating partitions in Linux allows you to allocate specific spaces for different uses, from separating data to installing multiple operating systems. This comprehensive guide will walk you through the process of creating partitions in Linux, ensuring both data safety and system integrity.

Before initiating the partitioning process, ensure you have a backup of all crucial data. While following the steps below, be meticulous and understand that incorrect partitioning can lead to data loss or even render your system unbootable.

Understanding Partition Schemes

The first step in creating partitions is understanding partition schemes. Two primary types of partitioning schemes exist: Master Boot Record (MBR) and GUID Partition Table (GPT). MBR was historically used, while GPT, introduced in the 1990s, is the more advanced and widely used scheme today.

AD
How to Create a Disk Partitions in Linux
How to Create a Disk Partitions in Linux
How to Check Disk Partitions: Exact Steps in This Pro Guide
How to Check Disk Partitions: Exact Steps in This Pro Guide
Run Windows and Linux: easy partitioning guide
Run Windows and Linux: easy partitioning guide

GPT supports larger disks, is more secure, and supports modern features like encryption and self-healing backups. For this guide, we'll focus on GPT, as it's the more modern and versatile scheme.

Identifying Your Disk

Beforeianas start creating partitions, you need to identify your disk. Open a terminal and use the `lsblk` command to list all available storage devices:

How to Create New Partitions in Linux - Make Tech Easier
How to Create New Partitions in Linux - Make Tech Easier
How to Create, Resize and Delete Linux Partitions With Cfdisk
How to Create, Resize and Delete Linux Partitions With Cfdisk
Linux Disk Partitioning & Mounting Guide (Step-by-Step)
Linux Disk Partitioning & Mounting Guide (Step-by-Step)

`lsblk`

Identify your disk, typically /dev/sda, /dev/sdb, etc. Be cautious and ensure you've identified the correct disk, as the following commands will alter data on this device.

AD

Partitioning Your Disk with fdisk

We'll use the `fdisk` utility to partition our disk. Replace 'your_disk' with your identified disk (e.g., /dev/sda):

How to resize a partition on Ubuntu
How to resize a partition on Ubuntu
How to Manage Disk Partitions in Linux With fdisk
How to Manage Disk Partitions in Linux With fdisk
How to Choose a Partition Scheme for Your Linux PC
How to Choose a Partition Scheme for Your Linux PC
How to Use Fdisk to Manage Partitions on Linux
How to Use Fdisk to Manage Partitions on Linux
How to Create, Resize and Delete Linux Partitions With Cfdisk
How to Create, Resize and Delete Linux Partitions With Cfdisk
How to Create a Partition on C Drive in windows 10/11 | Create a Storage Drive in Windows 11/10
How to Create a Partition on C Drive in windows 10/11 | Create a Storage Drive in Windows 11/10

`sudo fdisk /dev/your_disk`

This will open the `fdisk` interactive menu. Here's how to proceed:

AD
  • Press 'o' to create a new empty DOS partition table.
  • Press 'n' to add a new partition.
  • Press 'p' to create a primary partition.
  • Choose the partition number (1 for the first partition).
  • Select the default first and last sector using the 'Enter' key.
  • Press 'w' to write changes and exit.

Formatting Partition with mkfs

With our partition created, we need to format it using the `mkfs` command. Ensure you've selected the appropriate file system (e.g., ext4, NTFS, or FAT32 for compatibility with Windows):

3 Ways to Resize a Linux Partition Safely
3 Ways to Resize a Linux Partition Safely
Master Linux Special Permissions: SUID, SGID, and Sticky Bit
Master Linux Special Permissions: SUID, SGID, and Sticky Bit
How to Write to Windows Partition In Linux - Make Tech Easier
How to Write to Windows Partition In Linux - Make Tech Easier

`sudo mkfs -t your_file_system /dev/your_disk1`

e.g., `sudo mkfs -t ext4 /dev/sda1`

AD

Mounting the Partition

To access the newly created partition, mount it to a directory:

  • Create a directory to mount the partition: `sudo mkdir /mnt/new_partition`.
  • Mount the partition: `sudo mount /dev/your_disk1 /mnt/new_partition`.

Automatically Mounting Partition on Boot

To ensure your partition is mounted automatically every time your system boots, add an entry to the /etc/fstab file:

`echo "/dev/your_disk1 /mnt/new_partition your_file_system defaults 0 0" | sudo tee -a /etc/fstab`

Update 'your_disk1', 'mnt/new_partition', and 'your_file_system' with your specifics.

Congratulations! You've successfully created, formatted, mounted, and automated a Linux partition. Regularly review and manages your partitions to ensure optimal system performance and data integrity. Don't forget to explore other advanced topics, likeencrypted and LVM partitions, to further customize your Linux experience.

AD