fdisk's Examples

the above command is used to view all partitions in the system

fdisk -l

view partition on a specific disk

fdisk -l /dev/etc

it check size of the partition of the partitonn 

fdisk -s /dev/sda

This lists all available disks, partitions, their sizes, and filesystem types.

 

sudo fdisk -l

This displays partition details only for /dev/sda.

sudo fdisk -l /dev/sda

This opens /dev/sdb in fdisk interactive mode for partitioning.

sudo fdisk /dev/sdb

Inside the fdisk prompt:

  • Press n (new partition)
  • Choose partition type (p for primary, e for extended)
  • Set partition number (e.g., 1)
  • Define the first and last sector (default is full size)
  • Press w to save changes

sudo fdisk /dev/sdb

Inside the fdisk prompt:

  • Press d (delete partition)
  • Select partition number to delete
  • Press w to save changes

sudo fdisk /dev/sdb

Inside the fdisk prompt:

  • Press t (change type)
  • Select partition number
  • Enter the partition type code (e.g., 83 for Linux, 82 for swap)
  • Press w to save changes

sudo fdisk /dev/sdb

  • Inside fdisk, press p to print the partition table.
  • If satisfied, press w to save changes.
  • If not, press q to quit without saving.

sudo fdisk /dev/sdb

This formats partition /dev/sdb1 as an ext4 filesystem.

sudo mkfs.ext4 /dev/sdb1

This turns /dev/sdb2 into a swap partition and enables it.

sudo mkswap /dev/sdb2
sudo swapon /dev/sdb2

Run fdisk to Delete and Recreate Partition with the Same Start Sector:

sudo fdisk /dev/sdb

Inside fdisk:

  • Press d to delete the partition.
  • Press n to create a new partition.
  • Set the same start sector but adjust the end sector.
  • Press w to save changes.

Resize the Filesystem:

sudo resize2fs /dev/sdb1

sudo umount /dev/sdb1

A tool to manipulate disk partitions.

sudo fdisk /dev/sda

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us