Automate cloning machine into vserver

July 13th, 2007

Working with Linux is just art. It is unbelievable how creative one can be using it, something I bet you will never find with this kind of flexibility somewhere*windows*cough*else.

The prerequisites: you need to realize that 99% of the things you do by hand in Linux you can actually automate.

I’ve running an old SME Server (mail server with webgui) distribution on an even older hardware. A hard disc already died in the past, wiping out everything. The next outage is around the corner, I know it. We have contracted replacement for the server, but it may still take another month or two until it will be there. In the meantime, I cannot afford loosing the mail server.

First step: what do I want?

We purchased the Primergy RX200 S3 Killer and I want the mail serer to run in the Primergy. But not as a primary service: as a vserver.

This below roughly outlines the steps I had to go through, some with explanations why:

  1. Create the new vserver which will hold your new machine
  2. Get all the files from the remote machine on the local machine, using rsync
    rsync -avz --numeric-ids --delete --exclude-from=1exclude-files.txt -e ssh root@mail:/ 10.16.0.3-mail/
    Important factor: use --numeric-ids or you get translated ID numbers of file ownership and groups which won’t work
  3. Have a second copy of the rsyncd data on the new system
    I need to make modifications, the system won’t work out of the box. Modification deals mostly with IP address changes, fstab etc, see below. Important: this one goes right into your vservers vdir. This will potentially destroy your dev/ and proc/ dirs and need to be restored.
  4. Change into vserver/etc/ and replace all occurrences of the old IP address:
    perl -p -i -e 's;OLDIP;NEWIP;g' `find -type f|xargs grep -l OLDIP |grep -v cdb`
    In my case I also needed to exclude those binary cdb files
  5. Comment out every line in /etc/fstab:
    perl -p -i -e 's;^([^#].*);# $1;g' fstab
  6. SME Server uses runlevel 7 which is not support by util-vserver at the moment.
    Workaround: vserver by default start into runlevel 3. Modify runlevel 3 in SME to be runlevel 7:
    mv rc3.d rc3.disabled
    ln -s rc.d/rc7.d rc3.d
  7. Disable some services I don’t need:
    rm rc3.d/S25keytable
    rm rc3.d/S37network
    rm rc3.d/S91atalk
    rm rc3.d/S91smb
  8. SME server also has one essential service, svscan, it starts from init and thus this service is defined in inittab:
    sv:7:respawn:/usr/bin/env - PATH=/usr/local/bin:$PATH /usr/local/bin/svscan /service &
    Because vserver doesn’t run init, the process doesn’t get executed. A quick (and probably very bad) solution is to have it started as first service in runlevel 3:
    echo -e '#!/bin/bash\nPATH=/usr/local/bin:$PATH /usr/local/bin/svscan /service &' | sed 's;\\;;g' < rc3.d/S01svscan
    chmod 755 rc3.d/S01svscan

Now, that’s it. I now was able to start the vserver and everything was up and running. Automated. Awesome.

Entry Filed under: Linux

Leave a Comment

hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

July 2007
M T W T F S S
« Jun   Aug »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Most Recent Posts