월. 8월 4th, 2025

Introduction

Disk partitioning is essential for organizing storage, dual-booting systems, or isolating data. While GUI tools exist, mastering command-line utilities like fdisk and parted gives you precise control. This guide explains both tools with practical examples.

⚠️ Warning:

  • Back up critical data before partitioning.
  • Use lsblk or sudo fdisk -l to identify disks.
  • Operations require root access (sudo).
  • Mistakenly modifying partitions can cause data loss!

🔧 Using fdisk (Legacy MBR Support)

1. Launch fdisk

sudo fdisk /dev/sdX  # Replace X with your disk (e.g., sda)

2. Key Commands

  • n: Create new partition
  • d: Delete partition
  • p: View partition table
  • t: Change partition type (e.g., Linux = 83, Swap = 82)
  • w: Save changes & exit
  • q: Quit without saving

3. Step-by-Step Example

Command (m for help): n  
Partition type: p (primary)  
Partition number: 1  
First sector: (Press Enter for default)  
Last sector: +10G (Creates 10GB partition)  

Command (m for help): t  
Selected partition 1  
Hex code: 83 (Set as Linux filesystem)  

Command (m for help): w (Write changes)

4. Format & Mount

sudo mkfs.ext4 /dev/sdX1          # Format as ext4  
sudo mount /dev/sdX1 /mnt/newdisk # Mount to folder

🛠 Using parted (Supports GPT/MBR)

1. Launch parted

sudo parted /dev/sdX

2. Key Commands

  • mkpart: Make partition
  • rm [N]: Delete partition N
  • print free: Show partition table & free space
  • set [N] lvm on: Set flag (e.g., LVM)

3. Step-by-Step Example

(parted) mklabel gpt             # Use GPT partitioning  
(parted) mkpart                
Partition name? []: Data          
File system type? ext4           # Note: parted doesn’t format!  
Start? 1MiB                      
End? 5GiB                        

(parted) print free             # Verify  
(parted) quit

4. Format & Enable

sudo mkfs.ntfs /dev/sdX1        # Format as NTFS after creation  
sudo parted /dev/sdX set 1 lvm on # Enable LVM flag if needed

🔄 When to Use Which Tool?

Tool Best For Limitations
fdisk MBR disks, simple layouts No GPT support
parted GPT disks, >2TB drives, flags Doesn’t format partitions

✅ Post-Partitioning Steps

  1. Update system:
    sudo partprobe /dev/sdX  # Reload partition table
  2. Auto-mount at boot:
    Add to /etc/fstab:
    /dev/sdX1  /mnt/newdisk  ext4  defaults  0 2

💡 Pro Tips

  • Test partitioning on a USB drive first.
  • Use gdisk for advanced GPT operations.
  • Always double-check device names (/dev/sda/dev/sdb!).

Partitioning empowers you to optimize storage for your workflow. With fdisk and parted, you’re equipped to handle both legacy and modern systems. Practice safely! 🐧

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다