Linux Disk Partitioning steps

Introduction

Disk partitioning is an important skill for every Linux Administrator. It allows you to divide a disk into separate sections and use them for different purposes, like storing data, system files, or swap space. In this blog, we will learn how to create, format, mount, and permanently mount partitions with simple steps. We will also cover some production tips and interview questions.

Key Concepts of Disk Partitioning

  • Partition: A logical division of a hard disk.
  • Primary Partition: Maximum of 4 primary partitions can exist.
  • Extended Partition: A container that can hold multiple logical partitions.
  • Logical Partition: Partitions created inside an extended partition.
  • Filesystem Types: ext4, xfs, btrfs, etc.
  • Mount Point: The directory where a partition is attached in the Linux filesystem.

Practical Steps

1. List Available Disks

lsblk
fdisk -l

2. Create a New Partition

sudo fdisk /dev/sdb
# Press 'n' for new partition
# Press 'p' for primary or 'e' for extended
# Choose partition number and size
# Press 'w' to save changes

3. Format the Partition

sudo mkfs.ext4 /dev/sdb1
# or for XFS
sudo mkfs.xfs /dev/sdb1

4. Mount the Partition

sudo mkdir /mnt/mydata
sudo mount /dev/sdb1 /mnt/mydata

5. Check Mounted Partition

df -h
mount | grep sdb1

6. Permanently Mount Partition

Edit the /etc/fstab file and add the entry:

/dev/sdb1   /mnt/mydata   ext4   defaults   0  2

Then run:

sudo mount -a

7. Remove (Unmount) a Partition

sudo umount /mnt/mydata

Tips and Tricks for Production Servers

  • Always take a backup before partitioning.
  • Use lsblk and blkid to verify device names carefully.
  • Prefer UUIDs instead of device names in /etc/fstab for stability.
  • For large filesystems, use xfs for better performance.
  • Keep a rescue ISO/boot disk handy in case of boot issues after fstab misconfiguration.

Common Interview Questions

  1. What is the difference between primary, extended, and logical partitions?
  2. What is the maximum number of primary partitions you can create?
  3. How do you mount a partition permanently?
  4. What is the role of the /etc/fstab file?
  5. Why should we use UUID instead of device names in fstab?
  6. How do you check filesystem errors and repair them?

Conclusion

Disk partitioning is one of the core skills of a Linux Administrator. Knowing how to safely create, mount, and manage partitions will make your servers stable and efficient. With practice, you will handle production systems confidently and perform well in interviews.

Leave a Reply

Your email address will not be published. Required fields are marked *