1

I have a Micro SD card (/dev/sdb) that is "Locked" in some "read-only" state. When I try to format it with Gparted or other graphical software it reports "Can't have overlapping partitions". Looking over the internet and on this site I found a possible solution using the comands:

sudo fdisk -l -u /dev/sdb
sudo sfdisk -d /dev/sdb > sdb-backup.txt

Then change the .txt file for a valid one fixing the overlapping partitions and apply the command:

sudo sfdisk /dev/sdb < sdb-backup.txt

After trying this I had no success in fixing my Micro SD Card. Here are the results: 1st First attempt to fix Micro SD Card:

sudo fdisk -l -u /dev/sdb
Disk /dev/sdb: 7,4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1          16 13546943 13546928  6,5G 83 Linux
/dev/sdb3       24897    24897        0    0B  0 Empty


sudo sfdisk /dev/sdb < sdb-backup.txt
Checking that no-one is using this disk right now ... OK

Disk /dev/sdb: 7,4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Old situation:

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1          16 13546943 13546928  6,5G 83 Linux
/dev/sdb3       24897    24897        0    0B  0 Empty

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new DOS disklabel with disk identifier 0x00000000.
Created a new partition 1 of type 'Linux' and of size 12,2 MiB.
/dev/sdb2: Created a new partition 3 of type 'Empty' and of size 512 B.
/dev/sdb4: 
New situation:

Device     Boot Start   End Sectors  Size Id Type
/dev/sdb1          16 24896   24881 12,2M 83 Linux
/dev/sdb3       24897 24897       1  512B  0 Empty

The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
Syncing disks.

=> As I had no success in fixing the Micro SD Card, then I tried a second attempt. 2st Second attempt to fix Micro SD Card:

sudo fdisk -l -u /dev/sdb
Disk /dev/sdb: 7,4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1          16 13546943 13546928  6,5G 83 Linux
/dev/sdb3       24897    24897        0    0B  0 Empty

sudo sfdisk /dev/sdb < sdb-backup.txt
Checking that no-one is using this disk right now ... OK

Disk /dev/sdb: 7,4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Old situation:

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1          16 13546943 13546928  6,5G 83 Linux
/dev/sdb3       24897    24897        0    0B  0 Empty

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new DOS disklabel with disk identifier 0x00000000.
Created a new partition 1 of type 'Linux' and of size 6,5 GiB.
/dev/sdb2: Created a new partition 3 of type 'Linux' and of size 965,3 MiB.
/dev/sdb4: 
New situation:

Device     Boot    Start      End  Sectors   Size Id Type
/dev/sdb1             16 13546943 13546928   6,5G 83 Linux
/dev/sdb3       13546945 15523839  1976895 965,3M 83 Linux

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

=> I had no success again.

Questions: I would like to know: Is there still anything else using FDISK or other tool (graphical or command lined) I can try to recover my SD Card or I must consider it is destroyed and buy another one?

PS1: Maybe I have set some command wrong, so if you find it and can help me I thank you. Thanks for your time in reading and answering me.

PS2: I don't know if here is the correct space for it, but in response to the user who suggested the post What can I do if my USB flash drive is write-protected or read-only? to solve my situation, although the post is very well explained to a similar situation of read-only, it doesn't contain the solution to my problem with my MicroSDCard. I want to explain that my SD card is a MicroSD and does not contain a external pin to block its write state. I'm not tecnical in computing to prove it doesn't contain the answer to my situation, but after reading the above post I haven't found any way or solution to continue to solve my problem. If you want to help me just ask what more info you need about my MicroSDcard or comand line info that I post for those interested on helping.

===================== PS3: SOLUTION TO MY PROBLEM =====================

Well until now (January, 4th, 2017), THERE IS NO Solution to fix my MicroSD card. I tried to use the suggestions that bwDraco and AFH posted, but I had no success on restore my MicroSD functionality.

What about my MicroSD card problem and solution? Well I will wait a little more to see if someone else suggests here a different solution. I can still work on it's recovery if other people have anything more to suggest as a recovery option of its functionality.

Anyway I will consider to buy another SD Card. As bwDraco said, [possibly],"the card's broken. Memory cards fail like this alarmingly often, but at least replacements aren't expensive." "Stuff fails from time to time and it isn't necessarily your fault."

Fortunately, I had no important data on the MicroSD before this damage, so I didn't lose anything important on it. Anyway, is a bad thing to lose a storage device, I don't like it, but at least it's only a MicroSD loss, it doesn't represents a huge loss.

Besides that I'd like to thanks everyone who tried to help!

================================================================

Dan
  • 36
  • 1
  • 4
  • Assuming you don't need any of the data, you can try wiping the contents with `sudo dd if=/dev/null of=/sdb bs=64m` or similar. You should then be able to format it as a scratch disc. In fact you probably need to overwrite only the partition table, but it won't hurt to wipe everything. Just make sure you double-check that you are overwriting the correct device! – AFH Jan 04 '17 at 15:26
  • Hi AFH of anyone who can help. The /sdb is the correct device in my case. I don't need to recover any data on the device. I just like to try to recover it for it work again to write and copy data like it use to do in the past, originally on FAT 32 default/fabric format, and then format it for my individual use. I tried the command sudo dd if=/dev/null of=/sdb bs=64m you suggested and got the terminal response: dd: invalid number: ‘64m’ Any idea of what this mean? – Dan Jan 04 '17 at 15:45
  • Hi Tetsujin and others who read this. The post you suggested [What can I do if my USB flash drive is write-protected or read-only?] although is very well explained a similar situation doesn't contain the solution to my problem with my MicroSDCard. I want to explain that my SD card is a MicroSD and does not contain a external pin to block its write state. If it's locked is probably something internal. I am available to provide more information for people who want to help. Just ask what more info you need about my Microsdcard or comand line info that I post for those interested. Thanks anyway. – Dan Jan 04 '17 at 16:04
  • 1
    Try `sudo dd if=/dev/zero of=/sdb bs=64M` (sorry about the `if=` parameter: `/dev/null` returns immediate EOF) - some implementations allow different qualifiers for byte multiples. Or omit the `bs=` parameter altogether: it will work, but more slowly. – AFH Jan 04 '17 at 16:48
  • 1
    Hi AFH (or anyone who can help). After applying `sudo dd if=/dev/zero of=/sdb bs=64M` code you suggested and the terminal worked for a while it showed me the response `dd: error writing '/sdb': No space left on device 453+0 records in 452+0 records out 30384529408 bytes (30 GB, 28 GiB) copied, 278,123 s, 109 MB/s` What should I do now? When explaining, please, try to do the most detailed explanation as I am not expert in Computing. They way you are trying to guide me is just fine. What is the next step? – Dan Jan 04 '17 at 17:03
  • Run `sudo rm /sdb`, then run `sudo dd if=/dev/zero of=/dev/sdb bs=64M`. @AFH gave you the wrong command, which wrote to the system disk. – bwDraco Jan 04 '17 at 19:10
  • Hi bwDraco. You're right. The command AHF suggested wrote to my system disk and now instead of 1 problem (MicroSD Card) I have 2 (I can't access my system as the / or /root folder is 100% full, so the linux system seems to load but it doesn't makes login). I don't know if it was caused by the AHF but the fact is that was produced after that. If was caused by @AHF suggestion: "- Come on, people, I'm looking for a serious solution of my MicroSD problem not to get another ones. I know we cannot trust everything on the internet but at least some trust must exist" Thanks for those who can help. – Dan Jan 04 '17 at 19:34
  • Hi @bwDraco. I will try to access my system problem and take a screenshot of write the second problem I have now, maybe you or others can help me. – Dan Jan 04 '17 at 19:36
  • That error is normal: the command keeps writing until the end of the disc is reached, with the error you observed. At this point the whole SD has been overwritten, and you should be able to format it. You may need to remove and re-insert the SD first. – AFH Jan 04 '17 at 19:37
  • @AFH, pay attention to the command parameters. The output file should have been `/dev/sdb`, not `/sdb`. The latter writes to the root directory, filing up the system volume. – bwDraco Jan 04 '17 at 19:39
  • @bwDraco and AFH I will turn on my pc again in the recovery mode and take a screenshot of / folder info as now because of this 100% i cant log on it anymore. First, now i need you to help me to access again the system then we cant continue to try to solve the MicroSD question – Dan Jan 04 '17 at 19:42
  • @AFH I think bwDraco is right as now I cant log into my system. Maybe you can help too. I will send the screenshots in some minutes – Dan Jan 04 '17 at 19:43
  • Use a Live CD (or your installation media) and delete the /sdb file in the root directory of your system partition. – bwDraco Jan 04 '17 at 19:43
  • @bwDraco - Oops, you're quite right. It comes from not having an SD I wanted to overwrite, so I couldn't try the live command and copy/paste it. – AFH Jan 04 '17 at 19:44
  • @bwDraco - `sudo rm /sdb` should do it without needing any other media, though it may need an alternative boot if the command won't run. Recovery mode should suffice. – AFH Jan 04 '17 at 19:50

1 Answers1

0

From one of your comments (edited for formatting):

After applying sudo dd if=/dev/zero of=/sdb bs=64M code you suggested and the terminal worked for a while it showed me the response:

dd: error writing '/sdb': No space left on device
453+0 records in
452+0 records out
30384529408 bytes (30 GB, 28 GiB) copied, 278,123 s, 109 MB/s

What should I do now?

That should have been of=/dev/sdb, not of=/sdb. This command fills up the system disk, which could crash the machine. Run sudo rm /sdb to delete the extraneous file. If this fails, you may need to boot into a live CD to delete the file from your system drive. See this Ask Ubuntu question for more information on how to deal with a full root filesystem.


Once you've deleted the extraneous file, reboot to your original Linux system and try running the following command:

sudo dd if=/dev/zero of=/dev/sdb bs=64M count=16

If this fails with something like Input/output error, the card is bad and needs to be replaced. Otherwise, you should be able to reformat the card and use it normally.

bwDraco
  • 45,747
  • 43
  • 165
  • 205
  • I followed your instructions an now have access again to my linux system. Thanks! About the MicroSD I tried `sudo dd if=/dev/zero of=/dev/sdb bs=64M count=16` and the terminal is still working, for about 40 min, and don't give me any response, just that "black icon/bar, like this ( | ), and that indicates it is still working. If I try to access the device from the graphical interface the system says "Unable to mount /dev/sdb Volume An operation is already pending", probably because of the terminal command. What should I do? Keep waiting or is there anything else I can try? – Dan Jan 04 '17 at 21:10
  • This doesn't seem very normal—it shouldn't take 40 minutes to write 1 GiB of data. Hit Ctrl+C to stop the operation. What output do you get? – bwDraco Jan 04 '17 at 21:11
  • If i type Ctrl(keyboard) key + C on terminal, both using the right or left control keys on the keyboard I got a ^C symbol response. What am I doing wrong? Sorry, I am new and don't know much about the terminal.... be patient. – Dan Jan 04 '17 at 21:17
  • dd appears to have hung (it should normally exit right away when you hit Ctrl+C). The card is most likely faulty and needs to be replaced. Remove the card from the system and dd should stop with an error. If it doesn't exit, you may need to forcibly reboot the machine. – bwDraco Jan 04 '17 at 21:18
  • When you say "dd appears to have hung. The card is most likely faulty and needs to be replaced." do you mean probably there is nothing else to do and that the card is probably damaged in some way? Does it mean I lost this 8GB MicroSD card? – Dan Jan 04 '17 at 21:28
  • Yup, the card's broken. Memory cards fail like this alarmingly often, but at least replacements aren't expensive. – bwDraco Jan 04 '17 at 21:30
  • Must I give up or is there anything else I can try? I am asking because I originally tried to format this card with an app called "Aparted" download from Google Play Store, in order to use it on an old tablet I have to give it some extra life and usability. I am not an expert in Computing but I have enough inteligence to respect apps instructions. I'm sure I did nothing wrong on this process. Probably this app damaged my sdcard, although I can't be sure of that. Fortunately, I had no important data on the MicroSD, but anyway is a bad thing to lost a storage device. – Dan Jan 04 '17 at 21:30
  • I doubt the software had anything to do with this. Stuff fails from time to time and it isn't necessarily your fault. – bwDraco Jan 04 '17 at 21:32
  • I have tried `sudo dd if=/dev/zero of=/dev/sdb bs=64M count=16` and it immediately printed : `dd: failed to open '/dev/sdc': Read-only file system`. I have no issues with the adapter of the reader, What should I try next ? – Pini Cheyni Jul 13 '17 at 11:15
  • @PiniCheyni: Please see https://superuser.com/questions/1125282/what-can-i-do-if-my-usb-flash-drive-is-write-protected-or-read-only – bwDraco Jul 13 '17 at 14:42