LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-05-2005, 04:20 PM   #1
vulture99
LQ Newbie
 
Registered: Jan 2005
Posts: 7

Rep: Reputation: 0
cloning disk using cp - no special devices for target disk


I plan to clone one disk to another nightly, using cp:

cp /dev/hda /dev/hde

This works well, successfully copying the partition table and data. However, I am unable to mount the /dev/hde partitions since none of the associated special devices exist:

$ sudo mkdir /test
$ sudo mount /dev/hde1 /test
mount: special device /dev/hde1 does not exist

$ ls -la /dev/hd*
brw-rw---- 1 root disk 3, 0 2005-05-05 00:43 /dev/hda
brw-rw---- 1 root disk 3, 1 2005-05-05 00:43 /dev/hda1
brw-rw---- 1 root disk 3, 2 2005-05-05 00:43 /dev/hda2
brw-rw---- 1 root disk 3, 3 2005-05-05 00:43 /dev/hda3
brw-rw---- 1 root disk 3, 4 2005-05-05 00:43 /dev/hda4
brw-rw---- 1 root cdrom 22, 0 2005-05-05 00:44 /dev/hdc
brw-rw---- 1 root disk 33, 0 2005-05-05 00:43 /dev/hde

Should I manually create the /dev/hde special devices (to match those on /dev/hda, since /dev/hde will be a clone) using mknod? Or is there another approach? My goal is to have a bootable copy of the system disk.

Thanks. Here's the detailed disk info:


$ sudo fdisk -l /dev/hda

Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1216 9767488+ 83 Linux
/dev/hda2 1217 1824 4883760 83 Linux
/dev/hda3 1825 4256 19535040 83 Linux
/dev/hda4 4257 4865 4891792+ 82 Linux swap / Solaris

$ sudo fdisk -l /dev/hde

Disk /dev/hde: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hde1 * 1 1216 9767488+ 83 Linux
/dev/hde2 1217 1824 4883760 83 Linux
/dev/hde3 1825 4256 19535040 83 Linux
/dev/hde4 4257 4865 4891792+ 82 Linux swap / Solaris

Last edited by vulture99; 05-05-2005 at 04:24 PM.
 
Old 05-05-2005, 05:22 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,398

Rep: Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965
you can't just copy a whole disk with cp, not a chance. cp copies files, and /dev/ entries are not files... to clone a disk outright, you'd use dd, but you need to unmount all relevant partitions in order to do it safely, which means using a boot disk or something to avoid mounting any part of your primary master drive
 
Old 05-05-2005, 06:13 PM   #3
vulture99
LQ Newbie
 
Registered: Jan 2005
Posts: 7

Original Poster
Rep: Reputation: 0
You're right that dd actually *clones* a disk, empty space and all. But cp can definitely be used to copy the entire contents of a raw device.

My goal is to have a bootable copy (or clone) of the system disk as part of a backup plan. As long as it boots and functions, I don't care if a few log files change while the disk is being copied. What I'm not sure about is how to handle the special devices.

I understand your point about files changing during a copy, but take a look at what other folks have to say about using cp:

Quote:
Are you using identical disks? If so, here is what I do:
# cp /dev/hda /dev/hdb
Does the same thing as dd. cp understands that I am referencing raw disk
devices rather than file systems, and behaves correctly. I did not
partition the disk prior to the copy. This copied my MBR, extended
partitions, Linux partitions, swap partition, and Windoze partitions,
and the resulting disk boots and runs just like the original one. As I
recall, it took me 35 minutes to copy a 20G disk.
comp.os.linux.misc post
Quote:
Using dd to copy a 'live' system disk is likely to be bad news. It is
not a problem using dump/cpio/tar/cp/etc. since these are work at the FS
level and won't be affected by (normal) low-level changes to the
filesystem -- all that would be lost would be randomly updated system
files (eg log files), which won't affect the runablity of the cloned
system disk.
comp.os.linux.misc post
 
Old 05-05-2005, 06:50 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,500

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
cp and dd are doing here the very same things, actually dd gives you more control about the process and would probably run faster.

Anyway, cloning disks with mounted partitions is madness, unless you are in a very very quiest state: single user mode with no file write during the copy.

About you issue with missing devices, did you reboot or run MAKEDEV to have them created ?
 
Old 05-05-2005, 07:12 PM   #5
nxny
Member
 
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771

Rep: Reputation: 30
If the kernel is not letting you mount for instance say /dev/hde4, it might be due to the fact that the kernel is still using the old partition table. Read somethere that tools such as partx and GNU Parted can make the kernel reread the partition table when the new PT is written by the said tool. fdisk lacks this feature, not to mention dd and cp. I took the easy way out by rebooting.

If your device files are not present, run MAKEDEV, but beware that mknod will complain about existing devices.
 
Old 05-06-2005, 05:10 PM   #6
vulture99
LQ Newbie
 
Registered: Jan 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Hmmm, ok. Thanks for the input. I did `cp /dev/hda /dev/hde` and then tried MAKEDEV but couldn't get it to work. The command output indicated MAKEDEV created all the /dev/hde* files properly, but they did not appear. I ended up rebooting and that created the device files properly.

Point taken about dropping to single user mode. I am thinking of doing something like this (untested):

Code:
#!/bin/bash
/sbin/init 1
for i in 1 2 3 4;
  do
    /bin/umount /dev/hda$i
  done
/bin/cp /dev/hda /dev/hde  # or: dd if=/dev/hda of=/dev/hde bs=512
/bin/mount -a
/sbin/init 3
# done
 
Old 05-08-2005, 05:36 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,500

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Some comments:
- I'm not sure your script won't be interrupted by the state change (init 1).
- you won't be able to umount the partition where / stays (hda1 I guess).
- bs=512 is a very poor dd tuning, try using something like bs=1024k to optimize you I/Os.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cloning 1 hard disk to smaller hard disk, dd or ghost? fireman949 Linux - Hardware 8 12-23-2012 12:51 AM
Disk cloning question valnar Linux - Software 4 06-07-2005 02:41 PM
Cloning boot disk using DD vanibhat Linux - Hardware 3 12-01-2004 03:35 PM
Target Disk Freeze hew Slackware 7 05-20-2003 01:45 AM
Disk Cloning sts_cat Linux - General 1 03-24-2003 11:30 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration