Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to format an SD card in Linux  (Read 1371 times)

0 Members and 1 Guest are viewing this topic.

jibinw

  • Guest
How to format an SD card in Linux
« on: April 07, 2018, 12:06:04 am »
Here, I will explain you how to format a Micro SD card, SD card and any USB storage device 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:

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 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.