`
atomoptics
  • 浏览: 95225 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Replicating a Linux System - Yet Another Method

阅读更多
<p>用rsync复制ReiserFS文件系统,摘自<a href="http://www.linuxgazette.com/issue83/okopnik.html"><a href="http://www.linuxgazette.com/issue83/okopnik.html">http://www.linuxgazette.co...</a></a></p> <h3>Why Replicate?</h3> <p>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> <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. </p> <h3>A Little Insanity Goes A Long Way</h3> <p>Before you read any further, <strong>A WARNING:</strong> </p> <blockquote><p><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></p></blockquote> <p>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> <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> <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> <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="http://www.linuxgazette.com/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." </p> <h3>Diving Head-First Into The Dark Waters</h3> <p>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> <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> <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> <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! 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... 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> <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: </p> <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> <p>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. </p> <h3>After-Action Report</h3> <p>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> <p>Happy Linuxing to all! </p> <h3>References</h3> <ul> <li>man pages for "rsync", "ssh"/"sshd", "mke2fs"/"tune2fs", "chroot", "mkinitrd", "lilo" </li> <li>Documentation (/usr/share/doc/lilo/Manual.txt.gz) for "lilo" </li> <li>Documentation for the LNX-BBC CD </li> </ul> <p><!-- *** BEGIN copyright *** --></p>
分享到:
评论

相关推荐

    Replicating-Face-Mask-Detector

    复制面罩检测器原始作品: : 该模型我使用没有可训练参数的MobileNetV2预训练模型。然后,我将这个模型与服务器自定义层连接起来(AveragePooling 2D,Flatten,Dense,其中包含128个Relu神经元,0.5个辍学对象和...

    matlab自相关代码-Replicating-Blanchard-and-Quah:此代码复制Blanchard和Quah,并使用更多数据重

    matlab自相关代码复制空白和夸 我将输出的分解复制到永久和短暂的冲击中。 我复制了他们的定量结果,并且通过进行稳健性检查,我发现他们可能高估了由正供给扰动引起的失业率,但低估了对正供给扰动对国民生产总值...

    Self-replicating-machine-research:我对自复制机械的研究

    经过: 最佳 README.md 用另一种语言阅读本文 enespañol 除英语以外的其他语言的翻译是机器翻译的,尚不准确。 截至2021年3月21日,尚未解决任何错误,请在此处报告翻译错误。 请确保用资料来源备份您的更正并为...

    Iteam-DR-TF:我团队灾难恢复环境

    - replicating-compute.md - replicating-database.md - replicating-filestorage.md - replicating-networking.md - replicating-volume.md ./Terraform-Terraform (基础设施即代码)代码

    东北证券_0307_《Replicating+Anomalies》A股检验.pdf

    【量化金融】——《Replicating Anomalies》A股检验 本报告是对Hou、Xue和Zhang(2017)论文《Replicating Anomalies》的研究成果在中国A股市场的应用与检验。这是一份关于量化金融领域的证券研究报告,主要探讨了...

    Building Virtual Pentesting Labs for Advanced Penetration Testing(PACKT,2014)

    A penetration test, also known as pentest, is a method of assessing computer and network security by replicating an attack on a computer system or network from the outside world and internal threats....

    分布式的Key-Value存储系统Ringo.zip

    Ringo is an experimental, distributed, replicating key-value store based on consistent hashing and immutable data. Unlike many general-purpose databases, Ringo is designed for a specific use case: For...

    ISO 11452-4-2020.pdf

    - **Harness Excitation**: The method by which a vehicle’s wiring harness is intentionally exposed to electromagnetic energy to simulate real-world conditions and assess the component’s performance ...

    unix operating system

    UNIX的设计哲学重视简洁性和可移植性,为后来的许多操作系统,包括Linux和macOS,提供了灵感。 描述中提到的“deep modeling of the unix operating system for architectural cyber security analysis”(针对架构...

    Flume的高级案例

    在Master节点上创建`replicating_Channel_Selector.conf`配置文件: ```plaintext a1.sources=r1 a1.channels=c1c2 a1.sinks=k1k2 # Describe/configure the source a1.sources.r1.type=syslogtcp a1.sources.r1....

    Replicating-DeepMind:复现 DeepMind 的“Playing Atari with Deep Reinforcement Learning”的结果

    复制-DeepMind 复现 DeepMind 的“Playing Atari with Deep Reinforcement Learning”的结果。 所有信息都在我们的。 进度:系统已启动并在带有 cuda-convnet2 的 GPU 集群上运行。 它可以学习比随机播放更好,但还...

    The Executive’s How-To Guide to Automation

    It outlines the skills and technologies that must be brought to bear on replicating human-like thinking and judgment in the form of algorithms. Many believe that algorithm design is the exclusive ...

    Hibernate Reference Documentation3.1

    10.9. Replicating object between two different datastores 10.10. Flushing the Session 10.11. Transitive persistence 10.12. Using metadata 11. Transactions And Concurrency 11.1. Session and transaction...

    创建文字视图效果

    源码KTSecretTextView,KTSecretTextView可实现在Secret应用中重新创建文字视图。...更多内容可参考:http://corgitoergosum.net/2014/05/07/good-enough-isnt-replicating-the-secret-ios-app-text-view/

    Android代码-Android-Material-Examples

    Working with shared elements Commit - 8872619 Working with shared elements, explode transition, and animations ...Replicating some parts of the lollypop dialer app basing on the material design principl

    Learning Couchbase(PACKT,2015)

    Its ease of configuration and powerful features for storing different schema structures, retrieval using map reduce and inbuilt disaster recovery by replicating document across the geographical ...

Global site tag (gtag.js) - Google Analytics