Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Create and Manage Disk Partitions in Linux

Disk partitioning is a fundamental task when setting up or managing storage on a Linux system. It involves dividing a disk into one or more regions, each of which can be managed separately. This article will guide you through the process of creating and managing disk partitions in Linux using various command-line tools.

Understanding Disk Partitioning

Before diving into the commands, it's essential to understand the basics of disk partitioning. A disk partition is a logical division of a hard disk drive (HDD) or solid-state drive (SSD). Each partition can be formatted with a filesystem and used to store data independently.

Tools for Disk Partitioning in Linux

Several tools are available for disk partitioning in Linux, including:

  • fdisk: A command-line utility for creating and manipulating partition tables.
  • parted: A more advanced command-line utility that supports both MBR and GPT partition tables.
  • gparted: A graphical frontend to parted.

Example 1: Creating a Partition with fdisk

  1. List available disks:

    sudo fdisk -l

    This command lists all available disks and their current partitions.

  2. Select the disk to partition:

    sudo fdisk /dev/sda

    Replace /dev/sda with the appropriate disk identifier.

  3. Create a new partition:

    • Enter n to create a new partition.
    • Choose the partition type (primary or extended).
    • Specify the partition number, starting sector, and ending sector or size.
  4. Write changes to disk:

    • Enter w to write the changes and exit fdisk.
  5. Format the new partition:

    sudo mkfs.ext4 /dev/sda1

    Replace /dev/sda1 with the new partition identifier.

Example 2: Creating a Partition with parted

  1. Start parted with the desired disk:

    sudo parted /dev/sda
  2. Create a new partition table (optional):

    (parted) mklabel gpt

    Replace gpt with msdos for an MBR partition table if needed.

  3. Create a new partition:

    (parted) mkpart primary ext4 1MiB 100%

    This command creates a primary partition with the ext4 filesystem, spanning from 1MiB to the end of the disk.

  4. Exit parted:

    (parted) quit
  5. Format the new partition:

    sudo mkfs.ext4 /dev/sda1

    Replace /dev/sda1 with the new partition identifier.

Example 3: Managing Partitions with gparted

  1. Install gparted (if not already installed):

    sudo apt-get install gparted
  2. Launch gparted:

    sudo gparted
  3. Use the graphical interface to create, resize, move, and delete partitions as needed.

Conclusion

Disk partitioning in Linux is a critical skill for system administrators and users who need to manage storage effectively. Whether you prefer command-line tools like fdisk and parted or graphical tools like gparted, Linux offers robust utilities to handle all your partitioning needs.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.