Ubuntu 18.04 Conversion of Physical Machine to Virtual

My AMD Athon – II system has been running as a LAMP server for over eight years at this point.  I think I probably started with 14.04 and most recently updated to Ubuntu 18.04 Bionic Beaver. Over time, I played with alternatives to Apache like Nginx and Lighttpd, but always seemed to end up going back to Apache.  With an eight year old system, I could sort of start to tell it was losing its ability to process the new larger images and render them quickly in netPhotoGraphics, formerly ZenPhoto 2.0, by Stephen Billard.  WordPress itself never seemed to complain, but you have to admit this is pretty simple blog. I wasn’t looking forward to replicating the settings and tweaks I had made to the system over the past eight years.  Any externally listening port had security protections and monitoring along with lots of custom shell scripts to do things like look up GeoIP locations and fix the image file timestamps to match the time shot from the EXIF data.  While I could start from scratch and eventually get back to a similar state with a new server, I wanted to preserve the older system, the content, and my tweaks; but do it in the simplest way possible.  After a little research on converting physical to virtual methods, I decided to just try and create a VirtualBox virtual disk image (VDI) using the VboxManage tool to convert the existing hard drive from the Athlon – II server.

To complete this project, I needed some new hardware.  The case was bought a couple of years ago at a good discount from a local PC parts store, Intrex. The box had been pretty banged up in shipping, but I can’t really locate anything more than a tiny ding on one of the side panels.  For the internals, I felt like I wanted to stick with AMD given eight years of good service from the current server. So, I did some research on several sites and used the PC builder parts site to get a feel for pricing.  My initial order included these parts to populate the Antec P100 case.

Items OrderedPrice
1 of: EVGA SuperNOVA 750 G2, 80+ GOLD 750W, Fully Modular, EVGA ECO Mode, 10 Year Warranty, Includes FREE Power On Self Tester Power Supply 220-G2-0750-XR
Sold by: Amazon.com Services, Inc 

Condition: New
$98.93
1 of: AMD Ryzen 5 2600X Processor with Wraith Spire Cooler – YD260XBCAFBOX
Sold by: Amazon.com Services, Inc 

Condition: New
$219.99
1 of: Asus 24x DVD-RW Serial-ATA Internal OEM Optical Drive DRW-24B1ST (Black)
Sold by: Amazon.com Services, Inc 

Condition: New
$21.99
1 of: Corsair Vengeance LPX 16GB (2x8GB) DDR4 DRAM 2400MHz C16 Desktop Memory Kit – Black (CMK16GX4M2A2400C16)
Sold by: Amazon.com Services, Inc 

Condition: New
$137.99
1 of: GIGABYTE X470 AORUS Ultra Gaming (AMD Ryzen AM4/ X470/ USB 3.1 Gen 2 Front Type C/ATX/ DDR4/ Motherboard)
Sold by: Amazon.com Services, Inc 

Condition: New
$129.99

I ended up having a 2TB Western Digital Black drive to install as the primary disk, but decided to splurge for a 1TB Western Digital Black SSD since the Gigabyte motherboard supported it and I leveraged it for the OS and the 2TB for the VM drive.

Items OrderedPrice
1 of: WD Black 1TB High-Performance NVMe PCIe Gen3 8 Gb/s M.2 2280 SSD – WDS100T2X0C
Sold by: Electronic.Depot 

Condition: New
$329.98

For a video card, I had a Nvidia GeForce GT 710B PCIE card in another system I am retiring and moved that card into this system.  I installed Ubuntu 18.04 Bionic Beaver and VirtualBox after building up the system and letting it burn in over the weekend.  The next task was the actual conversion and setting up the virtual machine to use the VDI converted from the actual hard drive from the original server.  I will save you the heartache of thinking you can have the original drive hooked up to your new system for the conversion via USB.  It is just too slow, especially when the original was a 1TB disk with a 512GB root, 1GB swap, and the rest set up as the web content partition.  I tried it, but it was going to take like 60+ hours to make the conversion.  So the original drive was connected to the new server’s SATA controller and the VBoxManage raw disk to vdi conversion executed.

$ sudo VBoxManage convertfromraw /dev/sdc LAMP.vdi –format VDI

Connected to the SATA controller and writing my LAMP.vdi to the internal 2TB conventional disk, the conversion of the 1TB disk to a VDI took about three hours.  Once I had the vdi, I opened VirtualBox and pointed to the LAMP.vdi file as the hard drive for the new virtual machine. 
(Note: You will have to change ownership to your user account or grant permissions on the completed VDI file to use it in VirtualBox.)  Then I tried to replicate the hardware settings of the original system as close as possible.  Mainly the number of processor cores and memory.  I also defined a share so I could move files more easily between the host and the LAMP guest.  I installed another Gb NIC in the system so I could bridge the VM adapter to it and let the LAMP system use the same IP address that it had before without any NAT going on.  As I expected, the initial boot up of the VM failed; but I knew the /etc/fstab was going to be an issue as I had video and music drives that were not part of the migration plan.  After getting dumped into the recovery shell, I edited the fstab file and remarked out the two mounts for those drives.  Another reboot and I was able to sign in.  I went ahead and manually entered the IP address in the NIC config and disabled and re-enabled the connection using the Ubuntu GUI.  At this point, a quick check of trying to bring up the WordPress blog and the photo gallery resulted in the having the default Apache installation page rendered.  To remedy this issue, I did a sudo systemctl reload apache2 and cleared my browser’s cache and both sites rendered correctly on the next attempt.

So far, I am very happy with the new server and plan to add some old OS VM’s in the next few weeks.  One, I will create from an old XP laptop that I have to keep around to program a couple of ham radio HT’s. Eventually, I will add another large drive to the host computer and start using it or another VM to act as a media server and file share.  I suspect that it will take a lot to start taxing the resources on the new system for sometime to come.

Behind the scenes:  The recap above concerning the actual conversion of the disk into a VDI and booting the VM for the first time is from a repeated effort after I foobared some permissions in the /var folder after having a working converted VM.  What only took about 30 minutes to get going the second time around (not counting the VDI conversion), actually took several hours the first time as I could not get past Apache rendering its default page until clearing browser caches after using systemctl to reload the Apache configuration once the IP address was set correctly.  Also, I actually did try and use a dd raw image of the original disk I had created by writing the DD file to an external USB drive connected to the original server.  It was slow and painful and the VBoxManage convertfromraw did not succeed using the DD file as the source.  What I used to the get the VM going the first try, was DD cloned drive of the original and connecting it to the SATA controller to do the convert from raw.  For the final effort as blogged, I pulled the original drive from the Athlon system, connected it directly to the new server’s SATA controller, skipped making a DD image and just converted from the raw disk.  If you have physical access to the new server, this method should be pretty foolproof. But my experience with open source and Linux tells me your experience trying this could vary greatly.

Leave a Reply

Your email address will not be published. Required fields are marked *