How to format an SD card in Linux

This tutorial will guide you to format your Micro SD card, cards or any USB storage device with FAT32 file system.

To install some applications, it is required to format the Micro SD card with FAT32 file system.

Since different desktop environments use different tools to accomplish the same task, I have resorted to one method that may be the same in production environments: the command line.

So this is how to format SD cards, USB sticks or Micro SD cards with fat32 file system from command line in Linux.

1. Connect your removable flash drive and run the command ‘lsblk‘to identify the device.

Here is the output of the command “lsblk“On my system, where” SDB “is removable flash memory:

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
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 get the job done, but recently started using “parted”, so this is the utility I’ll be using for this tutorial. ‘parted’ with the name of the device you want to format. In this case, it is “SDB”. (Be careful with the device name because you might end up formatting the wrong drive.)

3. Replace ‘SDB’ with your device name in the following command:

sudo parted /dev/sdb

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

(parted) mklabel msdos

five. After the partition table is created, you can create partitions on the disk. We will only create one section:

(parted) mkpart primary fat32 1MiB 100%

6. Then set the boot flag on it:

(parted) set 1 boot on

7. Exiting the parted tool:

(parted) quit

8. Now we need to format this partition as FAT32. First, check that the partition was successfully created. Just run the ‘lsblk’ command and check the new partition for “SDB”.

nine. Now format it as fat32:

sudo mkfs.vfat /dev/sdb1

Just replace ‘sdb1’ with your disk partitioning. Make sure to format the ‘SDB’ partition and not the ‘SDB’ itself.

Here’s how to format external storage devices on Linux. You can now start using the removable disk.

Sidebar