Tuesday 6 March 2018

linux - dd aplied to dev USB before connect corrupt /dev/sdX and dont work


I have a USB where I'm coping an ISO of 5 Mb aprox with a small OS with its own grub. If I connect the device and check it sudo fdisk -l I get:


...
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 1 9551 9551 4.7M cd unknown

If I copy with dd the ISO sudo dd if=my_os.iso of=/dev/sdb


14852+0 records in
14852+0 records out
7604224 bytes (7.6 MB) copied, 0.538487 s, 14.1 MB/s

It works perfectly. An boot from BIOS in other PC.


The problem is, sometime I forget to connect the USB after update the BIOS, so I do ff WITHOUT the USB connected, the output is:


14852+0 records in
14852+0 records out
7604224 bytes (7.6 MB) copied, 0.00987684 s, 770 MB/s

Now, the /dev/sdb register is corrupted, the copy speed (770 MB/s) have no sense, and cannot user again dd until reboot.


I have tried to repair it with ddrescue and it doesn't work


sudo ddrescue /dev/zero /dev/sdb conv=noerror,sync

My question is, what is happening exactly and if is possible, how to repair /dev/sdb to avoid reboot and dd start working again?


Thanks.



Answer



Device nodes like /dev/sd* only show up in /dev after the device is connected, not before. (Also, they aren't called "registers".) So when you ran dd of=/dev/sdb it didn't actually touch any device – instead, since the output file didn't exist, dd created a new file by that name.



$ sudo dd if=archlinux-2016.04.01-dual.iso of=/dev/sdc
1482752+0 records in
1482752+0 records out
759169024 bytes (759 MB, 724 MiB) copied, 0.941926 s, 806 MB/s

$ ls -l /dev/sd*
brw-rw---- 1 root disk 8, 0 Jun 15 08:54 /dev/sda
brw-rw---- 1 root disk 8, 16 Jun 15 14:14 /dev/sdb
-rw-r--r-- 1 root root 724M Jun 15 15:06 /dev/sdc

So there's really nothing that could have been "corrupted", and nothing that makes sense to "repair" or ddrescue. You simply have a huge file named /dev/sdb, and because it exists, the kernel can't create a real device node there.


(The write speed makes perfect sense – /dev is stored in RAM, so you just copied the image from RAM, where it was cached, back to RAM, where /dev lives.)


Delete /dev/sdb and reconnect the device, and the real device node should reappear.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...