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

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

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

Special File Permissions: setuid and setgid

Special File Permissions: setuid and setgid Special File Permissions: setuid and setgid Setuid (Set User ID) The setuid permission is used primarily for executable files. When setuid is applied to a file, it allows users to run the file with the file owner's privileges. This is particularly useful for executing programs that require higher privileges to perform certain operations. How It Works When a user executes a setuid program, the operating system sets the effective user ID of the process to that of the file owner. Example -rwsr-xr-x 1 root root 53232 Jan 14 09:32 /usr/bin/passwd The passwd command, used to change user passwords, typically has the setuid bit set. This allows it to modify system password files which are normally only accessible by the root user. ...