Skip to main content

Formatting and Partitioning a USB Drive on Ubuntu with `fdisk`

Whether it's for cross-platform compatibility or to make the most out of storage space, partitioning a USB drive into multiple file systems is a commonly sought task. In this article, we'll guide you through the process of partitioning a USB drive into two file systems: ext4 for Linux and NTFS for Windows, using the fdisk utility on Ubuntu.


  1. A USB drive you'd like to format and partition.
  2. A system running Ubuntu.
  3. fdisk and mkfs utilities (pre-installed on most Ubuntu distributions).

Warning: The following steps will erase all data on the USB drive. Ensure you've backed up any important data.

Step-by-Step Guide

Here is a step by step guide on how you can create a new file system and partition your USB drive in Ubuntu

1. Identify the USB Drive

First, plug in your USB drive. Then, use the lsblk command to identify your drive's device name:


Look for your drive based on its size and remember its device name, typically something like /dev/sdb (not /dev/sdb1, which represents a partition).

For the purpose of this guide, we'll assume the USB drive is /dev/sdb.

2. Launch fdisk

To start partitioning the drive, enter:

sudo fdisk /dev/sdb

3. Delete Existing Partitions

Once inside fdisk, you'll be presented with a command prompt. To delete existing partitions:

  • Type d and press Enter.
  • If multiple partitions exist, you'll be asked which one to delete. Repeat this step until all partitions are deleted.

4. Create the First Partition (ext4)

  • Type n for a new partition.
  • Choose p for a primary partition.
  • For partition number, press Enter to accept the default of 1.
  • For the first sector, press Enter to accept the default.
  • For the last sector, define the size you want for this partition (e.g., +8G for an 8 GB partition).
  • You've now allocated space for the first partition.

5. Create the Second Partition (NTFS)

  • Again, type n for a new partition.
  • Choose p for primary.
  • Accept the defaults for the partition number and the first sector.
  • For the last sector, you can press Enter to allocate the rest of the space on the drive to this partition.

6. Write Changes

After making the above configurations:

  • Type w to write the changes. This will format the USB drive and create the two partitions.

Create File Systems on the Partitions

Create ext4 File System

sudo mkfs.ext4 /dev/sdb1

This command formats the first partition with the ext4 file system.

Create NTFS File System

First, ensure you have the ntfs-3g package:

sudo apt install ntfs-3g

Then, format the second partition:

sudo mkfs.ntfs /dev/sdb2


Your USB drive is now partitioned into two: the first partition with ext4 suitable for Linux, and the second with NTFS for Windows compatibility. Always remember to safely eject your USB drive before unplugging it from any system. This guide provides a basic understanding of partitioning with fdisk, and the possibilities extend far beyond this use case. Happy partitioning!

What Can You Do Next 🙏😊

If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.

YouTube @cloudaffle