Skip to main content

Partitioning Disks for Linux: A Comprehensive Guide

Partitioning Disks for Linux: A Comprehensive Guide Partitioning Disks for Linux: A Comprehensive Guide

Partitioning Disks for Linux: A Comprehensive Guide

Understanding Disk Partitioning

Disk partitioning is the process of dividing a hard disk into multiple logical sections, called partitions. Each partition functions as a separate disk, allowing you to organize data, manage resources, and install multiple operating systems on a single physical disk.

Types of Partitions

  • Primary Partitions: You can create up to four primary partitions on a single disk. Each primary partition can host a file system or an operating system.
  • Extended Partitions: An extended partition acts as a container for logical partitions. You can create one extended partition per disk, and within it, multiple logical partitions.
  • Logical Partitions: These reside within an extended partition and allow for more flexible disk organization. They function similarly to primary partitions but do not have the same limitations.

Common File Systems for Linux

  • ext4: The most widely used file system for Linux, known for its stability, performance, and support for large files.
  • XFS: A high-performance file system suitable for large volumes and parallel I/O operations.
  • Btrfs: Offers advanced features like snapshots, subvolumes, and RAID support, making it ideal for complex storage setups.

Tools for Disk Partitioning

  • GParted: A graphical partition editor that allows you to create, resize, and manage partitions using a user-friendly interface.
  • fdisk: A command-line utility for creating and managing disk partitions. It is suitable for MBR (Master Boot Record) disks.
  • parted: A versatile command-line tool that supports both MBR and GPT (GUID Partition Table) disks.

Steps for Partitioning Disks

Using GParted

  1. Install GParted: sudo apt-get install gparted
  2. Launch GParted: sudo gparted
  3. Select the Target Disk: Choose the disk you want to partition from the drop-down menu.
  4. Create a New Partition Table: Go to Device > Create Partition Table and select the partition table type (MBR or GPT).
  5. Create Partitions: Right-click on the unallocated space and select New. Configure the partition size, file system, and label. Repeat this step for additional partitions.
  6. Apply Changes: Click the green checkmark to apply the changes.

Using fdisk

  1. Launch fdisk: sudo fdisk /dev/sdX (Replace /dev/sdX with the target disk, e.g., /dev/sda).
  2. Create a New Partition:
    • Type n and press Enter.
    • Select the partition type (primary or extended).
    • Specify the partition number, starting sector, and size.
  3. Write Changes: Type w and press Enter to write the changes to the disk.

Using parted

  1. Launch parted: sudo parted /dev/sdX (Replace /dev/sdX with the target disk, e.g., /dev/sda).
  2. Create a New Partition Table: mklabel gpt
  3. Create Partitions:
    • mkpart primary ext4 1MiB 20GiB
    • mkpart primary linux-swap 20GiB 22GiB
    • mkpart primary ext4 22GiB 100%
  4. Quit parted: quit

Post-Partitioning Steps

  1. Format the Partitions:
    • sudo mkfs.ext4 /dev/sdX1
    • sudo mkfs.ext4 /dev/sdX3
    • sudo mkswap /dev/sdX2
  2. Mount the Partitions:
    • sudo mount /dev/sdX1 /mnt
    • sudo mkdir /mnt/home
    • sudo mount /dev/sdX3 /mnt/home
    • sudo swapon /dev/sdX2

© 2025 Linux Playground. All rights reserved.

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

Understanding the Sticky Bit and Its Role in File Security

Understanding the Sticky Bit and Its Role in File Security Understanding the Sticky Bit and Its Role in File Security File security is a critical aspect of managing any computing environment. Among the several mechanisms and permissions available to ensure files and directories are protected, the sticky bit is one of the lesser-known but powerful tools. This article aims to provide a comprehensive understanding of the sticky bit, how it functions, and its implications for file security. What is the Sticky Bit? The sticky bit is a permission setting that can be applied to files and directories in Unix and Unix-like operating systems such as Linux. Originally, it was used to indicate that a program's executable should be retained in memory after its initial execution to improve performance. However, this functionality has become largely obsolete with modern memory mana...