LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem involving *DD* command (https://www.linuxquestions.org/questions/linux-newbie-8/problem-involving-%2Add%2A-command-669586/)

garyg007 09-12-2008 06:50 PM

Problem involving *DD* command
 
copied an 80gig hard drive to an 80gig partition created on a 500gig hard drive. Used this command
80g hd = /dev/sda
500g hd = /dev/sdc;
Partition sdc1 exists.
added partition sdc2
executed command dd if=/dec/sda of=/dev/sdc2
here is the fdisk partition table for /dev/sdc2
Code:

Abitbox:~ # fdisk /dev/sdc2

The number of cylinders for this disk is set to 10335.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sdc2: 85.0 GB, 85008268800 bytes
255 heads, 63 sectors/track, 10335 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000aaca0

    Device Boot      Start        End      Blocks  Id  System
/dev/sdc2p1  *          1          13      104391  83  Linux
/dev/sdc2p2              14        9733    78075900    5  Extended
/dev/sdc2p5              14        778    6144831  83  Linux
/dev/sdc2p6            779        2053    10241406  83  Linux
/dev/sdc2p7            2054        2690    5116671  83  Linux
/dev/sdc2p8            2691        3965    10241406  83  Linux
/dev/sdc2p9            3966        4347    3068383+  83  Linux
/dev/sdc2p10          4348        4857    4096543+  83  Linux
/dev/sdc2p11          4858        9446    36861111  83  Linux
/dev/sdc2p12          9447        9733    2305296  82  Linux swap / Solaris

Command (m for help): q

How do I mount this mess? If I try
Code:

mount /dev/sdc2 /media/sdc2
It wants a filesystem type
If I try
Code:

mount /dev/sdc2/sdc2p10 /media/sdc2p10
it tells me:
Quote:

mount: special device /dev/sdc2/sdc2p10 does not exist

i92guboj 09-12-2008 07:10 PM

Quote:

Originally Posted by garyg007 (Post 3278790)
executed command dd if=/dec/sda of=/dev/sdc2

So you dumped a whole drive (with ALL its partitions) inside a single partition. Not a good thing. I'd just delete that partition (sdc2) and plan another way to copy the data.

keefaz 09-12-2008 07:20 PM

That is not the first person who wrongly think that dd is good for copy files
dd does not copy files
dd copies only blocks of data which means file fragments
If you use cp or similar command to copy files instead the program is designed to fail gracefully if the copied file has not been completly copied for some reason, also I think it is better for the destination drive because it will be much less fragmented than with dd

mcl 09-12-2008 07:46 PM

device-mapper
 
if you've got device-mapper on your system, you could try using that.
it may have automatically seen the sub-partitions on boot.
have a look in /dev/mapper and see if those partitions show up. then you can just do "mount /dev/mapper/sdc2p1 /eg/mount/point"

onebuck 09-12-2008 08:06 PM

Hi,
Quote:

Originally Posted by keefaz (Post 3278800)
That is not the first person who wrongly think that dd is good for copy files
dd does not copy files
dd copies only blocks of data which means file fragments
If you use cp or similar command to copy files instead the program is designed to fail gracefully if the copied file has not been completly copied for some reason, also I think it is better for the destination drive because it will be much less fragmented than with dd

Not to be smart but the 'man dd';
Code:

excerpt from 'man dd';

DD(1)                                                                    DD(1)

NAME
      dd - convert and copy a file

SYNOPSIS
      dd  [--help]  [--version]  [if=file]  [of=file] [ibs=bytes] [obs=bytes]
      [bs=bytes]  [cbs=bytes]  [skip=blocks]  [seek=blocks]  [count=blocks]
      [conv={ascii, ebcdic, ibm, block, unblock, lcase, ucase, swab, noerror,
      notrunc, sync}]

DESCRIPTION
      dd copies a file (from standard input to standard output,  by  default)
      using specific input and output blocksizes, while optionally performing
      conversions on it.

      It reads the input one block at a time, using the specified input block
      size (the default is 512 bytes).  If the bs=bytes option was given, and
      no conversion other than sync, noerror, or notrunc  was  specified,  it
      writes  the  amount  of data read (which could be smaller than what was
      requested) in a separate output block. This output block has  precisely
      the  same  length as was read unless the sync conversion was specified,
      in which case the data is padded with NULs (or spaces, see below).

Sure to use the 'dd' command you had better know what your doing. Read the man!

Quakeboy02 09-12-2008 08:44 PM

Regardless of what the man page says, it's not going to magically understand that the OP is starting with a disk(if=/dec/sda) but wants to convert it to a filesystem on the destination partition(of=/dev/sdc2). What's going to happen is that an image of the drive is going to be plopped at /dev/sdc2 with no way to access it. It would work with dd if=/dev/sda of=/dev/sdc, but that's not what's asked for. "dd" is probably the most confusing command on *nix, and I'm surely not an expert, but I don't see a way for "dd" to do what is asked. If it is necessary that all partitions on /dev/sda need to be copied to partition /dev/sdc2, then a series of filecopies is needed.

For example:
Code:

mount /dev/sda1 /source
mount /dev/sdc2 /dest
cp -axu /source /dest

Remount source as /dev/sda2 and then repeat for all partitions.

OTOH, if it's wanted to make a copy of /dev/sda on /dev/sdc, then that is possible by doing a "dd" copy and then fixing the partitions in /dev/sdc. I believe there is an example of doing this in this introductory thread on the use of "dd":

http://www.linuxquestions.org/questi...ght=dd+command

garyg007 09-13-2008 12:20 PM

The system I tried to copy, was corrupted and although it would boot it would not do much else. fsck found three of the file systems corrupted and tried to 'fix' them; the filesystems were '/' , '/var' , and '/home'. When I booted with a suse live-cd and mounted /dev/sda6 (which is '/var') - it was empty - so the fsck had obviously orphaned quit a bit of data.

I wanted to save as much data as possible for reference after re-installing linux.

After reviewing one of the threads in this forum ("Learn the DD command") I decided to use "dd" rather than "partimage" (which I've never had a lot of success with)

The original data no longer exists, Linux has been re-installed into that space; I am now in the process trying to rebuild what I had.

Quakeboy02 09-13-2008 12:43 PM

Do you actually see /dev/sdc2p10 when you do an "ls /dev"? If so, did you try the following?
Code:

# mount -t auto /dev/sdc2p10 /mnt
There is one thing you might be able to do with /dev/sdc2, and that's try mounting it with the "-o loop" option, such as:
Code:

# mount -t auto -o loop /dev/sdc2 /mnt
or whatever the proper syntax is. Give it a try. If it mounts, then you would mount the partitions under "/mnt". Not saying this will work, but grasping at straws.

One final option is to get another drive and dd sdc2 to that drive, such as:
Code:

dd if=/dev/sdc2 of=/dev/sdd
That should give you a working drive and access to the data, if the odd suggestions above don't work.

garyg007 09-14-2008 06:24 PM

Quote:

Originally Posted by Quakeboy02
Do you actually see /dev/sdc2p10 when you do an "ls /dev"?

No; Where I see it is when I do an
Code:

# fdisk /dev/sdc2
then option 'p' The output of this was pasted into my opening post.

Quote:

Originally Posted by Quakeboy02
There is one thing you might be able to do with /dev/sdc2, and that's try mounting it with the "-o loop" option, such as:
Code:

# mount -t auto -o loop /dev/sdc2 /mnt

Unfortunately, mounting as a loop device does not work

I took a look at "device-mapper" as suggested above by "mcl".
I was not able to get a good enough understanding of
device-mapper

jiml8 09-14-2008 06:50 PM

What you have done is put an image of the entire sda drive into the partition at sdc2. The first 512 bytes of that image are the master boot record, followed by the first partition on sda, then the second partition on sda, etc.

You cannot mount this; it just won't mount. I am pretty sure that the partition sdc2 won't mount either because you have hosed the partition boot record. If you run testdisk on this hard drive (sdc), it will find your partitions - including those you imaged in from sda - and may be able to build you a working partition table. In fact, I would expect this to work so long as sdc1 is defined as a physical partition. It won't work if sdc1 is an extended partition.

After it gives you a working partition table, then you can try mounting those partitions and see what you see.

edit: Before you do this, I would suggest that you re-image the entire sdc2 to some other hard drive for safekeeping. Testdisk will rewrite the sdc partition table and this will cause you to lose the information on the starting point of your current image. Should something go wrong, this could leave you in bad shape.

For that matter, if you re-image correctly to some other HD, you could then correctly use dd to just move your partitions to the new HD.

I use dd for this kind of thing all the time. In spite of the comments others here have made about dd, I find it to be extremely useful for this kind of thing. particularly when I am trying to recover off of a hard drive that is failing or failed. You do have to know what you are doing though.

jiml8 09-14-2008 06:58 PM

From my notes on various commands and things:
--------------------------------------------------------------------------------------------------------
Sizing partitions, determining start and end using linux fdisk, and organizing so dd can image

fdisk -l will give an output that specifies the # heads, the # of sectors/track, and the number of cylinders on the drive. For each partition, fdisk will list the starting cylinder and the ending cylinder, and the size in sectors; by default the formatting tools will use cylinder boundaries. Linux uses sectors that are 1024 bytes, which is 2 - 512 byte blocks. dd wants the starting sector and the size of the partition, in appropriate units. Default size for dd is blocks of 512 bytes.

To get the starting sector of the partition, take the end cylinder of the previous partition. Multiply that number by the number of sectors/track, then by the number of heads. This gives the first sector of the last track of the previous partition. Now add in the number of sectors/track to this number and the result is the first sector of the first track of the first cylinder of the next partition.

To get the size of the partition, subtract the beginning cylinder from the end cylinder and add one (to get the cylinder count). Then multiply this number by the sectors/track and the # heads. Then subtract the sectors/track from the result to get the total sectors in the partition. The size of the partition may also be determined in sectors by taking the size listed by fdisk (in "blocks"), multiplying it by 2, and adding 1.

Alternatively, sfdisk -l -sf /dev/sd# will give the start block and size directly

Quakeboy02 09-14-2008 07:10 PM

Quote:

Originally Posted by garyg007 (Post 3280398)
Unfortunately, mounting as a loop device does not work

Well, I was just hoping and grasping at straws.

Quakeboy02 09-14-2008 07:13 PM

Quote:

Originally Posted by jiml8 (Post 3280411)
You cannot mount this; it just won't mount. I am pretty sure that the partition sdc2 won't mount either because you have hosed the partition boot record. If you run testdisk on this hard drive (sdc), it will find your partitions - including those you imaged in from sda - and may be able to build you a working partition table. In fact, I would expect this to work so long as sdc1 is defined as a physical partition. It won't work if sdc1 is an extended partition.

Hey Jim,

Before you drop this, I have an idea and thought I'd check it with you. Normally dd copies an image, and I'm pretty sure you can copy the image of a drive to an iso and then open that with loop. If he were to dd /dev/sdc2 to an iso file, would that iso mount with loop and be the original drive that was copied? Or do I understand even less than I think I do of dd? :) Of course, it all depends on having enough disk space. 80GB is an awfully big iso.

jiml8 09-14-2008 07:27 PM

Quote:

Originally Posted by Quakeboy02 (Post 3280427)
Hey Jim,

Before you drop this, I have an idea and thought I'd check it with you. Normally dd copies an image, and I'm pretty sure you can copy the image of a drive to an iso and then open that with loop. If he were to dd /dev/sdc2 to an iso file, would that iso mount with loop and be the original drive that was copied? Or do I understand even less than I think I do of dd? :) Of course, it all depends on having enough disk space. 80GB is an awfully big iso.

You can copy the image of a partition to an iso file, mount it with loop, and open it. Yes, this works just fine.

The problem is that he has not imaged a partition but a drive. You can't mount a drive, only a partition on a drive. This is true even if the drive has only one partition.

I note that fdisk did pick up the partitions in sdc2. That suggests that there might be a way to mount them as they sit, but I don't know what that way would be exactly.

You'd have to study mknod I think, and find a way to make a node in /dev for the partitions in the partition. Then they'd mount. Not sure how to do that though.

garyg007 09-15-2008 06:55 PM

jiml8 and Quakeboy02:

Thank your for the comments - much appreciated.

jiml8 - after reading you last post, I had, what may be an obtuse thought: I am going to try and copy the partition /dev/sdc2 with dd creating an iso file, which I believe you indicated could be mounted.

EDIT-re-read the last two posts with my head on streight, and I think this is what you stated would not work

another thought I had was to try and create an LVM on /dev/sdc2; but it looked like all of the data would be lost.

gary


All times are GMT -5. The time now is 05:25 AM.