DEV Community

Cover image for 🖥️ Disk Partitioning Guide 🚀
Satyam Ahirrao
Satyam Ahirrao

Posted on

🖥️ Disk Partitioning Guide 🚀

🚀 Introduction

Storage management is a critical skill for every Linux administrator. Whether you're setting up a new server, managing cloud storage, or optimizing disk space, understanding disk partitioning is essential. From identifying different storage types to formatting and mounting partitions, this guide will walk you through the entire process in a simple and efficient way.

Image description

By the end of this guide, you'll be able to:
✅ Identify and analyze disk storage
✅ Create and format partitions with confidence
✅ Mount and manage partitions like a pro

Let's dive in! 🏗️💽

🗄️ Types of Storage

  • DAS (Direct Attached Storage) 🖴 - Directly connected to a single server.
  • NAS (Network Attached Storage) 🌐 - Shared over a network.
  • SAN (Storage Area Network) 🏗️ - High-speed storage network.
  • LVM (Logical Volume Manager) 🔄 - Flexible partition management.

🔧 Disk Naming in Linux 🏷️

  • Old HDDs (IDE): /dev/hda 🏛️
  • Newer Disks (SCSI/SAS): /dev/sda 🆕
  • Xen Hypervisor Disks: /dev/xvda 🖥️
  • KVM/QEMU Disks: /dev/vda 🎭
  • Multipath Disks: /dev/mpath 🔗
  • NVMe SSDs: /dev/nvme0n1

👀 Disk names are assigned by the kernel and can be managed via /etc/udev/rules

🔍 Checking Disk Information 🏗️

  1. List all block devices 🗂️
   lsblk -f
Enter fullscreen mode Exit fullscreen mode
  1. View partition table 📜
   sudo fdisk -l
Enter fullscreen mode Exit fullscreen mode
  1. Check free space 📊
   parted /dev/sda print free
Enter fullscreen mode Exit fullscreen mode

🛠️ Creating a Partition ⚙️

  1. Open fdisk:
   fdisk /dev/sda
Enter fullscreen mode Exit fullscreen mode
  1. Press m for help 🆘
  2. Press n to create a new partition ➕
  3. Choose partition type:
    • MSDOS (Legacy) 🏛️
      • Max disk size: 8TB
      • Max partition size: 2TB (use extended partitions)
    • GPT (Modern) 🚀
      • Supports larger disks and more partitions
  4. Save changes with w 💾

🔄 Updating Kernel with New Partition 🖥️

partx -a /dev/sda
partprobe -s
Enter fullscreen mode Exit fullscreen mode

If errors occur, reboot with:

init 6
Enter fullscreen mode Exit fullscreen mode

📝 Formatting the Partition 🗄️

  1. Check available filesystems:
   mkfs + [Tab]
Enter fullscreen mode Exit fullscreen mode
  1. Create a filesystem (example ext4):
   mkfs.ext4 /dev/sda3
Enter fullscreen mode Exit fullscreen mode

📌 Mounting the Partition 🏠

  1. Create a mount point:
   mkdir /apppart3
Enter fullscreen mode Exit fullscreen mode
  1. Mount temporarily:
   mount /dev/sda3 /apppart3
Enter fullscreen mode Exit fullscreen mode

✅ Verify Everything 🧐

df -h
blkid
Enter fullscreen mode Exit fullscreen mode

🚀 You're all set! Now, make the mount permanent by adding it to /etc/fstab 🎯

🎯 Conclusion 🏁

Understanding disk partitioning is crucial for system administrators and developers alike. Whether you're setting up a new storage device or troubleshooting an existing one, knowing how to check, partition, format, and mount disks is essential.

🔥 Key Takeaways:

  • Always check disk space before partitioning 🔍
  • Choose the correct partition type (MSDOS/GPT) based on system needs ⚙️
  • Use mkfs to format and mount to attach partitions 📌
  • Make changes permanent via /etc/fstab 🏗️

Mastering these commands will give you full control over your storage devices and ensure optimal system performance! 🚀😃

Top comments (0)