# Woes with dd



## aaruni (Oct 19, 2014)

My usage scenario :

I had to borrow someone's SD Card for a day, I had to delete stuff on it to make room for my stuff. I decided to take the geeky way out, and instead of just copy-paste to backup, I decided dd was a better option, since, as of my understanding, it makes a bit-by-bit clone of the source device and stores it into a neat little file. ( More about dd here : dd (Unix) - Wikipedia, the free encyclopedia ). 

My Mistakes :

My SD Card was /dev/sdb . I had to run :


```
dd if=/dev/sdb of=/path/to/iso
```

But I really, only wanted one partition. So, I thought making some changes to the command would be all right. What I really ran was :


```
dd if=/dev/sdb1 of=/path/to/iso
```

The Consequences of that Mistake :

When the next day, I had to restore the SD Card, I ran :


```
dd if=/path/to/iso of=/dev/sdb1
```

But I was horrified by the fact that only garbage was being copied into the SD Card. I repeated the same procedure twice, just in case, getting the same result both the times.

What I Had to Do :

I should have simply mounted the iso file, and then copy-pasted the data back into the SD Card. But here's the tricky part.


```
mount -o loop /path/to/iso /path/to/mountpoint
```

The code above would give errors, because of missing filesystem in the iso. After that, I lost all heart and gave up.

Here is the correct way of solving the problem :

Run the following :


```
fdisk -l /path/to/iso
```

You should get output similar to this :


```
Disk sdcard.iso: 31.5 GB, 31499223040 bytes
256 heads, 63 sectors/track, 3814 cylinders, total 61521920 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
Disk identifier: 0x00000000

     Device Boot      Start         End      Blocks   Id  System
sdcard.iso1   *        2048    61521919    30759936    c  W95 FAT32 (LBA)
```

So, in my case, the sector size if 512, and the filesystem starts at the 2048th sector.

Modify the mount command. (the number next to offset is calculated by sector start * sector size. In my case, that's 2048*512)


```
mount -o ro,loop,offset=1048576 /path/to/iso /path/to/mountpoint
```

And voila!

My Results :

The archive mounts just fine. Right now, I'm copying all the data back using the old fashion copy-paste method.


----------



## Vyom (Oct 19, 2014)

Congrats. You made quite a ruckus on the IRC chat room. 
I am glad that you finally resolved the issue.


----------



## aaruni (Oct 20, 2014)

all hail [MENTION=26711]ico[/MENTION] .


----------

