Converting Your Existing Ubuntu Installation Into a VirtualBox Virtual Machine

I often find myself in the position of having to transfer all my files, applications, and other configurations that make my laptop “mine” onto a new laptop.

What’s so strange about that, you might add? Well, I go through all of this once every six months.  It’s not that I keep buying new computers — I don’t.  But I often obtain them in other ways — I trade, I help someone buy a new computer and in turn get their old one, etc.

So, tired of having to constantly re-install everything (or, at the very least, if I’ve imaged one laptop to another, having to spend a week or so having to get everything running just right), I decided to just convert my current main computer into a VM that I could just run on any computer, running any sort of OS that’s enough to run VirtualBox.

(This tutorial was created with VirtualBox in mind, but other VM’s have similar ways of converting the final file after you get to about step 3 or so.)

It seems like it should be easy, and after a little bit of work, I found out that it’s not too hard.

  1. First, you’ve got to make an image of your current installation.  (This is much easier if you have your entire Ubuntu install on one partition, i.e., no /home partitions on another hard drive or partition.  You can probably figure out how to manage that, but this tutorial will be just for one-partition installs).
    • Boot your computer with another startup disk (CD, jump drive, whatever), and then perform the following command:
      • dd if=/dev/sda1 of=image.bin
    • “/dev/sda1″ refers to the partition name that your main install is on — you can find this by doing a “sudo blkid” or “sudo fdisk -l”
    • “image.bin” refers to the output file that the image will be contained in — this can be anywhere you want, but set it to a location that’s not on the hard drive you’re trying to image.
  2. At this point, I tried to turn the image.bin file into a .vdi file so that VirtualBox could use it for a virtual machine — the problem is, at this point, your .bin file is just a partition, and not a real “virtual” hard drive.  There’s no partition table, etc. — you have to simulate these things.
    • You do this by creation an empty “sparse image” where we’ll copy the image, simulating a hard disk, and then create a partition table:
      • dd if=/dev/zero of=newhd.img bs=1G count=0 seek=100
      • In this, “newhd.img”represents the location of the file we’re creating, and “100″ represents the size of the virtual hard drive we’re creating, in gigabytes.  You may want to make this larger or smaller depending on the image you made.
    • Now, edit the image with “fdisk newhd.img“, and, following the commands presented in the fdisk interface, create a new partition table, and create a partition as large as the image you created. (The commands inside fdisk are pretty self-explanatory.)
    • Now, make the partitions available as individual devices to your system.
      • sudo kpartx -a newhd.img
    • Now, copy the original .bin file you made in step 1 onto the newly mounted partition:
      • sudo cp image.bin /dev/mapper/loop0p1
    • Now, run a disk check, and expand the copied partition to fill all of the available space, and then finally close the mounted partitions:
      • sudo e2fsck -f /dev/mapper/loop0p1
      • sudo resize2fs /dev/mapper/loop0p1
      • sudo kpartx -d newhd.img
  3. At this point, you should have a newhd.img file, which represents the entire hard drive you’ll virtually mount in your VM — the only step left is to convert it from a raw image of a hard drive into a .vdi file for use in VirtualBox:
    • VBoxManage convertfromraw -format VDI newhd.img newhd.vdi

The only steps left at this point are to create your new VM in VirtualBox, and then start it using this HD.  It more than likely won’t boot, so what you’ll need to do is start it with a livecd of your choice, and then fix the boot (I used the wonderful boot-repair utility available to Ubuntu).

 

 

Sources:

https://unix.stackexchange.com/questions/41137/convert-image-of-a-partition-into-image-of-a-disk-with-partition-table

https://superuser.com/questions/554862/how-to-convert-img-to-usable-virtualbox-format

VBoxManage convertfromraw -format VDI skyhawk4.img skyhawk4.vdi

Review: Titanicus

Titanicus
Titanicus by Dan Abnett
My rating: 4 of 5 stars

Not a bad tale of the Adeptus Mechanicus — there aren’t too many books in the 40k universe written about them, though they’re a huge part of the lore of this literary universe (standing quite a bit higher than the Astartes in the hierarchy of how things are run in the Imperium of Man).

Titanicus deals with some of the usual things you might expect to find in a book about the Mechanicus — the politics of human-augmentation in a society that seeks species purity, the way the masses see the Mechanius as distant, aloof, etc — and some of things you would rather not see explored too far, like the relationship between the God-Emperor of man (a being exalted as a living/dead god who sits on a golden throne on the Earth) and the Omnissiah (the being who the Mechanicus are allowed to worship simply because everyone has decided to look the other way and just claim that it’s obviously another avatar of the God-Emperor).

View all my reviews

Android 4.3 Radios for Sprint Galaxy Nexus

Can’t update your Sprint Galaxy Nexus to Android 4.3, but want to enjoy the new radios (which actually do improve signal strength a good bit)?

Tried to download the 4.3 update but it just won’t install on your Galaxy Nexus?  (Maybe you’ve rooted, hacked away at something — I’m not judging.)

Well, I can confirm that this link below works great to flash just the radios.

xda-developers – View Single Post – [ROM][AOSP][4.3.1][JLS36I] OFFICIAL CyanogenMod 10.2 Nightlies.

Review: Small Gods

Small Gods
Small Gods by Terry Pratchett
My rating: 3 of 5 stars

Not bad — I’d never read anything by Terry Pratchett before this. I like his style of writing, and the ideas brought up here and there in the book regarding religion are thought-provoking.

Sadly enough — because I really wanted to really like this book — I’ve never been a fan of the “all satire/funny” style of writing. Give me some Heinlein (with the witty banter of his characters) or something more modern like John Scalzi (who’s a LOT like Heinlein in how he writes) and I’m fine, but the type of writing in Small Gods (or something similar like the Hitchhiker’s Guide to the Galaxy) just bothers me. I’ve never liked it.

Maybe when you try for the joke-a-minute style of writing that sometimes it can’t help but seem forced, or the jokes kind of just start losing their funniness after a litle while (I had that problem with Hitchiker’s Guide — near the beginning, I’m literally laughing out loud while reading, and about 2/3 of the way in, I’m like okay, get on with the story).

View all my reviews

HP Pavilion Touchpad Not Working (you need to “kick” it)

So, for about two days the touchpad on my HP laptop stopped working.  Of course it was right after a kernel update in Ubuntu, so I immediately blame that.  You know… because 9/10 times it is.

So, I’m checking and checking things but can’t find anything.  It’s weird.  It’s not like it’s not working correctly, or is misconfigured — it’s like Ubuntu, which is actually pretty good at picking up on hardware changes today, can’t even see it.  So on a hunch I reboot into Windows, but it’s not working there either.

So now, instead of having to tromp through the utterly useless Ubuntu forums (full of unresolved issues where people complain about some update or the other breaking something), I can now expand my search to various HP Windows forums. Where in about five minutes, I found this gem.

Apparently, on some HP laptops (or maybe all laptop hardware is set up like this, I’d honestly never encountered it before), you have to perform what’s called a “kick”:

  1. Turn off your laptop.
  2. Unplug your AC adapter.
  3. Take out your battery. (If you can’t take out your battery externally, time to pull out a screwdriver and start taking your laptop apart.)
  4. Hold down the power button on your laptop for at least 30 seconds, preferably more (just to make sure, since time is a relative construct perceived differently by all sentient forms of matter).
  5. Put in your battery, and turn back on.  Your touchpad should now be visible to your OS, be it Ubuntu or Windows, again.

Why or how this works is anyone’s guess.  I think it resets the BIOS (it seemed to do a strange double boot the first time plugging it in after performing this procedure, which is similar to what happens on a BIOS upgrade).  I’m just glad it does.

Noos you can uoos