Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
hd copy with dd
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 12:39 pm    Post subject: hd copy with dd Reply with quote

HD is failing so i want to make a copy of it onto a new HD
ie
Quote:
dd if=/dev/hda of=/dev/hdb


how long should this take ( 40 GB HD)

can I do this on a still-running machine ( ie our router) ?

are ther any better ways of doing it ?

eg partition the new HD and copy the partitions separately
_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sat Dec 10, 2005 1:30 pm    Post subject: Reply with quote

It's better to copy the partitions, since it's easier to create partitions of the same size, rather than getting same-sized HDDs. Besides, this way you can choose what to copy first (personal data partition before system data partition), and what not to copy at all (swap partition).

If the source device is failing, it's better to add error conversion options to dd:

Code:
dd conv=noerror,sync if=/dev/hda1 of=/dev/hdb1


How long it should take is hard to say for a dying disk... the one I had could still read 80% of it's data correctly, but at slow speed only (2-3MB/s instead of 30MB/s). So it can take very long. You can have dd output the progress using the USR1 signal (I think it was) though.
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 2:11 pm    Post subject: Reply with quote

Code:
grenada ~ # fdisk /dev/hda

The number of cylinders for this disk is set to 1245.
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/hda: 10.2 GB, 10248118272 bytes
255 heads, 63 sectors/track, 1245 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1           7       56196   83  Linux
/dev/hda2               8          70      506047+  82  Linux swap / Solaris
/dev/hda3              71        1245     9438187+  83  Linux

Command (m for help): q

grenada ~ # fdisk /dev/hdb

The number of cylinders for this disk is set to 1027.
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/hdb: 8455 MB, 8455200768 bytes
255 heads, 63 sectors/track, 1027 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1               1           7       56196   83  Linux
/dev/hdb2               8          70      506047+  82  Linux swap / Solaris
/dev/hdb3              71        1245     9438187+  83  Linux

Command (m for help): q
grenada ~ # dd                                                                                       


but ive got
Code:
grenada ~ # df /dev/hda1
Filesystem           1K-blocks      Used Available Use% Mounted on
udev                    257980        52    257928   1% /dev
grenada ~ # df /dev/hda2
Filesystem           1K-blocks      Used Available Use% Mounted on
udev                    257980        52    257928   1% /dev
grenada ~ # df /dev/hda3
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda3              9288792   3043492   5773392  35% /
grenada ~ #                                         


Im only using 35 % of the failing disk.

I assume /dev/hd?1 &2 are the same size
How do I copy the contents of /dev/hda3 to /dev/hdb3 ( which I assume are different sizes
_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sat Dec 10, 2005 2:39 pm    Post subject: Reply with quote

I think it's actually better to copy the whole partition, rather than the files. This is because when copying a partition, the hard disk doesn't have to do any seeking - it can just keep reading data on and on. When copying files, it always first has to seek to the beginning of the file before it can start reading it. This is a lot of unnecessary extra work for a dying hard disk... What's more, copying files works only on the file system layer, which may not be able to handle disk errors as "smoothly" as a raw stream reader like dd does.

If you still want to copy files rather than partition for some reason, a common way would be to use plain old cp -a or tar -p.
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 3:29 pm    Post subject: Reply with quote

Code:

grenada ~ # dd if=/dev/hda1  of=/dev/hdb1
112392+0 records in
112392+0 records out
grenada ~ # dd if=/dev/hda2 of=/dev/hdb2
dd: writing to `/dev/hdb2': No space left on device
3+0 records in
2+0 records out
grenada ~ # dd if=/dev/hda3  of=/dev/hdb3
dd: writing to `/dev/hdb3': No space left on device
515345+0 records in
515344+0 records out
grenada ~ #

_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sat Dec 10, 2005 3:39 pm    Post subject: Reply with quote

You could always try partimage, booting from a rescue CD with both hard drives attached.

http://www.partimage.org/

I use the system rescue cd:

http://www.sysresccd.org/

I used to use knoppix for such things, but the sysresccd is based on gentoo, and has a closer match to the gentoo install for things like lvm and such.
_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 3:56 pm    Post subject: Reply with quote

I was going to try and cp the stuff across.

Code:

grenada ~ # mount -t ext3 /dev/hdb3 /mnt/newdisk/
mount: /dev/hdb3 is not a block device (maybe try `-o loop'?)
grenada ~ #
       

and then just to check

Code:

grenada ~ # mke2fs -j /dev/hdb3
mke2fs 1.38 (30-Jun-2005)
/dev/hdb3 is not a block special device.
grenada ~ #                               

_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sat Dec 10, 2005 4:00 pm    Post subject: Reply with quote

What does
Code:
ls -l /dev/hdb3
show?
_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 4:17 pm    Post subject: Reply with quote

Code:

grenada ~ # ls -l /dev/hdb3
-rw-r--r--  1 root root 263856128 Dec 10 15:26 /dev/hdb3
grenada ~ #                                                         

_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sat Dec 10, 2005 4:21 pm    Post subject: Reply with quote

I see what your problem is - hdb3 is just a file & that's why you ran out of space.

It should be a block device (with a "b" in the first column).

You've copied your partition to a normal file in /dev.

I'm not sure why there is no device file there! what does ls -l /dev/hdb* show?
_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 4:25 pm    Post subject: Reply with quote

Code:
grenada ~ # ls -l /dev/hdb*
brw-rw----  1 root disk     3, 64 Dec 10 12:12 /dev/hdb
brw-rw----  1 root disk     3, 65 Dec 10 12:12 /dev/hdb1
brw-rw----  1 root disk     3, 66 Dec 10 12:12 /dev/hdb2
-rw-r--r--  1 root root 263856128 Dec 10 15:26 /dev/hdb3
brw-rw----  1 root disk     3, 69 Dec 10 12:12 /dev/hdb5
brw-rw----  1 root disk     3, 70 Dec 10 12:12 /dev/hdb6
brw-rw----  1 root disk     3, 71 Dec 10 12:12 /dev/hdb7
grenada ~ #                                                         


but i dont get this - see the output of fdisk /dev/hdb above
_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sat Dec 10, 2005 4:35 pm    Post subject: Reply with quote

Quote:
see the output of fdisk /dev/hdb above


That's what was confusing me - /dev/hdb3 should be a block special file, but it's just a plain old file. You didn't accidentally rm it at any time, did you? That's the only thing I can think of.

To re-create it, run this command:

Code:
rm /dev/hdb3
mknod /dev/hdb3 b 3 67


An ls -l /dev/hdb* should show something like this:

Code:
ls -l /dev/hdb*
brw-rw----  1 root disk 3, 64 Mar  4  2005 /dev/hdb
brw-rw----  1 root disk 3, 65 Mar  4  2005 /dev/hdb1
brw-rw----  1 root disk 3, 66 Mar  4  2005 /dev/hdb2
brw-rw----  1 root disk 3, 67 Mar  4  2005 /dev/hdb3
brw-rw----  1 root disk 3, 68 Mar  4  2005 /dev/hdb4
brw-rw----  1 root disk 3, 69 Mar  4  2005 /dev/hdb5
brw-rw----  1 root disk 3, 70 Mar  4  2005 /dev/hdb6
brw-rw----  1 root disk 3, 71 Mar  4  2005 /dev/hdb7


Once you have your block device back, you may be back up-and-running with dd.
_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 4:40 pm    Post subject: Reply with quote

Code:

grenada ~ # rm /dev/hdb3
grenada ~ # mknod /dev/hdb3 b 3 67
grenada ~ # ls -l /dev/hdb*
brw-rw----  1 root disk 3, 64 Dec 10 12:12 /dev/hdb
brw-rw----  1 root disk 3, 65 Dec 10 12:12 /dev/hdb1
brw-rw----  1 root disk 3, 66 Dec 10 12:12 /dev/hdb2
brw-r--r--  1 root root 3, 67 Dec 10 16:37 /dev/hdb3
brw-rw----  1 root disk 3, 69 Dec 10 12:12 /dev/hdb5
brw-rw----  1 root disk 3, 70 Dec 10 12:12 /dev/hdb6
brw-rw----  1 root disk 3, 71 Dec 10 12:12 /dev/hdb7
grenada ~ # dd if=/dev/hda3  of=/dev/hdb3
dd: opening `/dev/hdb3': No such device or address
grenada ~ #


_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sat Dec 10, 2005 4:41 pm    Post subject: Reply with quote

OK, the permissions are a bit wrong, but you should still be able to do your dd as root.
_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 4:42 pm    Post subject: Reply with quote

Code:
grenada ~ # whoami
root
grenada ~ # dd if=/dev/hda3  of=/dev/hdb3
dd: opening `/dev/hdb3': No such device or address
grenada ~ #


_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sat Dec 10, 2005 4:44 pm    Post subject: Reply with quote

Well that *is* odd - I guess that somehow your kernel may have lost visibility of the device. Does cfdisk still work on hdb? Maybe a reboot is in order...
_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 4:50 pm    Post subject: Reply with quote

cfdisk /dev/hdb givers a blank screen with this at the bottom of the page

FATAL ERROR: Bad primary partition 2: Partition ends after end-of-disk
Press any key to exit cfdisk

but
Code:
grenada fern # fdisk /dev/hdb

The number of cylinders for this disk is set to 1027.
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/hdb: 8455 MB, 8455200768 bytes
255 heads, 63 sectors/track, 1027 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1               1           7       56196   83  Linux
/dev/hdb2               8          70      506047+  82  Linux swap / Solaris
/dev/hdb3              71        1245     9438187+  83  Linux

Command (m for help):                         

_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sat Dec 10, 2005 4:52 pm    Post subject: Reply with quote

How much hassle would it be to recreate the partition table on hdb, and start again? (It is hdb you're copying *to*, isn't it?)

It sounds like your partition table has been corrupted. If you don't mind starting from scratch, I suggest this:

1. zero out your partition table with
Code:
dd if=/dev/zero of=/dev/hdb count=2
MAKE SURE YOU USE THE RIGHT DEVICE HERE ! 8O
2. reboot
3. create your new partitions with cfdisk
4. go back to using dd to copy your data again
_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sat Dec 10, 2005 4:54 pm    Post subject: Reply with quote

Ive been wondering whether to just start again

Thanks for the help . I'll let you know how I get on
_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sun Dec 11, 2005 1:38 pm    Post subject: Reply with quote

with the new HD as a slave I deleted the old partitions and recreated them . cfdisk now reads the new partitions
Code:
                                                                cfdisk 2.12i

                                                              Disk Drive: /dev/hdb
                                                         Size: 8455200768 bytes, 8455 MB
                                              Heads: 16   Sectors per Track: 63   Cylinders: 16383

       Name                  Flags               Part Type          FS Type                       [Label]                    Size (MB)
 -----------------------------------------------------------------------------------------------------------------------------------------------
       hdb1                                       Primary           Linux ext3                                                   32.52
       hdb2                                       Primary           Linux swap / Solaris                                        512.49
       hdb3                                       Primary           Linux                                                      7910.21




but

Code:
grenada ~ # ls -l /dev/hd*
brw-rw----  1 root disk     3,  0 Dec 11 12:46 /dev/hda
brw-rw----  1 root disk     3,  1 Dec 11 12:46 /dev/hda1
brw-rw----  1 root disk     3,  2 Dec 11 12:46 /dev/hda2
brw-rw----  1 root disk     3,  3 Dec 11 12:46 /dev/hda3
brw-rw----  1 root disk     3, 64 Dec 11 12:46 /dev/hdb
-rw-r--r--  1 root root  57544704 Dec 11 12:55 /dev/hdb1
-rw-r--r--  1 root root 206323712 Dec 11 12:55 /dev/hdb2
-rw-r--r--  1 root root         0 Dec 11 12:56 /dev/hdb3
grenada ~ #                                   


why are the new partitions not being created as block devices ?
_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sun Dec 11, 2005 5:00 pm    Post subject: Reply with quote

This is *really* weird.

Is this what your /dev/hd* looks like after a reboot?
_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sun Dec 11, 2005 8:47 pm    Post subject: Reply with quote

reboot sorted it
Code:
grenada ~ # ls -l /dev/hd*
brw-rw----  1 root disk 3,  0 Dec 11 20:09 /dev/hda
brw-rw----  1 root disk 3,  1 Dec 11 20:09 /dev/hda1
brw-rw----  1 root disk 3,  2 Dec 11 20:09 /dev/hda2
brw-rw----  1 root disk 3,  3 Dec 11 20:09 /dev/hda3
brw-rw----  1 root disk 3, 64 Dec 11 20:09 /dev/hdb
brw-rw----  1 root disk 3, 65 Dec 11 20:09 /dev/hdb1
brw-rw----  1 root disk 3, 66 Dec 11 20:09 /dev/hdb2
brw-rw----  1 root disk 3, 67 Dec 11 20:09 /dev/hdb3
grenada ~ #


when I do
Code:
dd conv=noerrors,sync if=/dev/hda2 of=/dev/hdb2
the HD clicks a lot and hangs - I assume this is the partition where the problem is.
Do i need to copy the contents of a swap partition over ?

the new /hdb3 is smaller than the old /hda3 so i assume dd will run out of space

I assume I have to copy the files across with cp but when i try that i get
Code:
grenada ~ # mount -t ext3 /dev/hdb3 /mnt/newdisk

_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sun Dec 11, 2005 9:34 pm    Post subject: Reply with quote

No, you don't need to copy swap partitions.
Back to top
View user's profile Send private message
morodoch
Guru
Guru


Joined: 22 Sep 2005
Posts: 523
Location: England

PostPosted: Sun Dec 11, 2005 10:38 pm    Post subject: Reply with quote

You just need to mkswap the new swap partition.

If you can mount both the old partition and the new partition, you should be able to do something like this to copy the files over:

Quote:
cp -ax /mnt/oldpartition/. /mnt/newpartition/.

_________________
Well, the Sister was right. You boys could use a little churching up. Slide on down to the Triple Rock, and catch Rev. Cleophus. You boys listen to what he's got to say.

-- Curtis
Back to top
View user's profile Send private message
thecooptoo
Veteran
Veteran


Joined: 27 Apr 2003
Posts: 1353
Location: UK

PostPosted: Sun Dec 11, 2005 11:02 pm    Post subject: Reply with quote

thanks

what NOT to do is

cp -Rp / /mnt/newdisk

it copies all the symlinked files as well ( I did RTFM but clearly didnt understand it )

I'll have another go tomorrow
_________________
join the optout - http://nhsconfidentiality.org
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum