Skip to main content

Using fdisk and parted: A Comprehensive Guide

Using fdisk and parted: A Comprehensive Guide Using fdisk and parted: A Comprehensive Guide

Using fdisk and parted: A Comprehensive Guide

When managing disk partitions in a Linux environment, two of the most commonly used tools are fdisk and parted. These command-line utilities offer robust functionality for creating, resizing, deleting, and managing disk partitions. This guide will provide a thorough overview of both tools, including their installation, usage, and key features.

Introduction to fdisk and parted

fdisk: This is a powerful disk partitioning utility available in Unix-like operating systems. It allows users to manipulate disk partition tables and is particularly useful for managing MBR (Master Boot Record) partitions.

parted: This tool is designed to handle both MBR and GPT (GUID Partition Table) disks, offering more flexibility than fdisk when it comes to modern storage devices. It also has a more user-friendly interface and supports a broader range of disk operations.

Installing fdisk and parted

Most Linux distributions come with fdisk pre-installed. If it's not available, you can install it using the following commands:

For Debian/Ubuntu-based systems:

sudo apt-get install fdisk
        

For Red Hat/CentOS-based systems:

sudo yum install fdisk
        

To install parted, use the following commands:

For Debian/Ubuntu-based systems:

sudo apt-get install parted
        

For Red Hat/CentOS-based systems:

sudo yum install parted
        

Using fdisk

1. Listing Disk Information

sudo fdisk -l
        

2. Creating a New Partition

sudo fdisk /dev/sda
        

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

  • Press n to create a new partition.
  • Choose the partition type (primary or extended).
  • Specify the partition number and size.
  • Write the changes to the disk by pressing w.

3. Deleting a Partition

sudo fdisk /dev/sda
        

Inside the fdisk prompt:

  • Press d to delete a partition.
  • Enter the partition number to delete.
  • Write the changes to the disk by pressing w.

Using parted

1. Listing Disk Information

sudo parted -l
        

2. Creating a New Partition

sudo parted /dev/sda
        

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

  • Enter mklabel followed by the label type (e.g., gpt or msdos).
  • Use the mkpart command to create a partition, specifying the type (e.g., primary), file system (e.g., ext4), and the start and end points of the partition.

3. Resizing a Partition

sudo parted /dev/sda
        

Inside the parted prompt:

  • Use the resizepart command, specifying the partition number and the new end point.

4. Deleting a Partition

sudo parted /dev/sda
        

Inside the parted prompt:

  • Use the rm command followed by the partition number.

Conclusion

Both fdisk and parted are essential tools for managing disk partitions in a Linux environment. While fdisk is great for handling MBR partitions, parted offers more versatility with its support for both MBR and GPT. By understanding how to use these tools, you can effectively manage your disk partitions and optimize your system's storage.

Comments

Popular posts from this blog

Configuring Network Interfaces

Configuring Network Interfaces Configuring Network Interfaces Configuring network interfaces is a critical task for both system administrators and enthusiasts looking to optimize the performance and security of their networked devices. Network interfaces are the gateways that connect a device to a network, whether it's a local area network (LAN), wide area network (WAN), or the internet. This article will delve into the essential steps and considerations for configuring network interfaces across various operating systems and environments. Understanding Network Interfaces A network interface can be either physical, like an Ethernet port, or virtual, like those used in virtual machines or containers. Each network interface has a unique Media Access Control (MAC) address and can be assigned an IP address. Proper configuration ensures efficient data transmission, network security, and optimal performance. Steps to Config...

Creating and Managing Partitions

Creating and Managing Partitions Creating and Managing Partitions Creating and managing partitions on a computer is essential for optimizing storage, improving system performance, and efficiently organizing files. Partitions divide a physical hard drive into multiple logical sections, allowing different types of data to be stored separately. This article provides a comprehensive guide on creating and managing partitions. Understanding Partitions A partition is a logical division of a physical hard drive that allows you to treat each partition as a separate storage unit. There are several types of partitions: Primary Partition : The main partition that contains the operating system (OS). Extended Partition : A container that can hold multiple logical partitions. Logical Partition : Sub-divisions within an extended partition used for additional storag...

Understanding sudo and su: A Comprehensive Guide

Understanding sudo and su: A Comprehensive Guide Understanding sudo and su : A Comprehensive Guide What is sudo ? The sudo (superuser do) command allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. Essentially, sudo grants temporary administrative privileges to perform a specific task. Key Features of sudo : Granular Control: sudo allows system administrators to delegate limited root access to users, specifying exactly which commands they are permitted to run. Auditability: Every use of sudo is logged, providing a clear trail of who used sudo , what commands were executed, and when. Temporary Elevation: sudo grants elevated privileges for the duration of a single command, reducing the risk of accidental system-wide changes. Sec...