Skip Navigation

Formatting a MicroSD Card

Before you can use a MicroSD card with the Raspberry Pi, it needs to be formatted with at least one FAT32 partition. This lesson will explain how to partition and format your MicroSD card with a single FAT32 partition using Raspberry Pi OS.

Page Contents

The Problem

Newer MicroSD cards with higher capacities are generally formatted with an exFAT file system from the factory. However, the Raspberry Pi (even the Pi 5) cannot currently boot from an exFAT partition. To make matters worse, Microsoft has artificially limited the ability for the built-in Windows formatting tools to format a large capacity MicroSD card to FAT32, offering only exFAT and NTFS (neither of which is supported by the Pi).

By far, the easiest platform for working with low level partitioning and formatting operations is Linux. While I strongly encourage you to switch to Linux on your desktop or laptop system for privacy reasons, doing so is beyond the scope of this article. Instead, we’re going to use Raspberry Pi Imager to create a Raspberry Pi OS MicroSD card, then boot the Pi into a Linux environment that we can use for this task.

Required Materials

To complete these steps, you need the following:

  1. Access to a Windows or Mac system where you have administrator rights to install software. If you already have a Linux system, you can adapt the instructions below to partition and format your MicroSD card. Just be careful to change /dev/sda in these instructions to the device node of your MicroSD card, so that you don’t accidentally destroy your Linux installation.
  2. Two MicroSD cards. One will be used for Raspberry Pi OS, where you will partition and format the other one.
  3. A USB MicroSD card reader. The Pi only has 1 MicroSD card slot, and we’ll be using it for the Raspberry Pi OS card.
  4. An assembled Raspberry Pi.

Step 1: Obtain and Start Raspberry Pi OS

Obtain Raspberry Pi Imager and create and boot your Raspberry Pi OS MicroSD card by doing the following:

  1. Go to Raspberry Pi OS and download the Raspberry Pi Imager for your system.
  2. Use your USB MicroSD adapter to connect one of your MicroSD cards to your Windows (or Mac) system.
  3. Use Raspberry Pi Imager to install Raspberry Pi OS to the MicroSD card. Choose the “Raspberry Pi OS with desktop” option and not the one “with desktop and recommended software.” The latter option contains software that you don’t need, which will make the download take longer for no reason.
  4. Once your MicroSD card has been created, verify that it has been properly ejected from your computer, and put this MicroSD card into the MicroSD card slot on the Raspberry Pi (the one directly attached to the Pi’s circuit board, not the USB adapter).
  5. Plug in the Pi, and boot it into Raspberry Pi OS.
  6. Put your second MicroSD card into the USB adapter, and plug it into the Pi.
  7. If an explorer-type window opens, showing the contents of the MicroSD card, close it.

Step 2: Remove the Existing Partition Table

Open a terminal window on your Raspberry Pi OS desktop, and run the following command:

sudo dmesg

Be sure that you see a reference to /dev/sda somewhere in the output. If you don’t see it, check that your MicroSD card is firmly plugged into the USB adapter and is oriented the right way.

Check to see if any partitions on the MicroSD card have been automatically mounted. Run:

mount

If you see any references to /dev/sda, take note of the number(s) that follow the letter a. For example, if you see that /dev/sda1 is mounted, note that. If /dev/sda2, or /dev/sda3, or so forth are mounted, note those things as well.

If nothing is mounted, skip the next command. Otherwise, if /dev/sda1 is mounted, run:

sudo umount /dev/sda1

Repeat the sudo umount command for any other partitions that were mounted.

Now remove the partition table using:

sudo wipefs -a /dev/sda

Step 3: Create a New Partition Table

Run the following command:

sudo fdisk /dev/sda

The fdisk program is interactive and works by taking in commands that you type. Do the following:

  1. Type o and press Enter to create a new DOS-style partition table.
  2. Type n and press Enter to create a new partition in the new table.
  3. We want a primary partition, so type p and press Enter.
  4. This new partition will be partition number 1 (so type 1 and press Enter).
  5. Just press Enter to accept the default starting sector (2048). This starting sector aligns the partition with the storage device for performance reasons.
  6. Press Enter again to accept the default ending sector, which will make the partition use the entire drive.
  7. If you are asked a question like “Do you want to remove the signature?”, answer y for yes.
  8. The new partition should have been created. Type p and press Enter to show it. Note that the partition type is Linux at this point, which is not what we need for a FAT32 file system.
  9. Run the t command to change the partition type.
  10. Partition 1 should be selected automatically.
  11. For the type code, enter c and press Enter. This is the partition type code for “W95 FAT32 (LBA),” which is the one we want.
  12. Verify the new partition table one more time with the p command. You should have a single partition of type W95 FAT32 (LBA). If something doesn’t look right, go back to #2 and recreate your table.

At this point, your partition table should look similar to following, although the ending sector and size of your /dev/sda1 will probably be different, since the size depends on both the size of your MicroSD card and how large a card your USB adapter can handle.

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 48410623 48408576 23.1G  c W95 FAT32 (LBA)

If everything looks good, it’s time to write the partition table and exit fdisk. Type w and press Enter.

Step 4: Format the File System

After you have exited fdisk, run

sudo mkfs.vfat -n SDCARD /dev/sda1

This command should run quickly, leaving your MicroSD card with a single FAT32 file system. You can now move the MicroSD card reader with the newly formatted card still in it back to your computer in order to copy files into this new partition. Alternatively, you should also be able to access the partition from Raspberry Pi OS, though you might need to unplug the USB adapter and plug it back in first.