Tutorials  /  Linux Basics

Linux Disk Partitioning Made Easy: A Simple Tutorial

Ccentron Redaktion · October 2024 ·4 min read ·Linux Basics, Tutorial

Managing disk space efficiently can be essential for system stability, especially when running multiple operating systems or reserving disk space for specific purposes. In this guide, you will learn how to create a partition in Linux using the command-line utility fdisk. The process is straightforward, and partitions can help protect your data in case of disk failure.

To begin with, we will use the fdisk command, a powerful text-based utility that allows you to view and manage partitions on your system.

Viewing Existing Partitions

Before creating a new partition, it is necessary to identify the current layout of your disks. The following command lists all the partitions on your system:

Console
sudo fdisk -l

This command will request administrative privileges. Once entered, you will see a list of partitions similar to the output below:

Code
Disk /dev/loop0: 14.8 MiB, 15466496 bytes, 30208 sectors
...
VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Selecting a Disk for Partitioning

After reviewing the list of partitions, choose a disk where you wish to create the new partition. To begin partitioning, we need to enter the disk's path in the following command:

Console
sudo fdisk [disk path]

This brings us to the command mode of fdisk.

Once in the command mode, you can view the list of available actions by pressing m. The fdisk command mode interface can be confusing at first, but it’s manageable once you know the basic commands.

Creating the Partition

To create a new partition, use the n command. This will prompt you to choose the type of partition:

  • Press p to create a primary partition.
  • Press l if you want to create a logical partition.

For this tutorial, we will create a primary partition by selecting p. You will now be asked to specify the starting and ending sectors of the partition.

To use the default starting sector, press ENTER. You can either use all available space or specify the size of the partition. In this example, we are creating a partition of 10 MB:

Code
+10M

Changing the Partition Type

By default, Linux assigns the "Linux" partition type. If you need to change it, you can use the t command. For example, if you want to set the partition to "Linux LVM", you will be prompted to enter the HEX code for that partition type.

If you don't remember the HEX code, press L to list all available codes. For "Linux LVM," the code is 8e. Enter this code to confirm the partition type.

Verifying and Saving the Changes

Once all your changes are set, it’s a good idea to verify them. You can list the partitions again with the p command to confirm everything is as expected.

To make the changes permanent, press w to write the partition to the disk. If you change your mind and don’t want to save the new partition, press q to exit without saving.

Formatting the Partition

After creating the partition, it is highly recommended to format it. This ensures the partition is ready for use and avoids potential issues. Use the following command to format the partition to the ext4 file system:

Console
sudo mkfs.ext4 [partition path]

Conclusion

Partitioning your disk in Linux is a great way to allocate space for specific tasks or install multiple operating systems. Using the fdisk tool, you can easily create, modify, and manage partitions to suit your needs. Each partition acts as a separate disk, which helps minimize damage if one partition becomes corrupted.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren