Thursday, February 25, 2010

Install Ubuntu from Alternate CD image; booting from USB flash drive

I recently tried a couple of ubuntu versions, installing them on a partition to play a few hours. In the process I re-discovered unetbootin, a wonderful tool for this: I burned the CD ISO images in a USB flash drive, instead of burning CDs (even if you use rewritable, it is slower than a USB key). UNetbootin let's you make a bootable pendrive from any ISO image; you can even download your favorite distro CD from there.

The main comment of this post is, however, not just the unetbootin process, but two tips that solved issues with these images.

First, the simpler one: You have to mark the partition in the USB drive as bootable, or you will not be able to boot... To do this, run fdisk /dev/sdb (or whichever your drive's device is), and add its boot flag.

The second on is subtler. With the Ubuntu 9.10 Desktop CD everything worked perfectly; I was able to boot. But later I tried the Alternate CD, which after booting it could not find the contents of the "CD" it was installing from. Somehow it missed the point it had boot from USB; so there would not be any contents on CD-ROM to read (in fact, that machine does not even have a CD drive). What I had to do was to add a flag to the kernel boot options: When UNetbootin starts, before pressing Enter on the "Default" option, press Tab to edit it. Edit the kernel line, to make it look like this one:
/ubnkern initrd=/ubninit vga=normal cdrom-detect/try-usb=true -- quiet

(Everything should be in a single line). Your line might not be identical; but the important part is to add "cdrom-detect/try-usb=true" before the "--". With this option the installer found the contents and was able to continue the rest of the install process.

Wednesday, February 24, 2010

Resizing a VirtualBox bootable WinXP drive

I have a couple of Windows images running in VirtualBox machines. (Yes I only boot linux, but still have a couple of windows images confined to their VMs). They ran out of diskspace; I created too small disks. I had attempted to solve this by adding increasingly larger secondary disks; but Windows does not like small "C:" partitions; sooner or later problems arise.

I found tips from several places about how to do this so I am going to compile my experience here. Since VDI images cannot be just resized (disk geometry can be altered), one needs to move the data to another VDI disk. The procedure is then: 1) Create a new (bigger) disk, 2) Clone the old disk into the new disk, 3) replace the disk in the virtual machine.

So far, that's more or less simple if the disk is not the primary, bootable disk. But I tried cloning with Acronis TrueImage, GParted and a couple of other tools, and they all resulted in an unbootable disk with "Disk reader error, press Ctrl+Alt+Del" message when trying to boot. I tried using the windows recovery console rebuild the MBR (fixmbr.exe) or the boot sector (fixboot.exe) but none of them worked. The extra tip was touching a parameter in the boot sector of the disk... find the details below.

Before you start, you might want to backup your entire VDI image; just in case (none of these steps will modify it... but there is always the case of selecting the wrong option).

All the steps then look like:
  1. Create the disk

    1. Shut down the virtual Windows machine
    2. From VirtualBox disk manager, create a new disk (bigger!), and attach it as secondary to that machine.

  2. Copy data. Use some cloning tool to copy the entire disk from the old disk to the new one. In my case, I found the simpler way was:

    1. Download a GParted LiveCD,
    2. Add it to the list of VirtualBox ISO images,
    3. Mount it on the virtual machine, and make sure the CDROM is first in boot order sequence.
    4. Boot GParted. Select the old disk/partition, click "Copy". Select the new disk, create on "Create Partition Table" (type "MSDOS"), then click "Paste" to bring the new data. In the resizing dialog, you can extend the partition to the end of the disk. Click "Apply" and it will take a while until the partition is copied. Then go to "Manage Flags" and enable the "Boot" flag.
    5. Shutdown the virtual machine; remove the ISO cd image.

  3. Enable the new disk (You might want to try seeing if the new disk just boots -- If you do not get a "Disk Read Error" message, skip next steps and you are done!).

    1. Start the virtual machine (still with the old disk as primary). You should be able to view the bigger, secondary disk, with the same contents as the old one.
    2. From within Windows, download Roadkil's Boot Builder. Then a) Read the boot sector of the NEW disk, b) change the "Heads" parameters to 255, c) write the sector back to the NEW disk. (Make sure not to screw up disk names! your old disk is still the backup.). See screenshot.
    3. Shutdown Windows. From VirtualBox, remove the old (smaller) disk, and leave only the new (larger) disk. Start up the VM, it will nicely boot up. (Well, Windows will boot up...)

I have no idea why that Heads parameter needs to be changed; but changing it from 128 to the magic 255 value worked for me (enlarging a 3Gb disk to 10Gb one) and others as well.

Happy cloning!