dd command help needed here
Hi,
I'm trying to save usb drive that has a corrupted partition table. And here's my idea of how to get it fixed, but I'm not sure if what I want to do will work. My plan is... take a backup of the usb drive with this command. dd if=/dev/sdb of=/tmp/dead_usb_file bs=512 And then I thought I would reformat / partition the usb drive - in windows.... And then put back the file I saved, skipping the first 512, since I believe that is what holds the mbr and partition layout. dd if=/tmp/dead_usb_file of=/dev/sdb bs=512 skip=1.............. My issue comes from the last command, as looking at the dd documentation it looks like I can skip the first chunk out of the input file, but how do I also skip the first chunk of the usb device since it has a new mbr / partition. I have also thought about just trying to repartition / rebuild a mbr but I haven't looked into that one enough yet. Thanks for any insight. |
Hi,
I'm not sure whether the partition table occupies only the first 512 bytes of the device, but I think is a good guess. In this case I would try to backup up only the partition you want to recover (i.e. skip the first 512 bytes when dumping the contents of the USB drive to your hard drive) and then try to mount it using the loopback device. If you succeed in doing this, all you have to do is format your USB drive properly, mount it and then copy the files from the mounted loopback device to the USB drive using cp (or whatever method you prefer). Good luck!, Guillermo |
The partition probably starts on block 63. This is from a 2GB pendrive that I never reformatted.
Code:
sudo /sbin/fdisk -lu /dev/sdd Code:
dd --help If you have the room, then make a copy of the backup file. Use that file as the destination for restoring the mbr and see if you can mount it. However, if the partition part of the image on the dead_usb_file file is OK, you could just try mounting it using losetup & mount. You don't need to mess with dd. Code:
sudo /sbin/losetup -sf /temp/dead_usb_file.bu -o $((512*63)) If you can mount the partition image part, then you can simply copy the files back to the reformatted pendrive. |
Thanks for the replies. Partition is toasted. That was the error I was getting when I was plugging in the usb drive. It is 2GB as well.
I'll try using seek to the same spot and fixing the mbr. I'll let you know how it goes next. |
All times are GMT -5. The time now is 07:04 PM. |