5

I wanted to dd an image from sdb to sdc, but because one hour before I had set up things differently, I just copied the same command:

dd if=/home/user/Downloads/ubuntu.iso  of=/dev/rsdb bs=2M; sync

sda = internal hard drive
sdb = USB hard drive (booted from right now)
sdc = USB stick

There are 3 partitions on the hard drive I've booted from, I guess the other 2 are in read only mode, and the error in shell as I tried two times:

568328192 bytes (568 MB) copied, 38,5818 s, 14,7 MB/s
dd: error writing ‘/dev/rsdb’: No space left on device
715128832 bytes (715 MB) copied, 17,1752 s, 41,6 MB/s

Now I realized I overwrote 1GB over the hard drive I'm booted from (using rsdb). I haven't turned off my computer. Will I loose all data on this drive? Can I recover anything now?

Here’s my /proc/partitions:

   8        0  156290904 sda
   8        1  154218496 sda1
   8        2          1 sda2
   8        5    2069504 sda5
   8       16  244198582 sdb
   8       17   31457280 sdb1
   8       18   20971520 sdb2
   8       19  191768576 sdb3
   8       32    2011136 sdc
   8       33    2011135 sdc1
user219095
  • 65,551

3 Answers3

2

You have destroyed the first ~1 GB, which covers the partition table and the first partition's file/directory list. You can still rebuild the partition table and find sdb2 & sdb3 untouched, though.

Run this script from a terminal, and write down the start/size/end numbers it reports (just in case):

for part in /sys/class/block/sdb[0-9]*; do
    num=$(<$part/partition)
    start=$(<$part/start)
    size=$(<$part/size)
    end=$((start+size-1))
    echo "partition $num: start $start, size $size, end $end"
done

Then use parted /dev/sdb or fdisk /dev/sdb to manually create the matching partitions. For example, if it prints:

partition 1: start 2048, size 204800, end 206847

then you could use:

parted /dev/sdb mkpart primary 2048s 206847s

(note the s unit at the end)

grawity
  • 501,077
1

You can recover your data using TestDisk (photorec)

TestDisk is OpenSource software and is licensed under the terms of the GNU General Public License (GPL v2+).

TestDisk is powerful free data recovery software! It was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software: certain types of viruses or human error (such as accidentally deleting a Partition Table). Partition table recovery using TestDisk is really easy.

TestDisk can

Fix partition table, recover deleted partition

Recover FAT32 boot sector from its backup

Rebuild FAT12/FAT16/FAT32 boot sector

Fix FAT tables

Rebuild NTFS boot sector

Recover NTFS boot sector from its backup

Fix MFT using MFT mirror

Locate ext2/ext3/ext4 Backup SuperBlock

Undelete files from FAT, exFAT, NTFS and ext2 filesystem Copy files from deleted FAT, exFAT, NTFS and ext2/ext3/ext4 partitions. TestDisk has features for both novices and experts. For those who know little or nothing about data recovery techniques, TestDisk can be used to collect detailed information about a non-booting drive which can then be sent to a tech for further analysis. Those more familiar with such procedures should find TestDisk a handy tool in performing onsite recovery.

Boot from Linux live usb.

To install TestDisk type:

 sudo apt-get install testdisk

to run TestDisk

sudo testdisk

There are a tuto :TestDisk_Step_By_Step

GAD3R
  • 3,900
0

I strongly recommend Recuva.

About 2 days ago I did the same mistake and worried a lot, and came to this topic. However, neither the partitioning script nor testdisk helped me. Tried photorec and saved some of the photos, but most of them were 3-days-ago uploaded ones, old ones were lost.

At the and, I was about to gave up, formatted whole of the HDD to NTFS (Because MBR was damaged) and used my friends Windows PC to use Recuva. It did the trick, (not all of them but) lots of the files have been recovered. Even it restored file names and last modification times (which photorec could not).

afedersin
  • 101