Clone a remote server to a virtual machine

The Linode server has been running nicely lately and it is time to start setting up the content side using Drupal. To do this safely it would be nice to have a development server available locally. As the Linode itself is running on User Mode Linux, the logical thing is to setup an UML machine at home and mirror the main server setup to that.

So how do we set it up ?

    Start by getting UML running on your home pc. This is very straightforward and much easier than full virtualisation like VMWare. Take a look on Basically you download a special kernel that you can run as a user process.
    Then download the example fedora image or any other diskimage that gives you basic tools and ssh server. Start the virtual machine and configure networking.
    The networking for UML works with a tunnel that ends on the real network that the host is on. If your host pc is on then the following line would start an UML instance with host side address

./linux-2.6.24-rc7 ubda=FedoraCore5-x86-root_fs mem=128M eth0=tuntap,,,

    On the guest configure the eth0 interface as and set the nameserver / default route. On Ubuntu as host I had to do some things to get networking up:
    install the uml utilities (apt-get install uml-utilities)
    link /usr/lib/uml_net to /usr/bin/uml_net (by default it is not on the path)
    add yourself to the group uml-net (check permissions on /dev/net/tun)
    The server image will live on a second UML disk image, so we make one with dd if=/dev/zero of=Disk.img bs= count= and add it to the UML machine by specifying ubdb=Disk.img
    Then set up the guest's root password, start the sshd server and allow incoming traffic from the internet. You could for instance port forward traffic on port 22222 on your router to your UML's port 22 at
    Mount the /dev/ubdb on /mnt/serverroot
    From the remote server copy over the whole disk using tar over ssh to the UML running on your Desktop:

sudo tar -Sclzpf - / | ssh root@YOUR.HOME.IP -p 22222 "(cd /mnt/serverroot && tar -Sxvzpf -)"

    The S keeps sparse files sparse, the l keeps you off other filesystems like /proc, the p preserves permissions and the z will compress the tar file.
    It goes without saying that this has the potential to wipe out an install or filesystem on the receiving end, so you should make doubly sure that you are in fact ending up on the UML virtual machine through root@YOUR.HOME.IP -p 22222.
    When the transfer is completed, halt the guest machine and start up UML with the Disk.img as root disk ubda=Disk.img. When the UML has booted, change IP configuration, hostname, and stop any processes like automated remote backups that may interfere with your real server.

There you have it; a nice development server for you to play around in. UML has many nice features that would come in handy when testing, like COW filesystems that only write changes and allow a number of variations of one disk image to be used by different UML's.

One last tip:
When you need to access your server under a specific hostname (e.g. for virtual servers) just add temporary entries in your host's hosts file pointing to your new virtual development server.