VirtualBox Grub2 Rescue ISO

Happily booting for over a year, one day the upgrade of Ubuntu came and I bit the bug. From 10.10 to 11.04 LTS. Smooth as glass for Ubuntu, but it shattered into pieces with Grub2.

The first symptom was booting into this:

error: symbol not found: 'grub_env_export'
grub rescue>

No Grub boot menu, so no selection between dual-boot, not even a default OS. This is corrected by booting a Ubuntu Live CD and running this:

# sudo mount /dev/sdXx /mnt
# sudo mount -o bind /dev /mnt/dev
# sudo mount -o bind /sys /mnt/sys
# sudo mount -o bind /proc /mnt/proc
# sudo chroot /mnt

Once at the prompt, reinstall grub (sda is the first disk. It may ask if you want to update /dev/sdaX, where X is the Ubuntu partition, I did this.):

# grub-install /dev/sda

Now update grub:

# update-grub

then Ctrl-D twice to exit, and reboot.

Now I can boot Windows or the squeaky clean Ubuntu 11.04. So forging into VirtualBox to run Ubuntu raw disk under Windows 7, there is another massive failure.

... nothing but blackness ...

There was no Grub menu. Euek.
Not to despair, I created a Grub2 ISO.

To create a bootable iso image from Ubuntu:

# grub-mkrescue --output=rescue.iso /boot/grub

This can be used in a Virtualbox by assigning it as the primary CD disk, then starting the instance. It contains all the grub files from /boot/grub, including the latest menu.

VirtualBox Grub.iso

Attach a bootable Grub2.iso to VirtualBox VM

To use this Grub ISO, copy the rescue.iso file from Ubuntu to Windows under the VirtualBox VM directory containing the Ubuntu VM, and add it as the first CD disk to the VirtualBox manager’s Storage IDE Controller definition of Ubuntu.

Now when you start the VM and see a black box with a grub> prompt, enter:

grub> configfile (hdX,Y)/boot/grub/grub.cfg

where X=the hard drive number, 0=first, 1=second…
and Y=the partition of the boot filesystem on the drive
Ex:

configfile (hd0,msdos6)/boot/grub/grub.cfg

Tip:
use ls to find the right disk
Reference: https://help.ubuntu.com/community/Grub2

If the menu does not display, you can try these things:

In file /etc/default/grub, un-comment

GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=false
GRUB_GXFMODE=640x480

Finally having things back to normal, I booting into Ubuntu from VirtualBox, installed an update from Netbeans 7.0 to 7.1. Luckly I did no more, shut down for the night and came back the next day. Wowza! Netbeans 7.1 is missing! Sure enough, if I created a file, rebooted within VirtualBox, my new file is gone…. Flashback… If I boot the same raw disk outside of VirtualBox, create a new file, the new files are retained after rebooting.

Total Recall

You can’t rely on your memory anymore.

As a wild guess I created a snapshot in VirtualBox with the VM stopped. Did my test again, and voila! Like magic my new file remains intact. Thanks to the post here:
https://forums.virtualbox.org/viewtopic.php?f=7&p=155510
for the hint.

VirtualBox

Virtualbox is a way to run another operating system within an already running operating system. Originally written by Sun Microsystems, and now owned by Oracle when they bought Sun in 2010, it is one of a dozen Virtual Machine software offerings.

One way I use it is to run Windows and Linux on the same PC at the same time with near-native speed. I call it ‘simultaneous boot’. Here is how I did it.

Start with a multi-core GB memory machine. I suggest at least 4 64-bit cores that support VM in the BIOS (i5-Intel) and 8 GB of RAM. Be sure you have a large disk, such as Seagate’s 1TB $59.00 Barracuda special. You will NEED 64-bit processor and motherboard support for more than 3GB of memory.

Partition and install Windows (XP, 7, etc…) 64-bit on a hard drive first. Windows assumes it owns everything so it is best to let it think that way.

Next partition and install Linux (Ubuntu, Fedora, etc…) 64-bit on the same drive, being careful to skip the existing windows partitions. It will install a boot loader (GRUB, etc…) that allows you to select which operating system you want to run.

http://pagead2.googlesyndication.com/pagead/show_ads.js

Test it out and boot several times between Windows and Linux.

Enable the VM extensions on the motherboard’s BIOS. This will allow one VM to have exclusive rights to whatever number of CPUs you have assigned it.

Download VirtualBox 64-bit from Oracle’s web site, as it has the VRDP, and USB extensions, but mostly because it can handle raw virtual disks. This is where the magic comes in. Normal VMs create files under the host operating system that the guest thinks are real disk drive partitions. In raw VM disks the filesystem for the guest are native to the guest, thereby making it as fast as greased lighting.

If your first drive on the machine is what you want, use ‘PhysicalDrive0’. For me, it’s the second one, so I use ‘PhysicalDrive1’. Be sure to Right Click cmd.exe in the Windows menu and select ‘Run as Administrator’ to enable access to raw disk.

Here is the disk we want to use, Partitions:
1 = Windows 7 ‘System Space’ (type 07)
2 = Windows ‘C:’ (type 07)
5 = Ubuntu ‘swap’ (type 82)
6 = Ubuntu ‘/’ filesystem (type 83
–> they show up as SATA drive 1 <–

cd C:Program FilesOracleVirtualBox
VBoxManage.exe internalcommands listpartitions -rawdisk \.PhysicalDrive1
Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
1       0x07  0   /32 /33  12  /223/19           100         2048
2       0x07  12  /223/20  1023/254/63        499899       206848
5       0x82  1023/254/63  1023/254/63          7720   1024002048
6       0x83  1023/254/63  1023/254/63        446147   1039814656



We need to register the Ubuntu partitions with VB using ‘internalcommands createrawvmdk…’. I want partitions 5 and 6 from the list above.

VBoxManage.exe internalcommands createrawvmdk -filename D:VirtualBoxubuntu.vmdk -rawdisk \.PhysicalDrive1 -partitions 5,6 



Now create a new VM in VirtualBox, and choose the existing disk you created above (D:VirtualBoxubuntu.vmdk). Also choose ‘Use Host Disk Cache’ for the SATA controller, and PXII System extensions. Allocate two (half) the CPUs you have, and half (4GB) of memory.

When you boot Ubuntu in VirtualBox it will display the Grub menu:
===> Choose the Linux partition ONLY!!! booting back into a running Windows system will corrupt the disk!!! <====

When I booted into Linux from VirtualBox the window manager did not start, leaving me looking at a black screen with the Login: prompt. To fix this I booted the machine into Linux and removed the proprietary Nvidia video driver, restarted the machine again and selected a lower screen resolution from the default video driver. Now boot back to Windows, run VirtualBox and select Linux from the GRUB menu. The GUI window manager video worked for me!

Now is a good time to install the VirtualBox Host Add-ons from the Device menu. This gets you better video, mouse, USB and file sharing.

References:
http://chaits.accosted.net/?p=54
http://www.neowin.net/forum/topic/784138-howto-boot-existing-ubuntu-partition-using-virtualbox-inside-windows/
http://www.virtualbox.org/manual/ch09.html#rawdisk


Remote Desktop Windows Protocol



To access the box remotely set the VM Display tab ‘Remote Access’ check box on, and change the port to something other than 3389, such as 5000. Leave the Authentication to NULL and time out 5000. Make sure the 3D and 2D video acceleration are turned off.

Start the VM, but leave it at the Login window. Start a Windows Remote Desktop program (RDP, not VNC) and enter the IP address of the Host PC, NOT the VM’s IP, with the trailing port number. For example:
1.2.3.4:5000

If all goes well you will see some warning about non-authentication connection, then click OK and your Linux Login GUI should display. You are in! One funny aspect of this is that using RDP on the local machine has a better display than VirtualBox, due to lowered screen resolution and it has better control over the full-screen view. I need to experiment more with the display settings.

References:
Mac OS X
Windows XP
Windows 7
Linux


Remote Desktop VNC Protocol



To set up VNC to Ubuntu running under Windows 7 Virtualbox you can use the NAT Advanced port forwarding settings and Ubuntu’s tightvncserver (sudo apt-get install tightvncserver). On Windows you can get a VNC client from TightVNC.

  1. Under Virtualbox setting for Ubuntu, select Network
  2. Change NAT adapter (the default) port forward:
  3. host port: 5902 – guest port: 5902

  4. Start Ubuntu, run:
    tightvncserver :2
  5. Test- Windows 7-> Connect to ‘localhost:2’
  6. Test- Other host -> Connect to ‘<ip address of Windows 7 PC>:2’


  7. References:
    Mac OS X
    Windows and Linux


    The speed of Windows and VM-Ubuntu are exceptionally fast, as if they are both running natively. I have half the CPU and memory allocated to the VM. The other nice advantage is if VirtualBox quits working, I can still dual-boot into both operating systems.

    You can also export your entire VM setup and data, then import it somewhere else. Oracle has several examples of that here where you can try out some of their complicated-to-set-up tools without all the muss-and-fuss. I’m not sure how it would export the raw disks.

    Hope this helps.

How I lost 90 pounds, for years

1. Decide: that you are ready to do something to become healthy, happy, and thinner. Not for anyone else but yourself. Talk it over with someone who actually has willpower and can keep their weight down. Don’t tell anyone else, this is for you, not them.

2. Move More: than you normally do. Find something that gets your heart’s rate going along with your enthusiasm. Start small and easy, don’t worry, have fun with it.
I went from bicycle riding ten minutes a day, to 10 + 10% = 11, then another 10% until I got up to an hour, then switched to walking. Same 10% progression, then switching to slow jogging. Eventually I signed up and finished several 1/2 marathons.

Finishing a 1/2 Marathon

Finishing my first 1/2 marathon in 2:43

3. Eat Less: calories and portions, but stay full. Several small meals help a lot, along with adding up calories. Just write down what and how much you eat on a daily basis for a week or two, then go to the U.S. Department of Agriculture web page and count them up. After a while you will know what is what. Veggies, fiber and fruit are your friends, but don’t forget to balance the proteins and water.

4. Measure: your progress with a scale. Every week. Write down your change and try to figure out why it works, or not. You will find the things that work, just ignore all those nasty books, people, shows, and sites. Listen to your body.

5. Enjoy: the stress relief from exercise and healthy food. Write down your stress people, places and things, and then resolve to deal with them. Stress is what you let happen to you, so you have the power to stop it. Sleep helps to loose weight and exercise make you sleep better. Happy hormones happen with hard physical work.

So, thats it!