How to format an SD card in Linux

How to format an SD card in Linux

As I was working on a tutorial about installing Raspbian on Raspberry Pi 3, I realized that I had to format the Micro SD card with fat32 partition. Another tutorial was in order!

Since different desktop environments use different tools to perform the same task, I resorted to one method that can be consistent across desktop environments: command line.

So here is how you format an SD card, USB drive or Micro SD card with fat32 file system from the command line in Linux.

1. Plug in your removable flash drive and run the ‘lsblk’ command to identify the device.

Here is the output of the 'lsblk' command on my system where ‘sdb’ is the removable flash storage:

sdb    8:16   1  3.8G  0 disk
├─sdb2   8:18   1  2.4M  0 part
└─sdb1   8:17   1  1.5G  0 part /media/sandisk

2. There are many command line tools to do the job, but lately I started using 'parted' more, so that’s the utility I will be using for this tutorial. Run the 'parted' command with the name of the block device that you want to format. In this case, it’s ‘sdb’. (Be careful with the name of the block device because you might end up formatting the wrong drive.)

3. Exchange ‘sdb’ with the name of your block device in the following command:

sudo parted /dev/sdb

4. It will ask you to enter the password for the user and you will notice that parted replaces the username and $ sign, which means you are running the parted utility. First, let’s create a partition table. In this case, we are using MBR:

(parted) mklabel msdos

5. Once the partition table is created, you can create partitions on the drive. We will be creating just one partition:

(parted) mkpart primary fat32 1MiB 100%

6. Then set the boot flag on it:

(parted) set 1 boot on

7. Exit the parted tool:

(parted) quit

8. Now we need to format this partition as fat 32. First, check if the partition has been created successfully. Just run the 'lsblk' command and verify a new partition on ‘sdb’.

9. Now format it as fat32:

sudo mkfs.vfat /dev/sdb1

Just exchange ‘sdb1’ with the partition of your drive. Make sure to format the ‘partition on ‘sdb’ and not ‘sdb’ itself.

That’s how you format external storage devices on Linux. Now you can go ahead and start using the removable drive.

IDG Insider


«Samsung's Evo+ 128GB microSD card has dropped to $40 at B&H


Google makes it easier to summon Assistant in Allo, adds in-app GIF searching»
IDG Connect

IDG Connect tackles the tech stories that matter to you

Our Case Studies

IDG Connect delivers full creative solutions to meet all your demand generatlon needs. These cover the full scope of options, from customized content and lead delivery through to fully integrated campaigns.


Our Marketing Research

Our in-house analyst and editorial team create a range of insights for the global marketing community. These look at IT buying preferences, the latest soclal media trends and other zeitgeist topics.



Should the government regulate Artificial Intelligence?