amuck-landowner

Convert Your Desktop to a Virtual Instance with VirtualBox

drmike

100% Tier-1 Gogent
WARNING


The following involves playing with data and partitioning drives. No warranties are implied. Don't do this while drunk / frazzled / half awake. All liability is yours. Pay attention, if in doubt post here and I'll do my best to reply.


Prerequisites


0. Linux. I use Linux. This document is on how to entirely backup and convert a Debian based computer on actual hardware and then convert that into a VirtualBox image to run on a new bigger, faster, nicer Debian workstation (technically I am running LinuxMint). This will work for server and desktop versions.  THIS SHOULD ALSO WORK FOR UBUNTU and derivatives of Debian and Ubuntu.


1. Original “old” computer drive in good condition, still functioning. This drive is your OS installation, usually a single drive that boots everything and where you store your data. (Having different partitions on such doesn't matter – it is just one drive).


2. A “new” computer ideally with more resources than your old one. In my instance I went from a Core2 CPU with 4GB of RAM to a dual quad with 16GB of RAM. Effectively, 4x the CPU cores and 4x the RAM.


3. A secondary drive for your new computer. This second drive should be at least the size of your original old computer drive. (i.e. if you had a 120GB drive you might consider a 256GB, 512GB, 1TB, etc.). You are going to need your old drive x 2 in space plus always have some headroom. In my instance I went from a 256GB SSD to 1TB HDD Hybrid drive and stuck it over USB since that's what I had laying around. 


YES, you can use a USB drive.  In fact, I did this entire process with a USB 3.0 drive and had to revert to USB 2.0 due to kernel problem that is 2 years old and unresolved.


Getting started:


Take your secondary drive for your new computer and plug it into your old computer, if you have the slot on your controller to handle another drive.


Now find and run gparted.  Don't have gparted?


apt-get install gparted




Partition the NEW drive if it is new into one big partition.


Format it with EXT4.


Create a mount point for this drive:


mkdir /mnt/newdrive




Mount the drive:


Where is the partition?
 


fdisk -l




It will usually end up being /dev/sdb1


mount /dev/sdb1 /mnt/newdrive




Successful?


Assuming that your boot drive is where it should be and nothing exotic going on.


Let's image the drive to a file on the new drive:


dd if=/dev/sda of=/mnt/newdrive/myolddrive.img




This will take a while to write your entire drive to that new drive.


Successful?


Time to install VirtualBox


apt-get install virtualbox virtualbox-qt




Now we have to convert the image to VirtualBox's format so the drive file can be used.


vboxmanage convertfromraw /mnt/newdrive/myolddrive.img /mnt/newdrive/virtualbox-myolddrive.vdi –format VDI




This will take a long time as it is a slow process and you are doing reads and writes on the same drive. Took about 5 hours for my 256GB drive.  Take a nap, go to bed, do something else on your new computer (you need to have the new computer installed with Debian / Ubuntu / Linux Mint).


So at this point you should have 2 big files – the original image and the converted version suitable for VirtualBox. If you have storage on your LAN, make a copy of these files somewhere just in case. Faster to pull them from there than have to run the conversion again or lose your data, especially the VDI file.


Shutdown your old computer. Say goodbye to it and put it aside. Pull the new drive that has the backup image and the VDI image on it.


Place the new drive in your new computer as the second drive. You should already have your new computer up and installed with Debian, Ubuntu, Linux Mint, etc.


Boot into your new OS.


Mount the new drive on your new computer:
 


mkdir /mnt/newdrive

mount /dev/sdb1 /mnt/newdrive




Now start VirtualBox from your start menu. (You installed it over here? If not:


apt-get install virtualbox virtualbox-qt




Are we in VirtualBox now?


Click on New


Complete the next three screens of options as follows:


Name: OLD COMPUTER

Type: Linux

Version: Pick whatever you had on the old computer – get the bit type right most importantly


Memory Size – set this to the amount of RAM your old computer had.

Hard Drive – click on “Use an existing virtual hard drive file”

click on the file navigation icon. Go to /mnt/newdrive and click on myolddrive.vdi

click on Create



BOOM!


We are done.


Click on Start on your new VirtualBox instance and it should boot up like your old computer.


Common End Problems


Odds are there will be some annoyances. This isn't going to be 100%, more like 95%.  Most notably screen resolution will end up at 1024x768 or something low resolution. Very common problem. VirtualBox has an Addons ISO you will need to locate, download, mount the ISO and run within your new box. After I did that, all was well.


Make sure you have 2d acceleration 3d acceleration on in VirtualBox.  (3d acceleration for me has VirtualBox barking about Invalid Settings).


You need to increase the CPUs to at least match your old computer or things are going to be slow.


Improvements


Biggest improvement here would be compressing space on that image file of the original drive.  VirtualBox has a compression toggle / way to when the drive is offline compress the file.  For what it's worth, I did so, and saved about 20GB of space (20GB isn't much upside.  Perhaps zeroing the empty space would help, then compressing it.
 
Last edited by a moderator:

drmike

100% Tier-1 Gogent
I am in the process now of slimming the disk file.  Shut the container down, mounted the drive manually in system boot time recovery mode, ran a tool to wipe empty space with zeroes.. and now running VirtualBox tool to compress the file.  Slow because the drive is external and USB keeps blipping (bug, tell the kernel devs).


This slimming part could be big for folks.  I probably have 80GB of empty space to be slimmed out of the 256GB maximum.


Ideally by tomorrow I am back to normal operations.


Still very impressed with VirtualBox.  Works too well so far.
 

drmike

100% Tier-1 Gogent
Done doing the zeroing of empty space and compressing the disk file.


239G originally
229G on the original compression run (didn't zero empty space)
178G final after zeroing


25% of disk saved. Not bad :)


I need to get a new SATA drive in and plugged internally.  See how much faster this whole process is with such.   It was multiple hours for this USB 2 connected drive.


Write up on the zeroing process soon (tm).
 
 

drmike

100% Tier-1 Gogent
Done doing the zeroing of empty space and compressing the disk file.


239G originally
229G on the original compression run (didn't zero empty space)
178G final after zeroing


25% of disk saved. Not bad :)


I need to get a new SATA drive in and plugged internally.  See how much faster this whole process is with such.   It was multiple hours for this USB 2 connected drive.


Write up on the zeroing process soon (tm).
 

So, when you go zeroing and compacting the file, VirtualBox is going to freak on the reboot.   It has some UUID identifier locked to the file.  After this, something changes and VirtualBox prior profile barfs.


Trick as I did it is to take the new compressed file, give it a different name..  Then in VirtualBox GUI get to storage for the contained version, delete the mapping to the old file, push it at the new file.  


I tried using the same name and no dice, tried dropping the file mapping and putting it back, no dice.


First boot into the new file volume blows up the CPUs for a while and goes nuts while it does something.  But all good, give it 5 minutes. 


Preload stays nuts.  I actually purged preload all was well.  Put it back in and it blew up CPU... So I am letting that run its course.
 
Top
amuck-landowner