Categories
Life Linux Ubuntu

Converting Your Existing Ubuntu Installation Into a VirtualBox Virtual Machine

Update for 2018: some of the commands have been changed  below to reflect new  possibilities present in Ubuntu 18.04, namely the excellent losetup command.)

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

https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device

Categories
Life

Oree Carved Wooden Wireless Keyboard

For some very impractical, inexplicable reason, I want this, or would at least like to buy it as a present for someone.  I just have no idea who.Oree Wooden Wireless Keyboard

http://www.theverge.com/2013/7/5/4494966/oree-wooden-keyboard-gets-pop-up-tokyo-workshop

Categories
Life

Spidey the Cat.

image

Categories
Android

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.

Categories
Hardware Linux Science and Technology Ubuntu

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.

Categories
Hardware Linux

Fun stuff about home server management you don’t learn until you’re already knee-deep in problems

  • The hardware-based “Raid 1” hard drive mirroring (for safe data “insurance”) that’s built into most motherboards today isn’t real Raid 1 — it’s a type of “fake” Raid 1 that’s really just a fancy software wrapper: https://help.ubuntu.com/community/FakeRaidHowto
  • It’s actually really, really easy to control what hard drives are mounted (and to what directories) on Ubuntu by editing the /etc/fstab file.  Yeah, that’s about it.  No fancy programs you have to run or weird modules/packages to install.  No need to search through Google for hours thinking that “there’s got to be something more to it than that.”

 

Categories
Android Linux

Startup Script for CM9 on the Droid Incredible 2

There’s a small bug when running Cyanogenmod 9 (Android 4.0.4) on the Droid Incredible 2 — every time you reboot, you have to run the command “killall drmserver” as root, or you won’t be able to install or upgrade any applications.

Now, why this isn’t baked into the OS, I don’t know, but in lieu of having to start a terminal every time you start up your phone and run this command, you can actually create a startup script.

It’s never that easy on linux (seems to be different on every distro), but the way it seems to be done on CM9 is:

1) First, create the directory ‘/data/local/userinit.d’ with the following command:

mkdir -p /data/local/userinit.d

2) Then, create your script in this directory and make sure and make it executable (chmod 755, at least) — I had something like:

#!/system/bin/sh

killall drmserver
Categories
Gaming Linux Ubuntu

Steam for Linux, with Repository, but no GPG Key?

Steam For Linux Now Available To All Users ~ Web Upd8: Ubuntu / Linux blogGreat job on making Steam for Ubuntu there, Valve, but (boo! hiss!) on not including the damn key with the installation so people can actually update it when they install it.

This blog mentions how to fix it, with the command below:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F24AEA9FB05498B7

 

Categories
Gaming Linux Ubuntu

Cron Tips

Been wondering this for a while — how do you make a cron script that will only run once, when your server boots?

Just append “@reboot” before the command, instead of the usual time information (at least on Ubuntu Server 12.04):

  • @reboot /path/to/execuable1

CronHowto – Community Ubuntu Documentation.

Categories
Hardware Science and Technology

Single-user mode, MacOSX 10.8

image

It’s how one tests for issues without the rest of the OS getting in the way. Just boot your Mac while holding Command+S.