My Brain on Code

Gentoo Guest in Virtual Box

Recently I wanted to test drive Gentoo Linux and so I decided to install it as a VirtualBox Guest on a 64 bit Windows 7 machine. I basically followed the Gentoo Docs so I won’t go into much detail about it here. However, I did download the weekly x86 minimal install iso. Mounted that as a CD in VirtualBox and went from there. I also used this to help configure the kernel. One odd thing about the Gentoo docs was that it used sda for the first hard drive whereas in my virtual machine it was seeing hda. I do not know why. So, I simply replaced any instances of sda in the docs with hda.

I got through everything in the manual fine, until I went to reboot my virtual machine. I made sure the CD wasn’t mounted. Grub booted fine, but the problem was a kernel panic:

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)

What?! A kernel panic?! My first one! Well, wait, a little before that it says:

Please append a correct "root=" boot option; here are the available partitions:  
  
[      0.964170] 0800        15728640 sda driver: sd  
  
[      0.965150]     0801              33232 sda1  
  
[      0.965985]     0802            524664 sda2  
  
[      0.966830]     0803        15170400 sda3

Hang on a minute! Available partitions start with sda?! That’s strange, on the install CD they were hda.

Well I guess that’s no big deal, I guess I can load my filesystem and edit my grub.conf and my fstab to use sda instead of hda.

So, let’s shut this down by just closing the Virtual Box window. Then, mount the minimal install CD and start the machine. Wait for the CD to boot and then you’re in the minimal install environment.

Once in the install environment we can mount our root and boot partitions:

livecd# mount /dev/hda3 /mnt/gentoo  
  
livecd# mount /dev/hda1 /mnt/gentoo/boot

Remember, the install environment recognizes your first hard drive as hda and NOT sda. Now, we can edit our fstab changing hda to sda:

livecd# sed -i s/hda/sda/g /mnt/gentoo/etc/fstab

So the relevant section of your fstab should read:

/dev/sda1             /boot       ext2         defaults       1 2  
  
/dev/sda2             none        swap         sw             0 0  
  
/dev/sda3             /           ext3         noatime        0 1

Then we can do the same with our grub.conf:

livecd#sed -i s/hda/sda/g /mnt/gentoo/boot/grub/grub.conf

grub.conf should look like the following. Remember to change your linux image to reflect your own if it’s different (mine is linux-2.6.30-gentoo-r8)

title Gentoo Linux 2.6.30-r8  
  
root (hd0,0)  
  
kernel /boot/linux-2.6.30-gentoo-r8 root=/dev/sda3  
  
  
  
title Gentoo Linux 2.6.30-r8 (rescue)  
  
root (hd0,0)  
  
kernel /boot/linux-2.6.30-gentoo-r8 root=/dev/sda3 init=/bin/bb

Unmount your filesystem, shutdown, make sure the CD isn’t mounted by Virtual Box and start the machine!

livecd# umount /mnt/gentoo/boot /mnt/gentoo  
  
livecd# shutdown -h now

Now if everything went successfully, you should be booted into your new Gentoo system.