Re: [SLUG] Converting a Hard Drive to a Virtual Machine

2010-11-19 Thread David Balnaves

Hi David,

If it was me I would copy the harddrive with dd before I do anything. 
Doesn't matter if its live (mounted), you can use fsck to clean this up 
later.  You may have some problems if the disk is really busy while you do 
this.  Be aware of weather you have taken an image of the entire drive or 
one of the partitions before running fsck.


You can manipulate the image of the drive with losetup (/dev/loop*), and the 
individual partitions with kpartx(/dev/mapper/*, kpartx -l will show).  Use 
fsck to clean the filesystems.  I would then shrink it so its more portable, 
so use e2fsresize or similar.  Shrink it to its smallest possible size.  You 
may find benefit in breaking each partition into a separate image, just dd 
the /dev/mapper/* to an appropriate image of each partition.  When your done 
use losetup/kpartx do remove any mappings to the original image.


Create your virtual machine with a disk big enough to hold the image of the 
original + whatever operational space is needed.  You will need some way to 
access the original image, so you may want to configure the image as some 
virtual drive or setup network access.  I'm pretty sure virtual box starts 
out as fully virtualized, so I think its just a matter of creating the VM 
then installing the appropriate kernel/modules for parra virtual support.


Before you begin, have a quick read of dmesg to find out what the net 
drive/interface names are.  Then dd the processed image/images to the newly 
created virtual hard disk.  If you took an image of the disk as a whole,  I 
would first setup your virtual hard disk to look like the one of the 
original drive, use fdisk to do this.  You can find out what it should 
roughly like by looking at fdisk on the original.  If you just copy the 
image of the entire drive, then you wont need to worry about fdisk step. 
When you've got the image copied across with dd, then you may need to amened 
/boot/grub or /etc/lilo.conf to relfect the virtual hard disk names.  You 
will also need to change the mappings in /etc/fstab.  For network you may 
need to change /etc/network/interfaces.


You may want to try one of the linux-*-virtual packages, this apparently has 
some parra virtualization support which may give some performance increases. 
I'm not sure if the pv stuff is there for virtualbox though :/  Either way, 
don't get your hopes up because I often find the pv stuff is broken at some 
level.


Hope this gives you a rough idea of how I'm doing it.  I've turned heeps of 
production servers into stable VM's using this method.  Feel free to shoot 
me more questions.  I'm sure I missed some steps, but I'm sure you will have 
fun figuring out what they are :)


Best Regards,
David Balnaves

-Original Message- 
From: david

Sent: Friday, November 19, 2010 3:25 PM
To: slug@slug.org.au
Subject: [SLUG] Converting a Hard Drive to a Virtual Machine

I have an Ubuntu box running which I would like to be able to clone into
a virtualbox VM.

I don't want to shut the hardware down, or play with it too much because
it's a live server.

Is it possible to use MondoRescue or some other software to clone the
server hard drive, preferably without shutting it down, and then create
a virtual machine from the resulting image?

Thanks...

David
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html 


--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] Converting a Hard Drive to a Virtual Machine

2010-11-18 Thread david
I have an Ubuntu box running which I would like to be able to clone into 
a virtualbox VM.


I don't want to shut the hardware down, or play with it too much because 
it's a live server.


Is it possible to use MondoRescue or some other software to clone the 
server hard drive, preferably without shutting it down, and then create 
a virtual machine from the resulting image?


Thanks...

David
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Converting a Hard Drive to a Virtual Machine

2010-11-18 Thread Daniel Pittman
david da...@kenpro.com.au writes:

 I have an Ubuntu box running which I would like to be able to clone into a
 virtualbox VM.  I don't want to shut the hardware down, or play with it too
 much because it's a live server.

 Is it possible to use MondoRescue or some other software to clone the server
 hard drive, preferably without shutting it down, and then create a virtual
 machine from the resulting image?

Not robustly, for cloning the raw disk, because you will end up with a really
messed up file system.  If you could stop file system access for a few hours
it would work, but that has ... probably the same issue. :)

What you *could* do is boot a LiveCD in the VM, and use rsync or something to
clone the files into the new machine.  Then, you can keep the block level
consistent and only risk file level oddities, which are much less nasty.

Daniel
-- 
✣ Daniel Pittman✉ dan...@rimspace.net☎ +61 401 155 707
   ♽ made with 100 percent post-consumer electrons
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Converting a Hard Drive to a Virtual Machine

2010-11-18 Thread Peter Hardy
On Fri, 2010-11-19 at 15:25 +1100, david wrote:
 Is it possible to use MondoRescue or some other software to clone the 
 server hard drive, preferably without shutting it down, and then create 
 a virtual machine from the resulting image?

If you don't mind free-as-in-beer, we've used VMWare's vCenter Converter
to migrate a big chunk of our Windows and Linux machines to guests -
http://www.vmware.com/products/converter/ .

Before that, my quick, dirty but effective way to do it was:
- create the new virtual guest
- boot it using your favourite liveCD, partition drives and create
filesystems
- use tar and netcat to transfer the running system across the network:
  - on guest, mount the new root filesystem and run `nc -l -p 1717 | tar
-C /mountpoint xvf -
  - on old server, run something like `tar cf - --one-file-system / | nc
address_of_guest 1717`. You'll need to tune the tar command to make sure
you include all of the server's mounted filesystems.
- edit the new /etc/fstab on the guest as appropriate
- install a bootloader in the guest, usually by editing grub config
files in /boot/grub and running grub-install.

Note that I made no attempt to keep any services running on the old
server during this process. So all but the bare minimum was shut down,
and there weren't any critical files being written to. On a real running
system, you're more than likely going to end up with some files in an
inconsistent state doing this if the old server is trying to write to
them.

-- 
Pete

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html