0Pricing
Linux Server Deployment & SSH Mastery · Lesson

Disk Partitioning and Formatting

Learn to partition disks using `fdisk` or `parted` and format them with common Linux file systems like ext4 or XFS.

Disk Partitioning and Formatting is a free Linux Server Deployment & SSH Mastery lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Server Deployment & SSH Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Disk Prep: Partition & Format

Welcome to disk management! Before a Linux server can use a new disk, it needs two main steps: partitioning and formatting.

  • Partitioning divides a physical disk into logical sections.
  • Formatting prepares these sections to store data using a specific file system.

Let's dive into making your disks ready for action!

Why Partition Your Disks?

Partitioning isn't just for organization; it's crucial for several reasons:

  • Separate OS & Data: Keep your operating system files on one partition and user data on another. This makes backups easier and protects data during OS reinstallation.
  • Multiple File Systems: Use different file systems (like ext4 for general use and XFS for large files) on different partitions.
  • Multi-Boot Systems: If you want to install multiple operating systems (e.g., two Linux distributions) on one disk, each needs its own partition.

Identifying Your Disks

Before you can partition, you need to know which disks are available. Linux typically assigns names like /dev/sda, /dev/sdb, etc., to physical disks.

You can use the lsblk command to list block devices (disks and partitions) and their sizes.

fdisk -l also shows detailed partition table information for all detected disks.

lsblk

fdisk -l

`fdisk`: MBR Partitioning

fdisk is a powerful command-line utility used for manipulating disk partition tables. It's traditionally used for disks employing the Master Boot Record (MBR) partitioning scheme.

MBR is older and has limitations, such as a maximum disk size of 2TB and supporting only up to four primary partitions.

Partitioning with `fdisk`

To use fdisk, you typically run it with administrative privileges, specifying the disk device. For example, sudo fdisk /dev/sdb.

Inside fdisk:

  • n: Create a new partition.
  • p: Select primary partition (or e for extended).
  • Specify start and end sectors/size.
  • w: Write changes to disk (be careful!).
  • q: Quit without saving.

Remember, changes are permanent once written!

sudo fdisk /dev/sdb

`parted`: GPT Partitioning

parted is another disk partitioning tool, often preferred for modern systems. It supports the GUID Partition Table (GPT) scheme, which overcomes MBR's limitations.

  • GPT supports disks larger than 2TB.
  • It allows for virtually unlimited partitions (typically 128 by default).
  • GPT is more robust, including redundancy and error checking.

Partitioning with `parted`

Using parted is similar to fdisk, but with different commands. Example: sudo parted /dev/sdc.

Inside parted:

  • mklabel gpt: Create a new GPT partition table.
  • mkpart primary ext4 0% 100%: Create a primary partition, specify file system type, and define start/end.
  • print: Display current partition table.
  • quit: Exit (changes are often applied immediately).

parted applies changes directly, so be extra cautious!

sudo parted /dev/sdc

Linux File Systems: ext4 & XFS

After partitioning, you need to format the partitions with a file system. This organizes how data is stored and retrieved.

  • ext4: The most common default file system for Linux. It's a journaling file system, meaning it tracks changes to prevent data corruption during power failures. It's robust and widely supported.
  • XFS: A high-performance journaling file system often used for large files and directories, especially in enterprise environments. It scales well to very large file systems (petabytes).

Formatting with `mkfs.ext4`

Once a partition is created (e.g., /dev/sdb1), you can format it with the mkfs.ext4 command. This command writes the ext4 file system structure onto the partition.

Always double-check the partition name, as formatting the wrong one will erase all data!

sudo mkfs.ext4 /dev/sdb1

Formatting with `mkfs.xfs`

Similarly, to format a partition with the XFS file system, you use the mkfs.xfs command. This is ideal if you're planning to store very large files or need high I/O performance.

Just like with ext4, ensure you're targeting the correct partition before executing the command.

sudo mkfs.xfs /dev/sdc1

Quick Check: Disk Preparation

Which of the following statements about disk partitioning and formatting in Linux are TRUE?

Recap: Disk Readiness

You've learned the essential first steps for preparing a disk on your Linux server!

  • Partitioning divides a disk and can be done with tools like fdisk (MBR) or parted (GPT).
  • Formatting applies a file system like ext4 or XFS using commands such as mkfs.ext4 or mkfs.xfs.

These skills are fundamental for setting up storage for your applications and data. Next, you'll learn how to actually make these new partitions accessible to your system by mounting them!

Frequently asked questions

Is the “Disk Partitioning and Formatting” lesson free?

Yes — the full text of “Disk Partitioning and Formatting” is free to read here on the web, and the Linux Server Deployment & SSH Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Server Deployment & SSH Mastery course, upgrade to CoddyKit PRO.

What will I learn in “Disk Partitioning and Formatting”?

Learn to partition disks using `fdisk` or `parted` and format them with common Linux file systems like ext4 or XFS. You practise Linux Server Deployment & SSH Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Server Deployment & SSH Mastery?

No prior experience is required. Linux Server Deployment & SSH Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Disk Partitioning and Formatting” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Server Deployment & SSH Mastery lesson?

Yes. Every Linux Server Deployment & SSH Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Disk Partitioning and Formatting
  2. Mounting File Systems
  3. Monitoring Disk Usage
  4. Logical Volume Management (LVM)
← Back to Linux Server Deployment & SSH Mastery