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 Partition a Disk in Linux Using Command Line Tools

Partitioning a disk is a crucial step in setting up a Linux system, allowing you to organize data, optimize performance, and manage storage effectively. In Linux, disk partitioning can be done using various command-line tools such as fdisk, parted, and gdisk. This article will guide you through the process of partitioning a disk using these tools.

Examples:

Using fdisk

fdisk is a powerful and widely-used command-line utility for managing disk partitions in Linux. Here’s how you can use it:

  1. List Available Disks: First, identify the disk you want to partition. Use the lsblk or fdisk -l command to list all available disks and their partitions.

    sudo lsblk
  2. Start fdisk: Begin by launching fdisk on the desired disk (e.g., /dev/sda).

    sudo fdisk /dev/sda
  3. Create a New Partition:

    • Type n to create a new partition.
    • Choose the partition type (primary or extended).
    • Specify the partition number, starting sector, and size.
  4. Write Changes: After creating the partitions, type w to write the changes to the disk.

  5. Verify Changes: Use lsblk or fdisk -l again to verify the new partition layout.

Using parted

parted is another versatile tool for disk partitioning, especially useful for handling large disks and GPT partition tables.

  1. Start parted:

    sudo parted /dev/sda
  2. Create a New Partition Table: If needed, create a new partition table (e.g., GPT).

    (parted) mklabel gpt
  3. Create a Partition: Use the mkpart command to create a new partition.

    (parted) mkpart primary ext4 1MiB 100%
  4. Exit parted: Type quit to exit.

  5. Format the Partition: Format the new partition with a file system, such as ext4.

    sudo mkfs.ext4 /dev/sda1

Using gdisk

gdisk is similar to fdisk but is used for GPT partition tables.

  1. Start gdisk:

    sudo gdisk /dev/sda
  2. Create a New Partition:

    • Type n to create a new partition.
    • Follow the prompts to specify the partition number, first sector, and last sector or size.
  3. Write Changes: Type w to write the changes to the disk.

  4. Verify Changes: Use lsblk or gdisk -l to verify the partition layout.

Conclusion

Partitioning a disk in Linux using command-line tools like fdisk, parted, and gdisk is a straightforward process once you understand the basic steps. Each tool has its strengths, so choose the one that best fits your needs based on the disk type and your familiarity with the tool.

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.