After doing some quick searches using my favorite search engine, I failed to find any specific information regarding any necessary configuration for a Gentoo system to live happily as a VirtualBox Guest. As such, I have decided to write this HOWTO: so that those wanting to create their own base image may have some guidance. This is not meant to be a generic quick-start guide for installing Gentoo, but a specialized HOWTO: for installing Gentoo as a VirtualBox guest.
VirtualBox Installation and Configuration
As this HOWTO: is primarily geared towards the configuration of Gentoo within VirtualBox, I will not go into detail as to how one should install and configure VirtualBox. Instead, I will point you to VirtualBox’s official documentation here.
Guest Configuration
Create a new guest machine with the following parameters:
- ACPI: Enabled
- IO APIC: Disabled
- Memory: 256 MB
- NIC: Attached to its own Host Interface
Besides these options (which were set by default) make sure that you create a hdd with the appropriate amount of storage. I would recommend *at least* 4 GB (I chose 8 GB). The final difference is the NIC. Make a dedicated Host Interface for this guest so that you can SSH into this server while installing. This will come in handy as we will not install the guest additions until much later and copy/paste functionality comes in handy.
Boot the Gentoo cd-rom
For this HOWTO: you will need to download install-x86-minimal-2007.0-r1.iso from your favorite Gentoo mirror. Boot your guest and when you are presented with the ‘boot:’ prompt be sure to load the kernel *without* framebuffer support by entering ‘gentoo-nofb’.
Gentoo Linux Installation LiveCD http://www.gentoo.org/
Enter to boot; F1 for kernels F2 for options.
boot: gentoo-nofb
After a few moments, Gentoo will be completely booted.
Gentoo Baseline
To help convey the time necessary to complete various steps. I would like to provide you with a baseline of the virtual machine I am working on. As Gentoo compiles everything itself, any times I publish are for my baseline and your results may vary.
livecd ~ # grep bogo /proc/cpuinfo
bogomips : 4434.23
livecd ~ # hdparm -tT /dev/hda
/dev/hda:
Timing cached reads: 2432 MB in 2.00 seconds = 1216.85 MB/sec
Timing buffered disk reads: 590 MB in 3.00 seconds = 192.63 MB/sec
livecd ~ # grep MemTotal /proc/meminfo
MemTotal: 255920kB
I would also like to note the hdparm results. Apparently, VirtualBox will load portions of the disk into the Host OS’s memory and use it for better performance.
Enable SSH
At this point, it would be a good time to enable ssh. To do this, set your root password with ‘passwd root’ and enable sshd with ‘/etc/init.d/sshd start’.
livecd ~ # passwd root
New UNIX password:
Retype new UNIX password:
passwd: password updated successfully
livecd ~ # /etc/init.d/sshd restart
* Starting sshd ... [ ok ]
At this point, you should ssh into this guest to complete this HOWTO:.
Preparing the Disks
Use fdisk to create your partition layout. You need at least a swap partition (type 82) and one Linux Partition (type 83). The following scenario shows /boot, swap, and / on /dev/hda
livecd ~ # fdisk -l /dev/hda
Disk /dev/hda: 8794 MB, 8794406912 bytes
16 heads, 63 sectors/track, 17040 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 195 98248+ 83 Linux
/dev/hda2 196 1188 500472 82 Linux swap / Solaris
/dev/hda3 1189 17040 7989408 83 Linux
Use ‘mke2fs’ and ‘mke2fs -j’ to create file systems on the new partitions.
livecd ~ # mke2fs /dev/hda1
livecd ~ # mke2fs -j /dev/hda3
livecd ~ # mkswap /dev/hda2 && swapon /dev/hda2
Setting up swapspace version 1, size = 512479 kB
no label, UUID=782f1a7b-7980-4397-8a6b-837f44a5262c
Mount the newly created file systems on ‘/mnt/gentoo’. Create ‘/mnt/gentoo/boot’ and mount that as well.
livecd ~ # mount /dev/hda3 /mnt/gentoo
livecd ~ # mkdir /mnt/gentoo/boot
livecd ~ # mount /dev/hda1 /mnt/gentoo/boot
Setting Up The Stage
Make sure your date and time is set correctly using ‘date MMDDhhmmYYYY’. Use UTC time.
livecd ~ # date
Sat Dec 8 22:42:49 UTC 2007
livecd ~ # date 120822432007
Sat Dec 8 22:43:00 UTC 2007
Next, download a stage 3 package from one of the Gentoo mirrors and save it in ‘/mnt/gentoo’.
livecd ~ # cd /mnt/gentoo
livecd gentoo # wget ftp://gentoo.osuosl.org/pub/gentoo/releases/x86/current/stages/stage3-i686*.tar.bz2
Now unpack the stage 3 archive.
livecd gentoo # time tar xjpf stage3*
real 1m2.197s
user 0m21.310s
sys 0m37.490s
Now install the latest Portage snapshot. Again, choose a mirror, download, and extract.
livecd gentoo # cd /mnt/gentoo/usr
livecd usr # wget http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2
livecd usr # time tar xjf portage*
real 1m5.045s
user 0m13.790s
sys 0m33.600s
Please note that if you begin to receive warnings regarding time stamps of files, you didn’t set your clock to UTC (GMT Timezone) Time. As far as I can tell, this message is purely cosmetic, but if the time continues to be incorrect, boot times will suffer as there is a brief but accumulating pause with every occurrence.
Chrooting
Mount the ‘/proc’ file system, copy over ‘/etc/resolv.conf’ and chroot into your new Gentoo environment.
livecd usr # cd /
livecd / # mount -t proc proc /mnt/gentoo/proc
livecd / # cp -L /etc/resolv.conf /mnt/gentoo/etc/
livecd / # chroot /mnt/gentoo /bin/bash
livecd / # env-update && source /etc/profile
>>> Regenerating /etc/ld.so.cache...
Set Your Time Zone
Set your time zone information by using the correct listing in ‘/usr/share/zoneinfo’.
livecd / # cp /usr/share/zoneinfo/EST5EDT /etc/localtime
livecd / # date
Sat Dec 8 23:00:00 EST 2007
Before, you set the time to UTC (GMT Timezone) time. If you selected the correct timezone here, the correct time will be displayed when running ‘date’.
Set Your Host and Domain Name
Set your host name in /etc/conf.d/hostname and /etc/hosts. In the following example, we use ‘gentoo’ as the hostname and ‘virtualized’ as the domain name.
livecd / # cd /etc
livecd etc # echo "127.0.0.1 gentoo.is.virtualized gentoo localhost" > hosts
livecd etc # sed -i -e 's/HOSTNAME.*/HOSTNAME="gentoo"/' conf.d/hostname
livecd etc # hostname gentoo
livecd etc # hostname -f
gentoo.is.virtualized
Kernel Configuration
Install the ‘gentoo-sources’ kernel sources. Be sure to verify all of the correct kernel options are set as well. But first, we will want to update our Portage tree and emerge the latest version of Portage if it states.
livecd etc # time emerge --sync
real 1m2.431s
user 0m5.130s
sys 0m30.090s
livecd etc # time emerge portage
real 3m14.129s
user 1m9.380s
sys 1m40.180s
livecd etc # time emerge gentoo-sources
real 2m59.923s
user 0m25.670s
sys 1m1.750s
livecd etc # cd /usr/src/linux
livecd linux # make menuconfig
livecd linux # time make -j2
real 6m35.241s
user 3m40.490s
sys 2m53.430s
livecd linux # make modules_install
livecd linux # cp arch/i386/boot/bzImage /boot/kernel
Items to be aware of
1. Processor type and features
- Processor family->
- Enable Tickless System (Dynamic Ticks)
- Remove High Resolution Timer Support
- Remove Symmetric multi-processing support
- Subarchitecture Type->PC-compatible
- Remove Machine Check Exception
- Remove 64 bit Memory and IO resources
- High Memory Support (off)
2. Power Management Options
- Remove Suspend to RAM and standby
- Remove Hibernation
- Enable ACPI Support
3. Device Drivers
- Remove Macintosh device drivers
- Remove Virtualization
4. Device Drivers -> ATA/ATAPI/MFM/RLL support
- enable Generic PCI bus-master DMA support -> Intel PIIXn chipsets support
- enable PCI IDE chipset support
5. Device Drivers -> Serial ATA and Parallel ATA drivers
- enable Intel ESB, ICH, PIIX3, PIIX4 PATA/SATA support
6. Device Drivers -> Network device support
- Remove Ethernet (1000 Mbit)
- Remove Ethernet (10000 Mbit)
7. Device Drivers -> Ethernet device support -> Ethernet (10 or 100Mbit)
- Remove 3COM cards
- Remove “Tulip” family network device support
- Remove Broadcom 4400 ethernet support
- Remove nForce Ethernet support
- Remove Intel(R) PRO/100+ support
- Remove RealTek RTL-8139 C+ PCI Fast Ethernet Adapter Support
- Remove RealTek RTL-8129/8130/8139 PCI Fast Ethernet Adapter Support
- Enable AMD PCnet32 PCI support
8. Device Drivers -> Graphics support
- Remove Lowlevel video output switch controls
- Enable Support for frame buffer devices
- Enable Support for frame buffer devices -> VESA VGA graphics support
Configure the System
Now we need to configure the fstab. Edit ‘/etc/fstab’ and make it look like the following.
livecd linux # cd /etc
livecd etc # nano -w fstab
/dev/hda1 /boot ext2 noauto,noatime 1 2
/dev/hda3 / ext3 noatime 0 1
/dev/hda2 none swap sw 0 0
Next, configure your network devices by editing ‘/etc/conf.d/net’. As the network ‘hardware’ configuration is really transparent of the guest we won’t have to worry about TUN devices or other interesting configurations. An empty configuration file resulting in DHCP should suffice for most users.
Next, set the root password and make sure the timezone is set correctly in ‘/etc/conf.d/clock’.
livecd linux # passwd
New UNIX password:
Retype new UNIX password:
passwd: password updated successfully
livecd linux # nano -w /etc/conf.d/clock
TIMEZONE="EST5EDT"
Change any settings you wish in ‘/etc/rc.conf’, ‘/etc/conf.d/rc’, and ‘/etc/conf.d/keymaps’.
Installing System Tools
Here we will install and configure various system tools such as cron and syslog.
livecd conf.d # time emerge syslog-ng vixie-cron slocate dhcpcd
real 2m21.958s
user 0m41.350s
sys 1m18.040s
livecd linux # rc-update add syslog-ng default
* syslog-ng added to runlevel default
livecd linux # rc-update add vixie-cron default
* vixie-cron added to runlevel default
livecd linux # time slocate -u
real 0m10.557s
user 0m0.130s
sys 0m5.450s
Configuring Grub
Finally, we will need to install a bootloader. I prefer grub over lilo so I will show the configuration for grub. Emerge grum and modify ‘/boot/grub/grub.conf’ to make it resemble mine.
livecd conf.d # time emerge grub
real 1m19.926s
user 0m31.080s
sys 0m35.280s
livecd linux # nano -w /boot/grub/grub.conf
default 0
timeout 5
title=Gentoo
root (hd0,0)
kernel /boot/kernel root=/dev/hda3
livecd linux # grub
grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/boot/grub/stage2
/boot/grub/menu.lst"... succeeded
Done.
grub> quit
Rebooting
We finally reach the end of our Gentoo base installation. All that is left is to unmount the filesystems, unmount the cd-rom from VirtualBox, and reboot into our new clean environment.
livecd conf.d # exit
livecd / # umount /mnt/gentoo/proc /mnt/gentoo/boot /mnt/gentoo
livecd / # reboot