LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Learn the DD command (https://www.linuxquestions.org/questions/linux-newbie-8/learn-the-dd-command-362506/)

[rascas] 02-11-2012 02:53 PM

Hi there!

Some days ago i did a dd image write of a Linux Mint image. The command i used was the recommended in their page: sudo dd if=~/Desktop/linuxmint.iso of=/dev/sdb oflag=direct bs=1048576
The problem was that i was sleeping and mistaken the drive letter and writed the image to an External USB 2TB hard drive instead of the usb pen drive! This was not so much a problem because i had a backup of that drive.

The real problem is, to put the data that i lost, again in that drive, i erased all partitions in gparted, created a new partition table, formated in NTFS (it has to be), then in windows did the same thing again just to be sure. Gparted, fdisk and windows disk management tool, all show me that the disk only has one partition (what i want). The problem is when i plug the drive into the PC, the Kde device notifier and Dolphin shows like 2 drives have been plugged ( One with the label "Store" with my files, and another with device name's label, with the files of the Mint image that i preveously writed). I can only mount one of that drives at a time.
Fdisk-l output:

Quote:

Disk /dev/sdb: 2000.4 GB, 2000396746752 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907024896 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: 0x00061614

Device Boot Start End Blocks Id System
/dev/sdb1 2048 3907020799 1953509376 7 HPFS/NTFS/exFAT
[diogo@ds-desktop ~]$
Well, something wrong is going here. I tried to google for a solution but didnt found anything. Hope someone can help me, specially if i can resolve this without reformatting the hard drive (it takes almost one day to put the data back)

Thanks in advance

JZL240I-U 02-13-2012 07:48 AM

Quote:

Originally Posted by [rascas] (Post 4599942)
...The real problem is, to put the data that i lost, again in that drive, ... Gparted, fdisk and windows disk management tool, all show me that the disk only has one partition (what i want). ...

You lost me there somewhere. You re-created and formatted a NTFS partition as needed. Well, then restore the data and have a look whether your backup worked ;).

Quote:

Originally Posted by [rascas] (Post 4599942)
...The problem is when i plug the drive into the PC, the Kde device notifier and Dolphin shows like 2 drives have been plugged ( One with the label "Store" with my files, and another with device name's label, with the files of the Mint image that i preveously writed).

On my box KDE shows (sometimes) the whole device and the partition.

Quote:

Originally Posted by [rascas] (Post 4599942)
...I can only mount one of that drives at a time.

Definitely "unusual". Looks like you didn't format the whole device but created a new partition. Perhaps a dedicated thread in an appropriate forum here might bring better results, sorry.

Quote:

Originally Posted by [rascas] (Post 4599942)
...
Fdisk-l output:
Code:

Disk /dev/sdb: 2000.4 GB, 2000396746752 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907024896 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: 0x00061614

Device Boot Start End Blocks Id System
/dev/sdb1 2048 3907020799 1953509376 7 HPFS/NTFS/exFAT


That's what I meant: The first block is the device /dev/sdb, the second the partition /dev/sdb1.

[rascas] 02-13-2012 12:06 PM

Yeah my post seems a bit confusing. I will try to explain better.
Forget the data backup part. I did that already and its not the problem. I did that in windows ( i dont trust linux/fuse to copy/move data between ntfs partitions). They are to WD Caviar green 2 TB.

Now i have 2 virtually identically drives with the same data. Virtually because, now in linux (dolphin) it is showing me one of the disks having 2 partitions. My only issue is that only dolphin and the kde device manager shows me that. Gparted and fdisk tells me that there is only one partition in that disk. Windows "sees" only one partition to. Thats what is confusing me (and maybe you). See the picture:

http://img35.imageshack.us/img35/7858/dolphinuf.jpg

WDC WD20EARS and Store is the same hard drive. This is the drive that i made the image copy with dd by accident. But on fdisk:

Code:

Disk /dev/sdb: 2000.4 GB, 2000396746752 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907024896 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: 0x00061614

  Device Boot      Start        End      Blocks  Id  System
/dev/sdb1            2048  3907020799  1953509376    7  HPFS/NTFS/exFAT

Disk /dev/sdc: 2000.4 GB, 2000396746752 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907024896 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: 0x0002de0f

  Device Boot      Start        End      Blocks  Id  System
/dev/sdc1            2048  3907020799  1953509376    7  HPFS/NTFS/exFAT
[diogo@ds-desktop ~]$

Can you see? The same info for the 2 drives. sdb is the "Store" drive. sdc is the "Backup" drive. Confirmed in gparted.

But i can tell you something is wrong beacause if i try to boot the computer by the "Store" HD (selected it in BIOS) the computer seems to detect a bootloader and tries to boot it but it fails and hangs (have to do a reset). This doesnt happen with the "Backup" drive.
Its stupid because neither hard drives have the "boot flag".
I made a "chkdsk" to the "Store" HD in windows and all seems fine. No errors or bad sectors.

When i made the data backup im pretty sure that i deleted the partition table and all partitions, and created only one partition. All of this with gparted.

I think dd messed up this hard drive... Can you tell at least if there is any dd command that erases all data and all partitons (well, everything), like if it was new? So that i can start from scratch and make the backup again.

Thanks

JZL240I-U 02-14-2012 02:14 AM

Quote:

Originally Posted by [rascas] (Post 4601346)
...Now i have 2 virtually identically drives with the same data. Virtually because, now in linux (dolphin) it is showing me one of the disks having 2 partitions. My only issue is that only dolphin and the kde device manager shows me that. Gparted and fdisk tells me that there is only one partition in that disk. Windows "sees" only one partition to....

I think this is a misconception on your part (no slight intended). As hinted in my previous post, KDE shows you the device ("WDC..." aka /dev/sdb) and the partition ("store" aka /dev/sdb1). I don't understand why it isn't doing this for the other drive as well.

Several things.

First, select the left menu (Places) and try pressing <F5>. This will re-read / refresh the data.

If this doesn't work, try the other mode(s) of dolphin. There is not only "Places" but several more choices to be made from "view" (I think. My dolphin looks quite different, there I chose from an icon on the right side...). Play around with dolphin, from your screenshot one can see, that you are using only the barebone abilities of it.

And thirdly, are you booting from "Backup"? If not, umount it and unplug it, then plug it in again. Let's see what then happens.

Quote:

Originally Posted by [rascas] (Post 4601346)
...But i can tell you something is wrong beacause if i try to boot the computer by the "Store" HD (selected it in BIOS) the computer seems to detect a bootloader and tries to boot it but it fails and hangs (have to do a reset). This doesnt happen with the "Backup" drive.
Its stupid because neither hard drives have the "boot flag".
I made a "chkdsk" to the "Store" HD in windows and all seems fine. No errors or bad sectors.

Well, you dd-ed something over to the MBR of that drive. Your 'puter will try to act on that but an .iso is not organized like a hard disk. This is not dangerous as far as I can tell. Backup has obviously a "clean" MBR, so nothing happens. Linux / GRUB doesn't care for the boot flag, you can boot from anywhere.

Quote:

Originally Posted by [rascas] (Post 4601346)
...I think dd messed up this hard drive... Can you tell at least if there is any dd command that erases all data and all partitons (well, everything), like if it was new? So that i can start from scratch and make the backup again.

Umm, you issued that command ;). And yes, there is a command to zero out your drive:
Code:

dd if=/dev/zero of=/dev/sdb bs=1M
Please make really, really sure it is sdb you are wanting to flatten, because everything will be gone irrevocably.

If you just want the MBR cleaned use:
Code:

dd if=/dev/zero of=/dev/sdb bs=512B count=1
You have then to re-partition and format it.

Satyaveer Arya 02-14-2012 04:16 AM

Thanks a lot for this helpful thread. It's really helpful.. :) Hats off! :hattip:

[rascas] 02-14-2012 01:25 PM

Hi JZL240I-U.
Thank you very much!! Cleaning the MBR with the dd comand you posted did the trick!
I didnt thought too much about the dd command i issued and i was not remembering an .iso is not organized like a hard disk. Thanks for remembering me that!!!
Now dolphin shows me only the partition and not the device name, the normal way, the way i wanted it.
I know how to use dolphin. I just like to get it simple ;). If i want something with more options i generaly use konqueror.

Anyway, thank you very much for your help and time.

Regards

EDDY1 02-14-2012 03:01 PM

I don't understand why this thread hasn't been made a sticky,so that it's easily found by others. I myself have it bookmarked as there is a lot of information on a continuous basis.

AwesomeMachine 02-24-2012 01:52 PM

Not Stickied
 
Quote:

Originally Posted by EDDY1 (Post 4602384)
I don't understand why this thread hasn't been made a sticky,so that it's easily found by others. I myself have it bookmarked as there is a lot of information on a continuous basis.

The dd post is good, but it really doesn't fit as a sticky, because it's not information nearly every newbie should know before embarking on the forum. But I don't make any decisions. That's my opinion.

AwesomeMachine 02-24-2012 01:56 PM

Just a quick note regarding some posts above: If you image to both an internal drive and a USB drive, the USB drive will probably not boot correctly, because the device files are slightly different. But GRUB2 usually will work if the USB image is the entire drive.

onebuck 02-25-2012 09:24 AM

Member response
 
Hi,
Quote:

Originally Posted by AwesomeMachine (Post 4611222)
The dd post is good, but it really doesn't fit as a sticky, because it's not information nearly every newbie should know before embarking on the forum. But I don't make any decisions. That's my opinion.

I agree that Learn the DD command should NOT be a sticky. Very useful and informative thread that does elevate within the forum.

Slackware®-Links references this thread: Learn the DD command.

I think the thread could be used to create/generate a <Linux-Answer> topic.

Master_CAPS 03-20-2012 08:00 PM

LOL its called truecrypt... try that instead of this "book" on how to do this...

TobiSGD 03-20-2012 08:27 PM

Quote:

Originally Posted by Master_CAPS (Post 4632081)
LOL its called truecrypt... try that instead of this "book" on how to do this...

Posted in the wrong thread, maybe? dd has nothing at all to do with Truecrypt.

RagonichaFulva 04-03-2012 09:08 AM

Hello,

I would much appreciate your assistance.

I backuped mi /dev/sda5 partition with the following command:

Code:

sudo dd if=/dev/sda5 > /media/discoduroexterno/imagenes/partitionimage.dd
I obtained a .dd file (47 GBytes).

I tried to restore the partition (after repartitioning the disk) and with the command:

Code:

sudo dd if=/media/Maxtor/partitionimage.dd of=/dev/sda5
But the restored partition appears as if it had no format.

Now I am trying to mount the .dd file with the following command:

Code:

sudo mount -o loop -t auto /media/Maxtor/imagenes/partitionimage.dd /media/carpeta
but I obtain the following error:

Code:

mount: tipo fs incorrecto, opción incorrecta, superbloque incorrecto en /dev/loop0,
      falta página de código o programa ayudante, u otro error
      En algunos casos se encuentra información en syslog, pruebe
  dmesg | tail  o algo parecido

If I execute dmesg | tail this is the output:

Code:

0.337:29): apparmor="STATUS" operation="profile_replace" name="/usr/bin/evince//launchpad_integration" pid=2554 comm="apparmor_parser"
[  137.716848] type=1400 audit(1333351970.341:30): apparmor="STATUS" operation="profile_replace" name="/usr/bin/evince//sanitized_helper" pid=2554 comm="apparmor_parser"
[  137.718630] type=1400 audit(1333351970.341:31): apparmor="STATUS" operation="profile_replace" name="/usr/bin/evince-previewer" pid=2554 comm="apparmor_parser"
[  137.723892] type=1400 audit(1333351970.345:32): apparmor="STATUS" operation="profile_replace" name="/usr/bin/evince-previewer//launchpad_integration" pid=2554 comm="apparmor_parser"
[  137.725525] type=1400 audit(1333351970.349:33): apparmor="STATUS" operation="profile_replace" name="/usr/bin/evince-previewer//sanitized_helper" pid=2554 comm="apparmor_parser"
[  138.048707] init: plymouth-stop pre-start process (2664) terminated with status 1
[  648.843419] EXT4-fs (loop0): bad geometry: block count 69594112 exceeds size of device (11676287 blocks)
[ 1109.826664] EXT4-fs (loop0): bad geometry: block count 69594112 exceeds size of device (11676287 blocks)
[ 1204.990716] EXT3-fs (loop0): error: couldn't mount because of unsupported optional features (240)
[ 3981.553666] EXT3-fs (loop0): error: couldn't mount because of unsupported optional features (240)

It seems that the block count is giving me some problems.

Now I am using testdisk on the .dd file in order to correct any wrong value, but there is no geometry correction related to blocks.

So I am stuck here. At present I am analyzing the .dd with testdisk.

Any help would be much appreciated.

Thank you.

JZL240I-U 04-11-2012 07:45 AM

Quote:

Originally Posted by RagonichaFulva (Post 4643659)
...
I backuped mi /dev/sda5 partition with the following command:

Code:

sudo dd if=/dev/sda5 > /media/discoduroexterno/imagenes/partitionimage.dd
...

That could be the source of your troubles if you really did that and not use "of=", like you did several lines below. If I understand the working of dd correctly, you redirected the standard output to a file. The standard output shows only printed characters and not the full range of hexadecimal values, so you lost lots of information (and in essence stored garbage). Anything of my assumption the more savvy readers would like to correct?

RagonichaFulva 04-11-2012 08:40 AM

Surely the ">" symbol might be the problem. I could extract the files with photorec, but it's 47 GBytes of unordered files... :(


All times are GMT -5. The time now is 06:00 AM.