Migrating a Linux system to virtual machine with rsync

Server consolidation ratio grows steadily. But how can we migrate our current systems to a virtual environment in an easy way?

Besides vendor specific solutions, for Linux systems there’s a simple and quick way to migrate a server to another machine (in most cases to a VM)

Create VM

  • create the virtual machine
  • boot it with a live cd
    • configure the network if necessary
sudo su -
nano /etc/network/interfaces
nano /etc/resolv.conf
/etc/init.d/networking restart
    • install necessary packages
apt-get update
apt-get install rsync
    • partition the disks
      • sda1 /
        mkfs.ext<3/4> /dev/sda1
      • sda2 swap (ram size)
        mkswap /dev/sda2
    • mount sda1 on /mnt
      mount /dev/sda1 /mnt


  • confirure rsync server with read-only share on source machine
motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock

    path = /
    comment = root
    uid = root
    gid = root
    read only = yes
    list = yes
    auth users = user
    secrets file = /etc/rsyncd.scrt


  • enable rsync in ”/etc/default/rsync”
    chmod 600 /etc/rsyncd.*
  • start rsyncd on source
  • sync it – command running on lice-cd system with sda1 mounted on /mnt
     export RSYNC_PASSWORD=&ltrsync_password>\
    rsync -vrtlpogDSH --progress --delete --exclude=/sys --exclude=/proc \
    --delete-excluded <rsync_user>@<source_ip>::root/ /mnt/;\
    mkdir /mnt/proc;mkdir /mnt/sys


get disk UIDs

blkid /dev/sda1
blkid /dev/sda2
  • modify UIDs, or replace them with /dev/sdaX in ”/mnt/etc/fstab”

Grub2 reinstall


  • Chroot into your normal system device
     sudo chroot /mnt
  • Reinstall GRUB 2 (substitute the correct device with sda, sdb, etc. Do not specify a partition number):
     grub-install --recheck /dev/sdX
  • If the system partitions are on a software RAID install GRUB 2 on all disks in the RAID. Example (software RAID using /dev/sda and /dev/sdb):
    grub-install /dev/sda
    grub-install /dev/sdb
  • Recreate the GRUB 2 menu file (grub.cfg)

Boot it

  • !!take a snapshot of your live-cd booted system including it’s memory content!!
  • reboot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s