1

I can't write the partition table on an SD card. IOCTL error. I can't delete it, either, neither in Linux using parted, cfdisk, or fdisk, nor in Windows, which just says format didn't work. The partition table just will not go away, so I'm pretty sure those sectors of the disk have just failed for writing, but can still be read somehow.

Can I write the partition table to a different place on the disk?

The SD card is a 32GB Sandisk which I flashed with k3os.

More info:

TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <[email protected]> https://www.cgsecurity.org Disk /dev/sdd - 31 GB / 29 GiB - CHS 30437 64 32 Analyse cylinder 1084/30436: 03% Read error at 1083/1/1 (lba=2218016) check_FAT: Unusual number of reserved sectors 4 (FAT), should be 1. FAT16 >32M 1 0 1 56 63 32 114688 [NO NAME] Linux 58 0 1 1010 63 32 1951744 [root] 

I tried writing zeroes to the first 512 bytes, but this was the result:

root@amnesia:~# dd if=/dev/sdd bs=512 count=1|hexdump 1+0 records in 1+0 records out 0000000 b8fa 1000 d08e 00bc b8b0 0000 d88e c08e 0000010 befb 7c00 00bf b906 0200 a4f3 21ea 0006 0000020 be00 07be 0438 0b75 c683 8110 fefe 7507 0000030 ebf3 b416 b002 bb01 7c00 80b2 748a 8b01 512 bytes copied, 0.0029971 s, 171 kB/s 0000040 024c 13cd 00ea 007c eb00 00fe 0000 0000 0000050 0000 0000 0000 0000 0000 0000 0000 0000 * 00001b0 0000 0000 0000 0000 e765 fb8c 0000 0080 00001c0 1001 030c 8fe0 0800 0000 c000 0001 0000 00001d0 a0c1 0383 ffe0 d000 0001 c800 001d 0000 00001e0 0000 0000 0000 0000 0000 0000 0000 0000 00001f0 0000 0000 0000 0000 0000 0000 0000 aa55 0000200 

It really seems like I can't write to the first sector. Also, the read error at cylinder 1083 has been consistent every time I use testdisk on this card. Btw, I changed the disk geometry from 4 to 64 heads to make testdisk happy.

Smartctl errored out with no useful info. lsblk showed this:

root@amnesia:~# lsblk2 /dev/sdd SIZE FSTYPE MODEL NAME SERIAL UUID 29.7G SD_Card_Reader sdd 000000000820 56M vfat ├─sdd1 D013-2C4C 953M ext4 └─sdd2 a3198349-8ae7-47cd-8ed7-26e09ba8146b 

A tool called sdtool revealed "Write protection state: Off".

Is this just a bad sd card that I can't rescue?

2
  • It might be possible that the partition table is not real, i.e. you can only format the existing partition. Commented May 23, 2022 at 16:09
  • Oh it's real. I can mount both partitions and list files. Commented May 24, 2022 at 15:48

3 Answers 3

2

I'm pretty sure those sectors of the disk have just failed for writing, but can still be read somehow.

That's not a failure mode of flash memory with an flash abstraction layer, like SD cards. Writing flash memory requires erasing of a page, then rewriting the whole page, with the data modified.
Because that can only be done a finite amount of times, usually, when erasing a page, the abstraction layer just picks a different, already erased page and maps it to the same address to implement wear leveling. This conversely means that your flash memory is physically larger than what your operating system sees – simply because the addresses on the physical memory have nothing to do with the addresses your operating system sees, and there always has to be a percentage of unused blocks that can be used when a formerly used block gets erased.

Only when pages have been erased so often that they're not reliable anymore, they are removed from the pool of available pages. When that happens often enough, the memory becomes "read only", because no page can be erased anymore without risking it becoming a data loser.

Since you don't complain about the device being impossible to read elsewhere, that's not the case here.

So, I'm pretty sure that this is either a firmware protection (the flash controller in the SD card is a microcontroller running firmware, and so is your card reader) feature that locks the addresses pointing to your partition table (never seen that, but it's possible), or your operating system stopping you from doing that.

So, assuming that it's not the OS, seeing you've tried a couple, I'd assume it's some firmware stopping you. Check whether there's a specific little slider on the side of your card that might be in the wrong position!

Can I write the partition table to a different place on the disk?

You can write anything anywhere on the memory device (it's not really a disk ;)!) but a partition table only works as partition table at the very beginning of the device. So, no, not in the way you meant this question.

5
  • I wrote this image probably 10-15 times. Could that have worn out the drive? Is the first sector wear-leveled? Commented May 24, 2022 at 13:45
  • I've seen quite a few microSD bricked (become read-only) by a RPI 4 like that though. Even tried using this to unlock them IIRC. (Also permanent write protection seems to be a thing, related or not) Commented May 24, 2022 at 15:26
  • @wirelessben Btw in my cases they bricked after during/after the first system clone, so it does not need to be worn to happen. Commented May 24, 2022 at 15:30
  • @tom-yan That seems to be the case, as I definitely cannot write to the first 512 bytes. Too bad the wear-leveling firmware locked it. I can write to the rest of the disk, though. Commented May 25, 2022 at 14:45
  • Hmm only one single block cannot be wiped/written? That's kind of weird. In my case IIRC the whole card was bricked. If you happen to have a computer that has a "native" SD card reader in it (i.e. mmcblkN instead of sdX), maybe you can see if blkdiscard helps. Commented May 25, 2022 at 20:32
0

what I would try using linux is this

lsblk # identify the sd card, be sure it is what u think it is by removing then running # lsblk again and seeing that not there, then reconnecting. # also alias lsblk2='lsblk -o size,fstype,model,name,serial,uuid' lsblk2 # that will print out more useful info # then, for example, if your sd card is /dev/sdb dd if=/dev/zero of=/dev/sdb bs=512 count=1 

if that dd command does not work and results in error when writing simple zeros to your sd card then you got other things going on, like was mentioned in the other answer (which is over my head). You mentioned cannot write partition table but did not elaborate... there's many utilities out there that oftentimes do not work and can lead you down a path of wrong conclusions. Doing that dd command will also effectively clear out any existing partition table on the sd card.

# to create a partition table it would be this command, # again assuming /dev/sdb is your sd card for example parted /dev/sdb mklabel gpt # I have never had this parted command fail on me 

Another diagnostic to use is smartctl --xall /dev/sdb to access the values of the sdcard showing its health which may help you understand if the sd card actually has a problem, particularly the wear level.

https://superuser.com/questions/1064119/usb-flash-drives-or-sd-cards-with-s-m-a-r-t

5
  • oh I'm sorry to hear my answer is over your head! If there's anything I could have explained better, please let me know. It's very likely not a ron-problem but a Marcus' text-problem. Commented May 23, 2022 at 17:39
  • i wasn't being sarcastic, i thought your answer was good, I just have zero knowledge of flash abstraction layer or how firmware at that level actually operates. The only thing you mentioned i know of is the write-protect slider you mentioned. if a simple 'dd' results in error then i'd agree with your answer as being what is happening, that's all i was trying to get at. Commented May 23, 2022 at 19:06
  • I know! I was not assuming you're being sarcastic :) I just hoped the answer would illustrate things well enough! Commented May 23, 2022 at 19:30
  • The smartctl command resulted in "Read Device Identity failed: scsi error unsupported scsi opcode" and SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 82-83 don't show if SMART supported. SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 85-87 don't show if SMART is enabled. Commented May 24, 2022 at 15:02
  • parted /dev/sdd mklabel gpt did nothing. Commented May 24, 2022 at 15:08
-1

use the command lsblk to find the block where your sd card is.

followed by fdisk to do disk partitioning.

Then try partprobe or hwprobe to find additional information about the partitions.

2
  • wirelessben is already describing using fdiskon it, and being able to read it such: hence, using the right device. Commented May 23, 2022 at 17:38
  • yeah didnt think of that at the time. It was more of a request to see what the output was for the given commands in verbosity. Commented May 24, 2022 at 2:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.