255 lines
15 KiB
HTML
255 lines
15 KiB
HTML
<!--startcut ==============================================-->
|
|
<!-- *** BEGIN HTML header *** -->
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML><HEAD>
|
|
<title>Replicating a Linux System - Yet Another Method LG #83</title>
|
|
</HEAD>
|
|
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
|
|
ALINK="#FF0000">
|
|
<!-- *** END HTML header *** -->
|
|
|
|
<!-- *** BEGIN navbar *** -->
|
|
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="klimkiewicz.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue83/okopnik.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="padala.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
|
|
<!-- *** 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">Replicating a Linux System - Yet Another Method</FONT></STRONG></BIG></BIG><BR>
|
|
<STRONG>By <A HREF="../authors/okopnik.html">Ben Okopnik</A></STRONG></BIG>
|
|
|
|
</TD></TR>
|
|
</TABLE>
|
|
<P>
|
|
|
|
<!-- END header -->
|
|
|
|
|
|
|
|
|
|
<h3>
|
|
Why Replicate?</h3>
|
|
Replication - sometimes referred to as cloning - is the process of copying
|
|
an installed filesystem from one machine to another (usually to a new machine)
|
|
instead of going though the entire installation process again; a good thing
|
|
indeed. Given the speed at which computers improve, by the time you have
|
|
your system tweaked and tuned exactly the way you like it - usually at
|
|
the cost of dozens if not hundreds of hours of playing with it - the hardware
|
|
is outdated. Replication allows you to conserve all that effort by simply
|
|
transferring the entire configured system to new hardware.
|
|
<p>What makes replication a uniquely wonderful experience under Linux is
|
|
the large number of options for doing so, which implies flexibility and
|
|
the ability to adapt the method to your exact situation - just as I have
|
|
here. Other OSes are generally confined to one rather restrictive method
|
|
(in effect, "dd"ing the hard drive contents to an identical drive.) With
|
|
Linux, you can pick whatever method suits your needs. However, there is
|
|
a cost - the same one that applies to just about anything else in Linux.
|
|
As the XFree folks say, "don't set policy - provide a mechanism." What
|
|
you have to do, rather than blindly running a provided menu-driven application
|
|
(what
|
|
<b>is</b> that thing doing behind the scenes? Can you troubleshoot
|
|
the process if it goes wrong?) is a) understand the process, and b) choose
|
|
the tools that will make it happen. In the world of Unix, where "small
|
|
sharp tools" is a major tenet of the underlying philosophy, this is the
|
|
default way to work.
|
|
<h3>
|
|
A Little Insanity Goes A Long Way</h3>
|
|
Before you read any further, <STRONG>A WARNING:</STRONG>
|
|
|
|
<BLOCKQUOTE><EM>
|
|
This is <b>not</b>
|
|
the standard way to replicate a Linux system. What is described below was
|
|
an experiment just to see if it could
|
|
be done. Yes, you could probably repeat my results - you might even find
|
|
it as convenient as I did to do it this way - but if you
|
|
mess it up and end up causing clogged toilets in New Guinea, earthquakes
|
|
in Abu Dhabi, and war between Earth and the
|
|
intelligent cephalopods of Beta Cygni 4, don't blame me!
|
|
</EM></BLOCKQUOTE>
|
|
|
|
It seems that for a number of people, myself most emphatically included,
|
|
the best way to learn how something works is to take it apart and then
|
|
put it back together (usually turning a five-dollar toy into a three-day-long
|
|
project and seven gallons of sweat, but - oh well.) So... about a week
|
|
ago, I was given a computer, somebody's "outdated" box. (Wind*ws is great.
|
|
No, really. There's no way I'd run it, but I love the effect it has: it
|
|
makes people think that a P3-400/64MB machine is "outdated". There are
|
|
always going to be a lot of uninformed folks out there, so I can see a
|
|
lifetime of free computers ahead of me! Somebody else here wants to give
|
|
me a really nice 486 Gateway laptop, too...)
|
|
<p>Of course, as far as I'm concerned, new computer = Linux installation.
|
|
That's like ham and eggs, bread and butter, <i>agua caliente para chocolate</i>
|
|
(yes, I'm getting a little hungry here, but you get the idea.) It's just
|
|
natural. However, my install CDs are old enough that I have to wipe off
|
|
the Tyrannosaurus footprints - I mean, they're almost a year old! - so
|
|
I wasn't going to do that. Hmm. My Net access these days consists of walking
|
|
over to the marina office (I live on a sailboat) and plugging into a phone
|
|
jack - dragging over a desktop PC and leaving it plugged in for a week
|
|
wasn't going to be looked on favorably. Scrap <i>that</i> scenario. I could
|
|
order the latest CD set from <a href="http://www.cheapbytes.com">CheapBytes.com</a>,
|
|
but I didn't feel like waiting for several days: I had a time slot <i>now.</i>
|
|
This was going to take a little planning.
|
|
<p>My laptop has a well-polished install of Debian on it - I've had quite
|
|
a while to get it all set up exactly the way I want it. I could just "dd"
|
|
everything over, and - oh. The laptop drive is 12GB; the drive I dug up
|
|
was an old 6GB that had a 2GB partition with some historical data on it
|
|
and a
|
|
<i>really</i> ancient Debian install. I didn't want to just scrap
|
|
the data, didn't feel like messing around with my backups and tape drives,
|
|
and 12 won't fit into 6 anyway. Let's see. A fair chunk of that 12 is my
|
|
music collection; heck, I'll just leave it on the 'top. Next, there's my
|
|
"Data Dump": an FTP archive backup, a mirror of the Comprehensive Perl
|
|
Archive Network (CPAN)... yeah, all that could stay there too. A little
|
|
decision-making, and my entire kit of programs turned out to fit into about
|
|
2GB - just what the doctor ordered! All except one thing, that is - how
|
|
would I get it from <b>here</b> to <b>there</b>, keeping all the permissions,
|
|
etc. correct? And what other problems would I run into?
|
|
<p>There are a number of standard methods for installing Linux: CD or other
|
|
media, an archive or a loop-mounted image via a network, raw copying between
|
|
same-sized drives with "dd", and - closest to what I wanted - a filesystem
|
|
dump between identically laid-out systems (see Jim Dennis' tip in LG#68,
|
|
"Bulk File Transfers from Wind*ws to ???".) However, I wasn't doing any
|
|
of those, not even the last; instead, I was going to transfer bits and
|
|
pieces to a different FS layout. Would it work? In a move strongly fueled
|
|
by way too much machismo, entirely too little sense, and Mike Orr's column
|
|
in this very magazine (see his "The Foolish Things We Do With Our Computers"
|
|
[look in the <A HREF="../lg_index.html">Index of All Issues</A> to find it]
|
|
-- perhaps this whole article belongs in that category!), I said to myself:
|
|
"Self... let's do it anyway. We can
|
|
<i>always</i> restart from scratch."
|
|
<h3>
|
|
Diving Head-First Into The Dark Waters</h3>
|
|
One of my main tools for this project was the Bootable Business Card from
|
|
the <a href="http://www.lnx-bbc.org">LNX-BBC project</a>. I booted the
|
|
new machine with it and used "mke2fs" with the "-j" option (this creates
|
|
a journal on the new partition, something I needed since I use ext3 on
|
|
my laptop) to reinitialize "/dev/hda2" - this is where Linux would live.
|
|
Next, I mounted "/dev/hda2" on "/mnt/0", activated the network card by
|
|
entering "insmod dmfe" (the new desktop came with an on-board Davicom),
|
|
assigned it an IP address ("ifconfig eth0 192.168.0.5"), and I could now
|
|
"see" the laptop - which was ready and waiting at 192.168.0.3, courtesy
|
|
of a NetGear PCMCIA card and a crossover cable.
|
|
<p>I don't run any network services on my laptop by default - one of the
|
|
first things I do in almost any install is disable "inetd" - but here,
|
|
I wanted to use "sshd" for a specific reason. Therefore, Baldur (the laptop)
|
|
got a command of "su -c '/etc/init.d/ssh start'", and Ymir (the desktop)
|
|
got "rsync -e ssh -avz --exclude-from file.lst root@192.168.0.3:/ /". The
|
|
exclude list, a file called "file.lst" (files and directories that "rsync"
|
|
should ignore) was a fairly short one: "/proc/", not being a "real" filesystem,
|
|
didn't need to be copied (in fact, doing so would be a bad idea); however,
|
|
I did make an empty "/proc" directory on the new partition. I skipped "/lost+found/"
|
|
as well - one was automatically created on Ymir when I ran "mke2fs" (besides,
|
|
it's not just a simple directory; see "mklost+found" for more info). I
|
|
also most carefully did not copy the journal-related files ("/.journal"
|
|
and "/.memdump") from Baldur; they would have no relation to the disk state
|
|
on Ymir, and could probably screw things up pretty badly. Last, I added
|
|
the directories that I didn't want to copy to the new system.
|
|
<p>Once done with the copying - which took a while, even at 100Mb/s - I
|
|
did a "chroot /mnt/0 /bin/bash" on Ymir, which made this new filesystem
|
|
the root ("/") and ran a shell in it. Success! I thought of this as the
|
|
"three-quarter-way point"; most of the moving was done, and the only remaining
|
|
critical thing was making the system bootable. Of course, I had to do a
|
|
bit of system-specific setup: modifying "/etc/fstab" to reflect the correct
|
|
partitions, fixing "/etc/modules" to load the right ones, adjusting "/etc/lilo.conf"
|
|
and running "/sbin/lilo" to boot the right image... oh, whoops. Baldur
|
|
boots via "initrd"; the "initrd" image includes information about which
|
|
partition gets "pivoted to" as root, and that was different between Baldur
|
|
and Ymir. OK, then - I jumped over to Baldur and ran "mkinitrd" with the
|
|
"-r /dev/hda2" option, which built me a new "initrd" image with the correct
|
|
partition as the root. I "rsync"ed it to Ymir, and life was lookin' good.
|
|
<p>As a last step before rebooting, I ran "/sbin/lilo -v3", and... aaarrgh.
|
|
I got a message about the boot sector being made by a previous version
|
|
of LILO (remember that ancient Debian distro that had been on there?),
|
|
and the new one simply refused to rewrite it! <sigh> Clearly, this would
|
|
not normally be an issue, but this time, it was a pain. Ah - LILO's manual
|
|
mentions the "QuickInst" script that is supposed to be used for initial
|
|
installs only - perfect. (See LILO's "doc" directory.) "QuickInst" walked
|
|
me through setting up some basics, and... <laugh> it didn't work - the
|
|
"lilo.conf" that it wrote was too simple, and didn't match my setup. That
|
|
was OK, because it <i>did</i> rewrite the boot sector; I simply copied
|
|
the correct version of "lilo.conf" back into "/etc", re-ran "lilo -v3",
|
|
and All Was Cool.
|
|
<p>I then rebooted, swapped the BIOS settings back so that Ymir would boot
|
|
from the HD rather than the CDROM, watched a few errors fly by... and was
|
|
greeted with a login prompt. Hurrah! That was 90% of the way there; the
|
|
rest was just more tweaking. For the record, the things that produced the
|
|
errors were: "hdparm" disk tuning parameters had to be changed, and one
|
|
old module was still loading from "/etc/default/hotplug.usb". Other than
|
|
that, all that remained was much like setting up a new system, although
|
|
a lot less work. Let's see:
|
|
<ul>
|
|
<li>
|
|
Reconfigure X for different video card/monitor</li>
|
|
|
|
<li>
|
|
Load a different module for sound hardware</li>
|
|
|
|
<li>
|
|
Change the hostname in several "/etc" files ("grep -rl Baldur /etc")</li>
|
|
|
|
<li>
|
|
Run "ssh-keygen" for new SSH-2 "fingerprints" for Ymir</li>
|
|
|
|
<li>
|
|
Shut down "sshd" on Baldur</li>
|
|
</ul>
|
|
That was all of it. It's been more than a month now and I haven't had any
|
|
trouble at all. Sure, I've left a lot of stuff out of this description
|
|
in order to make myself look smarter - I probably rebooted, switching between
|
|
the LNX-BBC CD and the HD, about a dozen times because I'd forgotten "just
|
|
one little thing" - but the above was the critical path, the stuff that
|
|
had to happen to make it work. About two hours of work, and I had an up-to-date
|
|
Linux system that's all tuned to my preferences - setting it up from scratch
|
|
and getting it all adjusted would have taken much, much longer.
|
|
<h3>
|
|
After-Action Report</h3>
|
|
As a result of doing this, I learned a number of important things: a little
|
|
more knowledge about the "initrd" boot process, a little more experience
|
|
at fixing LILO problems, what exactly <b>is</b> affected when you move
|
|
from one system to another - and most important of all, how to do this
|
|
process and its associated pitfalls. As well, it's another tool in my "knowledge
|
|
toolbox" - and that's always a good thing. In fact, the laptop on which
|
|
I'm typing this - a brand-new Dell Inspiron - had Wind*ws XP on it just
|
|
a short while ago... :) It is now a very smoothly operating Linux 'top.
|
|
The actual time that I spent on the cloning, excluding the transfer time
|
|
(12GB takes a <b>while</b> to move across), was about 10-15 minutes; experience
|
|
is a wonderful thing.
|
|
|
|
<p>Happy Linuxing to all!
|
|
|
|
<H3>References</H3>
|
|
<UL>
|
|
<LI>man pages for "rsync", "ssh"/"sshd", "mke2fs"/"tune2fs", "chroot", "mkinitrd", "lilo"
|
|
<LI>Documentation (/usr/share/doc/lilo/Manual.txt.gz) for "lilo"
|
|
<LI>Documentation for the LNX-BBC CD
|
|
</UL>
|
|
|
|
<!-- *** BEGIN copyright *** -->
|
|
<hr>
|
|
<CENTER><SMALL><STRONG>
|
|
|
|
Copyright © 2002, Ben Okopnik.
|
|
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
|
|
Published in Issue 83 of <i>Linux Gazette</i>, October 2002</H5>
|
|
</STRONG></SMALL></CENTER>
|
|
<!-- *** END copyright *** -->
|
|
<HR>
|
|
|
|
<!--startcut ==========================================================-->
|
|
<CENTER>
|
|
<!-- *** BEGIN navbar *** -->
|
|
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="klimkiewicz.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue83/okopnik.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="padala.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
|
|
<!-- *** END navbar *** -->
|
|
</CENTER>
|
|
</BODY></HTML>
|
|
<!--endcut ============================================================-->
|