Skip to content
Home » Manage your Linux disk partitions like a pro with fdisk

Manage your Linux disk partitions like a pro with fdisk

Fdisk is a command-line tool that is used to create, modify, and delete disk partitions on a Linux system. If you’re new to Linux, understanding fdisk can be intimidating. But don’t worry – we’ll take you through the basics in this guide.

What is a Disk Partition?

A disk partition is a logical division of a hard drive. You can create multiple partitions on a single hard drive, and each partition can have its own file system and data. In Linux, disk partitions are represented by device files with a number appended to the end. For example, the first partition on the first hard disk is represented by /dev/sda1.

Getting Started with Fdisk

Before we dive into the commands and use-cases of fdisk, it’s important to understand how to use fdisk on a Linux system. Here are some basic commands to get started:

sudo apt install fdisk    # for Debian-based systems
sudo dnf install fdisk    # for Red Hat-based systems

Once fdisk is installed, you can use it to manipulate partitions on a hard drive. To start, you need to understand disk devices and disk partitions.

Understanding Disk Devices and Disk Partitions

A disk device in Linux is represented by a device file, which can be found in the /dev directory. For example, the first hard disk on a Linux system is represented by /dev/sda.

Basic Commands in Fdisk

Here are some basic commands in fdisk:

sudo fdisk /dev/sda   # open fdisk for editing /dev/sda

n    # create a new partition
p    # select primary partition
[default for first sector]    # start partition at default sector
[default for last sector]     # end partition at default sector
w    # write changes to disk

This example creates a new primary partition on the first hard disk (/dev/sda). Once you’ve created a partition, you can format it with a file system like ext4 using the mkfs command.

Leave a Reply

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

seventeen − 4 =