-1

I'm trying to format a 4Gb sandisk sd card in which i have previously installed ubuntu installer. Now i'm not able to format it. I tried sd card formater, gparted (says unable to complete format due to lack of partition table), and when i used sudo mkfs.ext4 /dev/mmcblk0p1 said input output error when wirting and closing file. Even using mkusb to format the file leads to input output error. And i'm not able to format any partition. Its partitioning says master boot record, if that info is needed. Also i checked and the sd card reader in not in read-only mode.

I don't want to recover any data, i just want to format it completely so i can use it for other purposes.

  • Is it mounted? man umount df – waltinator May 02 '21 at 02:20
  • it says its not mounted – Pranav Kumar May 02 '21 at 02:29
  • 1
    Reset USB flash that was dd'd to make it usable again, reuse https://askubuntu.com/questions/939230/formatting-a-usb-stick-unable-to-operate-usb/939266#939266 & https://help.ubuntu.com/community/mkusb#Re-use_the_pendrive & https://unix.stackexchange.com/questions/216152/usb-disk-read-only-cannot-format-turn-off-write-protection – oldfred May 02 '21 at 02:33

1 Answers1

1

You need to take 3 steps to prepare the USB stick. Before you start, make sure you know the correct drive letter (/dev/sd?) that is used by the system for the USB stick and replace the ? with that letter in the following commands.

If the USB stick is unmounted, let's open a terminal and let's start:

Step 1
Blank the beginning of the USB stick.
sudo dd if=/dev/zero of=/dev/sd? bs=4M count=1 && sync

Step 2
Create both a partition table and a partition on the drive.
sudo fdisk /dev/sd?
fdisk will create an msdos/mbr partition table on the USB stick automatically.
Press n for new partition and if you want to create a single partition on the whole drive, you can accept the default selections in the questions that follow by simply pressing Enter. You can always consult the man pages by typing man fdisk for further details on how to customize partitioning.
After you're finished with the new partition, press w to write the changes to the USB stick and close fdisk.

Step 3
Format the partition you've created:
sudo mkfs.vfat -F 32 /dev/sd? to create a FAT32 partition or,
sudo mkfs.ext4 /dev/sd? to create an EXT4 partition for use with Linux only.

The USB stick should be ready to use at this point.


WARNING: If you don't use the correct drive letter on any of the commands shown above, another disk's data will be destroyed, possibly irrevocably.

Stormlord
  • 6,317
  • Thanks, but i now think there is physical damage to the sd. I have tried like 20 things to fix it. Cant even create/delete files in the sd card normally connected to the computer. – Pranav Kumar May 03 '21 at 12:42
  • Thanks, this fixed an irritating input/output error on my sd card which gui apps like gparted, gnome disks etc. couldn't do anything. Perhaps they need to incorporate step 1 above. – Sadi Aug 05 '22 at 09:42