File: ward.html

package info (click to toggle)
lg-issue89 1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,804 kB
  • ctags: 80
  • sloc: xml: 106; makefile: 34; sh: 34; perl: 1
file content (335 lines) | stat: -rw-r--r-- 12,150 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<!--startcut  ==============================================-->
<!-- *** BEGIN HTML header *** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>Cloning workstations with Linux LG #89</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!-- *** END HTML header *** -->

<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->

<!--endcut ============================================================-->

<TABLE BORDER><TR><TD WIDTH="200">
<A HREF="http://www.linuxgazette.com/">
<IMG ALT="LINUX GAZETTE" SRC="../gx/2002/lglogo_200x41.png" 
	WIDTH="200" HEIGHT="41" border="0"></A> 
<BR CLEAR="all">
<SMALL>...<I>making Linux just a little more fun!</I></SMALL>
</TD><TD WIDTH="380">


<CENTER>
<BIG><BIG><STRONG><FONT COLOR="maroon">Cloning workstations with Linux</FONT></STRONG></BIG></BIG>
<BR>
<STRONG>By <A HREF="../authors/ward.html">Alan Ward</A></STRONG>
</CENTER>

</TD></TR>
</TABLE>
<P>

<!-- END header -->








<p>Anybody who has had to install a park of 10 - 100 workstations with exactly
the same operating system and programs will have wondered if there is
a neater - and faster - way of doing it than moving the CDs around from box to 
box. Cloning consists in installing - once - a model workstation setup, and then
copying it to all the others.</p>

<p>The purpose of this text is to explore several of the many ways of cloning
a workstation hard disk configuration. In the cloning process, we will use
the native possibilities of Linux to produce more or less the same effect as
the well-known Norton Ghost of the Windows world.</p>

<p>Though we will be booting the workstations under Linux, the final operating
system they will be running may or may not be Linux. Actually, I use this
system for a park of Windows ME workstations that get to be reformatted at least
once a year - for evident reasons.</p>

<hr>
<p><b>Hard disk switching</b></p>

<p>The oldest way of cloning a hard disk requires two workstations (A is the model,
B is the clone), and another computer C. Only C needs to run Linux.</p>

<p>1. We take the hard drives out of the two workstations, and add them to C.
Take care to leave C's original hard disk in the first IDE position. For example:</p>

<pre>
	IDE bus 0, master	=&gt;	C's hard disk	=&gt;	/dev/hda
	IDE bus	0, slave	=&gt;	A's hard disk	=&gt;	/dev/hdb
	IDE bus 1, master	=&gt;	B's hard disk	=&gt;	/dev/hdc
</pre>

<p>We then get to copy the contents of /dev/hdb to /dev/hdc. If they are both the
exact same model, we can get by with a plain byte-by-byte copy:</p>

<pre>
	dd if=/dev/hdb of=/dev/hdc
</pre>

<p>or even:</p>

<pre>
	cp /dev/hdb /dev/hdc
</pre>

<p>These are the easiest ways of doing the copy, however you should be aware of
the following points:</p>

<p><ul>
<li>The hard disks must be the </u>exact same model</u>: you have problems with
more recent/older versions of the same hard disk.</li>
<li>You may have problems with bad sectors in either A or B.</li>
<li>You are also copying all the blank parts of the A disk to B; this can take
some time and is useless for our purposes.</li>
</ul></p>

<p>This way can be the best for people using bootloaders such as lilo or grub,
as the bootsector is copied along with the rest.</p>

<p>The second, slightly more complicated way of copying A to B consists in two
steps:</p>

<p><ul>
<li>First, you get to set up B's partition table (with fdisk, cfdisk, ...)</li>
<li>You then format B's partitions (with mkfs.ext2, mkfs.vfat, mkswap)</li>
<li>You do the actual copying.</li>
</ul></p>

<p>In this case, copying means mounting:</p>

<pre>
	mkdir /mount/A ; mkdir /mount/B
	mount /dev/hdb /mount/A
	mount /dev/hdc /mount/B
	cp -dpR /mount/A/* /mount/B
	umount /dev/hdb ; umount /dev/hdc
</pre>

<p>This can be a bit of a pain if there are a lot of workstations to clone, but
takes less time than a complete install ... and you are sure they have the same
configuration.</p>

<font color=#b00000>
<p><b>Important</b>: if you are using a bootloader such as lilo or grub to
boot a Linux workstation, you then get to write a personalized bootloader
configuration file and install it on disk B's boot sector.</p>

<p>Basically, you need to tell the bootloader:</p>

<p><ul>
<li>To use disk /dev/hdc to write the boot sector on; this is where your cloned
hard disk currently is.</li>
<li>To use disk /dev/hda to boot from; this is where your cloned hard disk will
be when you boot from it.</li>
</ul></p>

<p>Be careful: you may end up having to use your rescue disks if you do this
wrong! Been there, done that. You've been warned. Before starting, take a close
look at your current /etc/lilo.conf or /boot/grub/menu.lst files, and at their
man pages</p>

<p><b>Alternatively</b>, if you are just booting Linux you can:</p>

<p><ul>
<li>copy the files to disk B</li>
<li>put disk B back into workstation B</li>
<li>boot workstation B from the rescue diskette you built for workstation A when
installing the system</li>
<li>run lilo or grub directly</li>
</ul></p>

<p>This second way can be much easier for people with less flying time on Linux
systems. :-)</p>
</font>

<p>Another version of the same setup is, if C's disk is large enough, to copy once
from A to C, and then to copy many times from C to B1, B2, B3 ... etc. If your
IDE setup has enough busses (or you are using SCSI) you can copy 5 disks
or more at a time.</p>

<p>Neadless to say, we use this only if we have no networking set up - a rather
uncommon situation these days. However, speed can be rather high as we are working
directly at IDE-interface speeds.</p>


<hr>
<p><b>Copying over a network</b></p>

<p>Copying over a network consists in booting workstation B with a diskette or
CD into an operating system that can drive the network (let's see now ... here Linux
is in, Windows is out) and getting the hard disk image either directly from
station A, or more commonly from a file server C. In our examples, I will use
workstation B as the computer to be configured and suppose we have the image files
from workstation A copied to a directory on server C.</p>

<p>There are several "tiny" Linux-on-a-diskette distributions available out there.
MicroLinux (<i>muLinux</i>) is my favourite, but they all work in similar ways.</p>

<p>The idea is to boot from the diskette, and set up networking.</p>

<p>You can then either:</p>

<p><ul>
<li>Have a complete hard disk image on the server, which you then copy onto the local
disk with a byte-by-byte copy. As with a direct hard disk to hard disk copy, it is
easier to set up, but also has the same caveats.</li>
<li>Have the filesystem available on the server, which means you get to partition the
local disk, format the partitions and recursively copy the files from the network
onto you disk.</li>
</ul></p>

<p>An example of the first way, over NFS:</p>

<pre>
	mkdir /mount/C
	mount server:/exported.directory /mount/C
	dd if=/mount/C/my.image of=/dev/hda
	umount server:/exported.directory
</pre>

<p>An example of the second (supposing you already have set up and formatted the 
partitions on local hard disk /dev/hda):</p>

<pre>
	mkdir /mount/B ; mkdir /mount/C
	mount /dev/hda /mount/B
	mount server:/exported.directory /mount/C
	cp -dpR /mount/C/* /mount/B
	umount server:/exported.directory /mount/C
	umount /dev/hda
</pre>

<p>In the second case, if you use a bootloader, remember to install it either
immediately after copying the files, or after rebooting workstation B from a
rescue diskette.</p>

<p>The nice thing about Linux is that in essence, copying an image or separate files
from a network is exactly the same as from another hard disk on your computer.</p>

<p>NFS is naturally not the only way of downloading the file or files from server C. There
are actually as many suitable protocols as you have available clients on your bootable
diskette. I would suggest you use whatever server you already have installed on your
network. Some choices:</p>

<table border=1>
<tr><td>NFS (Network File System)</td>
<td>This is the native way Un*x systems use to share files; robust and easy to
set up. My favourite.</td></tr>
<tr><td>HTTP (as in Web server)</td>
<td>Easy to set up on the server side, but it can be difficult to find a suitable
client. Used mainly with automated install scripts. You may already have one of these
running.</td></tr>
<tr><td>FTP</td>
<td>Less easy on the server side, but very easy to find clients. You may already have
one of these running.</td></tr>
<tr><td>TFTP (trivial FTP)</td>
<td>Very easy to set up on the server, very easy to use the client. Many routers (eg. Cisco)
use tftp to store their configuration files.</td></tr>
<tr><td>SMB (or Netbios)</td>
<td>Yes, this works. Your server can run either Linux + Samba or any version of WinXX.
The client Linux system on workstation B can mount volumes using <i>smbmount</i>.
Why you would ever want to is your business, though.</td></tr>
<tr><td>rcp or scp</td>
<td>(scp is preferable for security)</td></tr>
<tr><td>rsync</td>
<td>Another favourite of mine. Used normally to synchronize a back-up file or web
server to the main server. This can be a bit of a security hole if server C is
accessible from outside your network, so take care to block this on your firewall.
Performs compression.</td></tr>
</table>

<p>There is a recent on-a-CD distribution called <i>Knoppix</i> that boots you directly
into a KDE desktop. From here, you can use all your regular graphics-based file
tools if you are so inclined.</p>

<hr>
<p><b>Booting from the network</b></p>

<p>A final twist is to boot workstation B directly from the network without using
a boot diskette. The idea is to tell the BIOS to load a minimum network driver
from an EPROM. Control is then passed to this driver, which goes onto the network
searching for a DHCP server it can get an IP address and a kernel image from. It
then boots the kernel, which in turn gets the root filesystem from an NFS server.</p>

<p>By this time, workstation B is up and running with a Linux system. You can then
format its local hard disk and copy files from the server.</p>

<p>Needless to say, this rather more complicated to set up than a diskette or CD
Linux system. However, the process can be completely automated and suits large
networks with many workstations that must be reconfigured often.</p>

<p>Another twist of the same is to dispense completely with the local hard disks
on workstations B1, B2, B3 ... and have them boot each time from the network.
Users' files are stored on the central NFS file server.</p>

<hr>
<p><b>Further reading</b></p>

<p>Another program used by many scientific cluster administrators is <i>dolly</i>.
I've heard a lot of good about it, but have not tried it out yet.</p>

<p>On booting from a network, look up <i>etherboot</i> or, if your hardware 
supports it, <i>PXE</i>.
<hr>

<p>PS. Should anybody want to translate this article: I wrote it in
the spirit of  the GPL software licence. i.e. you are free (and
indeed encouraged) to copy, post and translate it -- but please,
PLEASE, send me notice by email!  I like to keep track of translations --
it's good for the curriculum :-)</p>









<!-- *** BEGIN author bio *** -->
<P>&nbsp;
<P>
<!-- *** BEGIN bio *** -->
<P>
<img ALIGN="LEFT" ALT="[BIO]" SRC="../gx/2002/note.png">
<em>
Alan teaches CS in Andorra at high-school and university levels. His hobbies
include science photography (both digital and traditional), trekking, rock and
processor collecting.
</em>
<br CLEAR="all">
<!-- *** END bio *** -->

<!-- *** END author bio *** -->


<!-- *** BEGIN copyright *** -->
<hr>
<CENTER><SMALL><STRONG>
Copyright &copy; 2003, Alan Ward.
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR> 
Published in Issue 89 of <i>Linux Gazette</i>, April 2003
</STRONG></SMALL></CENTER>
<!-- *** END copyright *** -->
<HR>

<!--startcut ==========================================================-->
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</BODY></HTML>
<!--endcut ============================================================-->