cloning running linux machine through network, strategy and tactics

Alan Evans alanwevans at
Tue Aug 7 21:27:30 MDT 2012

I third the configuration management tool idea.  But...  Right tool
for the job.  If you are indeed just trying to turn one webserver into
two...  Well then a good 'ol clone/image is a decent way to do it.

One of my fav tricks though is to use a live cd like systemrescuecd to
boot one or both boxes and use netcat + dd to clone.

# Off the top of my head and assuming devices of the same size, please
test carefully...
nc -l -p 8000 | lzop -d - | dd of=/dev/sda
# this would start netcat listening on port 8000 piping its output to
lzop -d to decompress then pipe to dd to be written to the disk

dd if=/dev/sda | pv | lzop -1 - | nc <ip of web1> 8000
# read from /dev/sda pipe through pv which displays stats for you,
pipe into lzop -1 to compress (near line speed) then write to netcat
through TCP on remote host

But tar, cpio, rsync, all good ways to copy files from one system to another.

Or if you want to be even more smooth use something like 'partimage'
which I think is also on systemrescuecd.  But you'll have to make a
partition table on the new device (assuming there isn't one).

In addition to your excludes I would add
/etc/ssh/ssh_host_*_key{,.pub} or at least remove the files on the new
host and restart sshd.  It will regenerate new keys.  But you will
only have to do this once.  The idea is that these are now two
different hosts and should have different ssh host keys.

My 2¢, no refunds!


On Tue, Aug 7, 2012 at 11:03 PM, Tod Hansmann < at> wrote:
> On 8/7/2012 3:27 PM, Joshua Marsh wrote:
>> On Aug 7, 2012 2:49 PM, "Ryan Byrd" <ryanbyrd at> wrote:
>>> [root at CurrentlyRunningServer ~]$ rsync -ave ssh --delete /* root at NewServer
>> :/
>> --exclude={/etc/sysconfig/*,/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs}
>>> Then he'd just set up the new ip addresses on the new server, and WHAMMO!
>>> web server #2.
>>> Good idea? bad idea? something better?
>> You should check out tool like salt or chef. They were designed to do thing
>> like this, but in a cleaner, more reliable manner.
> Seconded.  I will also add that if you have a filesystem capable of
> doing snapshots, just copy the snapshot of the whole filesystem over
> instead of copying the VFS version.  I've heard of utilities that will
> monitor for file changes and keep copying over changes files, and I hear
> good things about Mondo, but I could be mistaken since I've never used it.
> The way I'd personally do it if there wasn't a snapshot method available
> is: a) image copy the whole drive over or b) use this opportunity to
> build a "build process" that's possibly even scripted.  The salt/chef
> style setup may be good here.
> -Tod Hansmann
> /*
> PLUG:, #utah on
> Unsubscribe:
> Don't fear the penguin.
> */

More information about the PLUG mailing list