Skip to content

How to format an SD card in Linux?

  • by
  • 3 min read

Most of us use SD cards for storing data, and sometimes it gets necessary to format the SD card either to remove a virus or to delete all data or for any other possible reason.

It is easy to format an SD card in Windows operating system. However, how can you format your SD card in a Linux system? Let’s dive into the article to find out the answer.

Also read: How to fix the ‘Sudo command not found’ error on Linux?


Using parted command-line tool

Parted is a command-line tool used to create and manage partition tables. Usually, the tool comes pre-installed on most Linux systems. You can check if the tool is installed in your system or not by using the following command.

parted --version

You can install the parted tool by using the following command.

Ubuntu and Debian
sudo apt install parted

CentOS and Fedora
sudo yum install parted

SUSE
sudo zypper install parted

After installing the tool, insert your SD card onto your system. Use the ‘lsblk’ or ‘dmesg’ command to get a list of all the block devices available on your system.

lsblk

or 

dmesg

Note down the name of your SD Card and run the following command. Give the name of your SD card in the value of the ‘of’ attribute. This command will wipe out all the present data on your SD card.

sudo dd if=/dev/zero of=<name of your sd card> bs=4096 status=progress

The most common file systems used in Linux are FAT32 and EXT4. You can format your SD card to either FAT32 or EXT4 file system.


Format with FAT32

Start by creating a partition table.

sudo parted <name of your SD card> --script -- mklabel msdos

Next on, create a FAT32 partition and then format the boot partition.

sudo parted <name of your SD card> --script -- mkpart primary fat32 1MiB 100%

sudo mkfs.vfat -F32 <name of your SD card>

Run the following command to print the partition table and ensure that the setup is correct.

sudo parted <name of your SD card> --script print

Your SD card is formatted successfully with the FAT32 file system.


Format with EXT4

Start by creating a GPT partition table.

sudo parted <name of your SD card> --script -- mklabel gpt

Create an EXT4 partition and then format it.

sudo parted <name of your SD card> --script -- mkpart primary ext4 0% 100%

sudo mkfs.ext4 -F <name of your SD card>

Run the following code to verify the partition table and ensure that the setup is correct.

sudo parted <name of your SD card> --script print

Your SD card is formatted successfully with the EXT4 file system.


Using file manager

You can use the file manager of your Linux system to format your SD card.

Step 1: Insert your SD card and go to the file manager. Your SD card should appear there.

Step 2: Right-click on your SD card and select the format option.

Step 3: Give a name for your SD card and select the type of file system you want in your SD card. Click on the Format button.

After some time, you will see that your SD card is formatted and will appear with the new name that you gave to the card.

Also read: Is partitioning your Hard Disk Drive (HDD) a good idea? Pros and Cons

Chetali Shah

Chetali Shah

An avid reader and an engineering student. Love to code and read books. Always curious to learn new things :)

>