LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-12-2008, 07:50 PM   #1
garyg007
Member
 
Registered: Aug 2008
Location: north-east ohio
Distribution: Debian-squeeze/stable;
Posts: 279
Blog Entries: 1

Rep: Reputation: 31
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
 
Old 09-12-2008, 08:10 PM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by garyg007 View Post
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.
 
Old 09-12-2008, 08:20 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
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
 
Old 09-12-2008, 08:46 PM   #4
mcl
LQ Newbie
 
Registered: Sep 2008
Posts: 1

Rep: Reputation: 0
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"
 
Old 09-12-2008, 09:06 PM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 12,603
Blog Entries: 25

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Hi,
Quote:
Originally Posted by keefaz View Post
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!
 
Old 09-12-2008, 09:44 PM   #6
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,277

Rep: Reputation: 126Reputation: 126
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
 
Old 09-13-2008, 01:20 PM   #7
garyg007
Member
 
Registered: Aug 2008
Location: north-east ohio
Distribution: Debian-squeeze/stable;
Posts: 279
Blog Entries: 1

Original Poster
Rep: Reputation: 31
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.
 
Old 09-13-2008, 01:43 PM   #8
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,277

Rep: Reputation: 126Reputation: 126
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.

Last edited by Quakeboy02; 09-13-2008 at 01:45 PM.
 
Old 09-14-2008, 07:24 PM   #9
garyg007
Member
 
Registered: Aug 2008
Location: north-east ohio
Distribution: Debian-squeeze/stable;
Posts: 279
Blog Entries: 1

Original Poster
Rep: Reputation: 31
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
 
Old 09-14-2008, 07:50 PM   #10
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
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.

Last edited by jiml8; 09-14-2008 at 07:55 PM.
 
Old 09-14-2008, 07:58 PM   #11
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
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
 
Old 09-14-2008, 08:10 PM   #12
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,277

Rep: Reputation: 126Reputation: 126
Quote:
Originally Posted by garyg007 View Post
Unfortunately, mounting as a loop device does not work
Well, I was just hoping and grasping at straws.
 
Old 09-14-2008, 08:13 PM   #13
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,277

Rep: Reputation: 126Reputation: 126
Quote:
Originally Posted by jiml8 View Post
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.
 
Old 09-14-2008, 08:27 PM   #14
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by Quakeboy02 View Post
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.
 
Old 09-15-2008, 07:55 PM   #15
garyg007
Member
 
Registered: Aug 2008
Location: north-east ohio
Distribution: Debian-squeeze/stable;
Posts: 279
Blog Entries: 1

Original Poster
Rep: Reputation: 31
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

Last edited by garyg007; 09-15-2008 at 08:03 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems involving installation Visual Basic Imp Linux - Newbie 2 04-25-2006 05:14 PM
Compile errors involving lstdc++ kmullin Programming 0 05-25-2004 02:21 PM
Question involving kernel compile synapse Slackware 2 04-28-2004 03:53 PM
Kernel problem involving recognition of partitions. binarynova Linux - General 0 02-18-2004 06:48 PM
Multiple os installation involving Linux 7.0 mk1_1 Linux - Software 1 01-15-2002 03:04 PM


All times are GMT -5. The time now is 05:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration