Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a server running Ubuntu 10.04. As I want to test some maintenance work, such as upgrading to 12.04, I thought I should create a VM copy of the server using Virtual Box. I don't have a physical access to the server, so I considered the following options: I do

  • dd'ing the entire hard disk to a raw image on my pc and then creating a VDI out of the raw dd image.
  • Installing the same ubuntu version, install update and mount the VDI locally and rsync the filesystem from the server to the mounted VDI creating a logical copy of the server.

The rsync solution is a bit more complicated, but seems to save bandwidth, and allows me to create a "copy" of the server with slightly different configuration (e.g. smaller disk).

What do you think is the best way to do so? One of the above methods? A different one?

share|improve this question
1  
Why do you want to do all this just for making a copy of the system? You can try creating image using Norton Ghost / Acronics etc and restore it to the VM. Another way is, using vmware vsphere converter to convert the physical server to a vmware esxi/server/workstation virtual machine –  Hari Dec 28 '12 at 12:15

2 Answers 2

Admittedly the dd-approach or creating an otherwise image of the server is likely to have bandwith issues in case you only have remote access to the server.

Installing Ubuntu 10.04 server to a VDI only to be able to copy an existing installation also is not really needed (but it may save some bandwith).

Let me suggest the following approach:

  • Create a Virtual Machine with an empty virtual hard disk of desired size.
  • Boot the VM with any live (Ubuntu) system from an .iso file.
  • Partition the hard drive (include boot flag and format with the same file system your old server has).
  • Mount this partition to your live environment.
  • Copy all files from the old server to the yet empty partition of your VM

    rsync -avze ssh user@host:/ /<mountpoint>
    
  • Install Grub resp. Grub2 to the MBR of the now populated VDI drive.

  • Reboot.
share|improve this answer
up vote 2 down vote accepted

Using rsync directly turned out to be more problematic than I first thought:

  1. The command needs to be run as root on the remote machine.
  2. I didn't won't to enable remote root login.
  3. The filesystem in based on LVM and it was a hassle to mount the actual root partition of the VM from inside the LVM in the VDI file.

For these reasons I ended up with a 2 step process:

  1. Copy all the files from the remote machine to the local host machine.
  2. Copy the files to the guest.

I finally went with basic tar, although I could have used rdiffdir provided by duplicity to save some bandwidth.

I started out by setting up an SSH tunnel which I could use to tunnel the tar files so I wouldn't have to write the archive to the filesystem I was copying.

local$ ssh user@remote -R 3000:localhost:3000
loacl$ nc -l 3000 > filesystem.tar.gz
remote$ sudo tar -vcz / --exclude={/dev,/proc,/sys,/tmp} | nc localhost 3000

This created a tar archive of the entire filesystem in my local host machine. The next step was to untar it on the guest:

guest$ cd /
guest$ nc -l 3000 | sudo tar -xvz
local$ nc guest_ip 3000 < filesystem.tar.gz 

In my case /etc/fstab referenced filesystems by their UUIDs, so I had to update it with the output of guest$ sudo blkid. I also had to update the networking settings in /etc/udev/rules.d/70-persistent-net.rules (interface names) and /etc/network/interfaces (ip addresses).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.