How to reformat my SD card?
14,782
Just zero out the drive and create a new partition table.
Zeroing the Drive:
sudo dd if=/dev/zero of=/dev/mmcblk0
To create a new parition table, simply use GParted or a similar tool.
Author by
T_S_
Updated on September 18, 2022Comments
-
T_S_ over 1 year
I have a micro SD card (/dev/mmcblk0) with one partition on it (/dev/mmcblk0p1).
There is a btrfs filesystem on it, that won't mount. When I insert it, I get an error message on the desktop, saying:
Error mounting /dev/mmcblk0p1 at /media/franck/mysdcard: Command-line `mount -t "btrfs" -o "uhelper=udisks2,nodev,nosuid" "/dev/mmcblk0p1" "/media/franck/mysdcard"' exited with non-zero exit status 32: mount: wrong fs type, bad option, bad superblock on /dev/mmcblk0p1, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so
So I want to erase the disk, re-partition it and reformat to a new fs (probably ext4).
My problem is that I cannot do it. fdisk as well as gparted try to do it, and then fail to read again the partition table:
$ sudo parted /dev/mmcblk0 GNU Parted 2.3 Using /dev/mmcblk0 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Model: SD SD64G (sd/mmc) Disk /dev/mmcblk0: 63.4GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 16.8MB 62.4GB 62.4GB primary btrfs (parted) rm 1 (parted) print Error: /dev/mmcblk0: unrecognised disk label
If I remove and re-insert the device, the old partition and fs are still here.
I suspect gvfs is holding a lock on the device, preventing any write on it:
$ sudo lsof /dev/mmcblk0 lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs Output information may be incomplete.
So, is there a way to erase my disk ?
-
T_S_ over 9 yearsEven that did not work. dd executed just fine (took a while). But when I reinserted the card, the old partition is still there! (maybe the write could not be synced to disk? Maybe the media is broken?
-
Kaz Wolfe over 9 years@alci Edited it. Try the updated command.
-
T_S_ over 9 yearsOk, I think the card is definitely broken. I get IO errors whatever I try... Thanks for the tips. Marking this as answer, as it works on other cards and is good to remember.
-
Jan about 7 yearsmaybe adding a bs=1M would fasten that thing up a lot? or is that not valid in this case?