Linux system administration: Which command-line utility is used to create, delete, and modify disk partitions on a hard drive (for example, preparing a new disk before making filesystems)?

Difficulty: Easy

Correct Answer: fdisk

Explanation:


Introduction / Context:
Before a Linux system can format a filesystem or mount storage, the disk must be partitioned. Partitioning defines start and end sectors for one or more logical areas on a physical drive. The traditional utility for this task on MBR-style disks is fdisk, which provides interactive commands to add, delete, and change partition types.



Given Data / Assumptions:

  • The question is about partitioning, not formatting or checking filesystems.
  • A standard Linux environment is assumed with common administrative tools present.
  • No specific partition table type is mandated (fdisk primarily targets MBR; many builds can also handle GPT, though gdisk/parted are often preferred for GPT).


Concept / Approach:

Partitioning precedes filesystem creation. The correct tool must manipulate the disk’s partition table. fdisk edits partition entries at the block device level, allowing administrators to create primary/extended/logical partitions and set partition types and bootable flags.



Step-by-Step Solution:

Identify the disk to partition (for example, /dev/sda or /dev/nvme0n1).Run fdisk /dev/sda to open the interactive editor.Use p to print the current partition table and n to create a new partition.Select partition number, start sector, and size (for example, +20G).Write changes with w, then create a filesystem (for example, mkfs.ext4 /dev/sda1) and mount.


Verification / Alternative check:

Verify with lsblk, blkid, or fdisk -l that the partition table reflects your changes. Try mounting the new partition to ensure it is accessible after creating a filesystem.



Why Other Options Are Wrong:

a: mkfs creates a filesystem inside a partition; it does not partition the disk.

c: fsck checks and repairs an existing filesystem; it does not edit a partition table.

d: mount attaches an existing filesystem to the directory tree; it does not create partitions.

e: Not applicable since fdisk is correct for partitioning.



Common Pitfalls:

Confusing partitioning with formatting, writing changes to the wrong device, and forgetting to update /etc/fstab for persistent mounts. Always back up critical data before changing partitions.



Final Answer:

fdisk

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion