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...

ACLs: Access Control Lists

ACLs: Access Control Lists ACLs: Access Control Lists Introduction Access Control Lists (ACLs) are a fundamental aspect of network security and management, crucial for ensuring that only authorized users have access to specific resources within a network. As networks become more complex, ACLs serve as a vital tool for administrators to control the flow of traffic and enforce security policies. What Are ACLs? An Access Control List is a set of rules that dictate what kind of traffic is allowed to enter or exit a network. These rules are applied to network devices such as routers and switches to control the movement of data packets. Each rule within an ACL specifies whether to permit or deny traffic based on criteria such as source and destination IP addresses, protocol types, and port numbers. Types of ACLs Standard ACLs These ACLs filter traffic based only on the source IP address. They are simpler bu...

Using ping, traceroute, and netstat for Network Diagnostics

Using ping, traceroute, and netstat for Network Diagnostics Using ping, traceroute, and netstat for Network Diagnostics In the complex world of networking, diagnosing and troubleshooting issues is essential for maintaining a healthy and efficient network. Three fundamental tools often used for these purposes are ping , traceroute , and netstat . Each of these utilities offers unique insights into network performance and connectivity. Let's dive into their functionalities, use cases, and how they can be employed effectively. 1. Ping: Checking Connectivity and Latency The ping command is one of the most straightforward and commonly used network diagnostic tools. It tests the reachability of a host on an Internet Protocol (IP) network and measures the round-trip time for messages sent from the source to a destination computer. How It Works: The ping command sends Inte...