[comp.unix.aix] How do you clone a disk?

ji@cs.columbia.edu (John Ioannidis) (10/07/89)

I have a bunch of PS/2-80's (and a lot more soon to arrive) with 330MB
ESDI drives and I want to be able to have a master disk and clone every
machine off that `master' disk.

SO far I've tried some things, but none have worked satisfactorily.
Since there is NO documentation on how to install a second drive (but
FLAME ON they'll tell ou about 6.023E+23 times where the Enter key is
and that the prompt is a '$' sign FLAME OFF) I tried to do various
logical things, none of which really worked. 

Here's what I tried:

First I used minidisks(1m): the program can figure out that there is a
second disk on the controller and correctly display its partitions (I
wonder how), but it won't `name' them (first field in the menu) so I
can't change partition sizes and stuff.

Then I tried to figure out what the minor device numbers for the
second disk should be. It turned out that they start at 32, with the
32 being the entire disk, 33 being what was hd1 when the disk was the
first disk of another machine etc. I guessed that if I were to 

	# mknod /dev/hd32 b 3 32
	# dd if=/dev/hd00 of=/dev/hd32 

it would copy the entire first disk onto the second. Ha! It copied
about 700 blocks and then gave me an I/O error.

SO next I tried copying it partition by partition; I successfully
copied the / and the /<machinename> partitions, but it took an
ENORMOUS amount of time, like forty-five minutes to copy ~130M of
stuff. After a couple of fsck's I got the machine with the cloned disk
to reboot correctly, but I'm not yet satisfied.

DOes anyone have any clean and fast way to clone disks? Is there a
lower-level program than minidisks (which won't let you touch the hard
drive if the parameters it sees on it do not match /etc/filesystems,
but it won't tell you which parameters DONT match so that you can fix
them) that I can use? LIke format() on the suns, f'r instance? 

Thanks,

/ji

webb@bass.tcspa.ibm.com (Bill Webb) (10/12/89)

> I have a bunch of PS/2-80's (and a lot more soon to arrive) with 330MB
> ESDI drives and I want to be able to have a master disk and clone every
> machine off that `master' disk.
> ...
> 	# mknod /dev/hd32 b 3 32
> 	# dd if=/dev/hd00 of=/dev/hd32 
> 
> it would copy the entire first disk onto the second. Ha! It copied
> about 700 blocks and then gave me an I/O error.
>...
> /ji

I've been considering writing a utility that would use the BIOS calls
to clone disks or partitions. Having written a program to change the
partition table by opening /dev/hd00 I'm surprised that you were able
to write hd32 at all - you first have to issue an ioctl (HDIOWRT - see
<sys/mdisk.h>) before any I/O will work on a whole disk partition such
as /dev/hd00. (I assume - it didn't appear to be documented anywhere
that I saw). I suggest that you try the above after writing a program
	( hdiowrt ; dd if=/hd00 bs=... ) > /dev/hd32
Of course non of this is for the faint of heart - writting directly to
a hard disk can be very, very dangerous if you don't do it EXACTLY 
right (I assume thats why the ioctl is there in the first place).

We have found that we could copy whole disks if we used the IBM 6152
AOS 4.3 standalone disk copy utility, but that's probably not available 
to everybody (it essentially uses BIOS to access the disk).

You also have to make sure that you use the 'chparm' command
to change the name of the new machine after booting it for the first time,
and also use the boot menu to change the node name as well.

If you're installing DOS/MERGE you should do that on the actual machine
that its running on as it must run on the same hardware its installed on
because it takes a BIOS image (see the documentation).

Note of the above should be taken as any IBM support for the practice
of disk cloning, however I hope that it helps you get the job done.

Good Luck!

----------------------------------------------------------------
The above views are my own, not necessarily those of my employer.
Bill Webb (IBM AWD Palo Alto), (415) 855-4457).
UUCP: ...!uunet!ibmsupt!webb

jackv@turnkey.gryphon.COM (Jack F. Vogel) (10/15/89)

In article <363@cs.columbia.edu> ji@cs.columbia.edu (John Ioannidis) writes:
>I have a bunch of PS/2-80's (and a lot more soon to arrive) with 330MB
>ESDI drives and I want to be able to have a master disk and clone every
>machine off that `master' disk.
 
>Here's what I tried:
 
[ minidisks attempt deleted....]

>Then I tried to figure out what the minor device numbers for the
>second disk should be. It turned out that they start at 32, with the
>32 being the entire disk, 33 being what was hd1 when the disk was the
>first disk of another machine etc. I guessed that if I were to 
>
>	# mknod /dev/hd32 b 3 32
>	# dd if=/dev/hd00 of=/dev/hd32 
>
>it would copy the entire first disk onto the second. Ha! It copied
>about 700 blocks and then gave me an I/O error.
 
You had the right idea, but there is a trick to getting this to work.
You see, there is a flag that must be set to allow one to write to
the zero partition or whole device. I suppose the rational is that
only programs like minidisks and maint should need to diddle with the
whole device. However, the superuser can override this normal restriction
using a suitable ioctl first.

What you need to do is write a little program that includes <sys/mdisk.h>
and then have it do the following:

		ioctl(1,HDIOWRT)

Wrap this in the usual error handling code, naturally. Then run this program
as root and redirect stdout to /dev/hd32. You will now be able to write the
whole device and your dd scheme above should work.

One comment on cloning systems this way, by doing so you are going to have
all the clones with the same site name, not really desireable in real
world situations. Perhaps in a lab or some such situation it wouldn't matter.
Also if you were comtemplating just using the bootstrap option to change
the name afterwards, I don't believe this will work, you will have a
conflict between the site name in nvram and the vtocs. But if this is what
you want to do, now you know how.

Good luck!

Disclaimer: This is in no way an official statement of Locus or IBM.


-- 
Jack F. Vogel			jackv@seas.ucla.edu
AIX Technical Support	              - or -
Locus Computing Corp.		jackv@ifs.umich.edu

ji@close.columbia.edu (John Ioannidis) (10/16/89)

In article <6384@turnkey.gryphon.COM> jackv@turnkey.gryphon.COM writes:
>In article <363@cs.columbia.edu> ji@cs.columbia.edu (John Ioannidis) writes:
>>I have a bunch of PS/2-80's (and a lot more soon to arrive) with 330MB
>>ESDI drives and I want to be able to have a master disk and clone every
>>machine off that `master' disk.

>all the clones with the same site name, not really desireable in real
>world situations. Perhaps in a lab or some such situation it wouldn't matter.

Thanks for all the info. I'll try it. However, the above statement is
not very accurate. The only place the "machine name" is used in the
system is for network connections. /etc/rc has a line SITE=`uname -n`,
and SITE is only used by /etc/rc.tcpip to ifconfig the network
interface. By seting SITE to `cat /etc/HOSTNAME`, I can have all my
machines have exactly the same name as far as AIX is concerned, and
still get my work done. I fail to see the reason why the hostname
should be hardwired in two dozen different files and directories.

Thanks again,

/ji

In-Real-Life: John "Heldenprogrammer" Ioannidis
E-Mail-To: ji@cs.columbia.edu
V-Mail-To: +1 212 854 5510
P-Mail-To: 450 Computer Science \n Columbia University \n New York, NY 10027