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)