Gentoo as a DomU

From PrgmrWiki

Space Requirements

A base stage3 Gentoo install is around 2.5 gigabytes. Keep this in mind when installing on your VPS. It is possible to install a more minimal system with a stage1 or 2 install, but this tutorial does not cover that.

Partitioning the Disk

Boot into the CentOS rescue image so you can use fdisk to mess with your hard disk. I just made one big partition. You can add a swapfile later if you want.

fdisk /dev/xvda
d
n

etc. I think fdisk defaults to filling up the whole disk if you only have one partition.

Now format the filesystem and mount it.

mkfs.ext3 /dev/xvda1
mount -n /dev/xvda1 /mnt

Get portage and the stage3 tarball from a Gentoo mirror, and unzip them:

cd /mnt
wget http://mirrors.kernel.org/gentoo/releases/amd64/autobuilds/current-stage3/stage3-amd64-20100902.tar.bz2
wget http://mirrors.kernel.org/gentoo/snapshots/portage-latest.tar.bz2

tar xpjf stage3-amd64-*.tar.bz2
tar xjf portage-latest.tar.bz2 -C /mnt/usr/

Change the root password

Use whichever method you wish to change root the password. The simplest way is probably to chroot to the new filesystem.

Other methods include manually editing /etc/shadow with a password crypt hash. The hash can be generated with md5crypt in the grub command shell.

Edit etc/fstab

Just make sure your root partition gets mounted:

/dev/xvda1    /   ext3    noatime,barrier=0   0 1

The barrier=0 option is a possible fix for the barrier issue with recent kernels. You will also want to verify that /dev/xvda and /dev/xvda1 are listed in /dev. If they are not you will want to issue the following commands to make them for your environment.

mknod /dev/xvda b 202 0
mknod /dev/xvda1 b 202 1

Edit etc/make.conf

These are good CFLAGS for a prgmr vps:

CFLAGS="-march=native -Os"

-march=native allows gcc to optimize for your processor, and -Os produces the smallest binary possible.

Edit etc/conf.d/hostname to change your hostname

You probably want to change it to your prgmr host name.

Copy resolv.conf from rescue image

cp -L /etc/resolv.conf /mnt/etc/resolv.conf

Enable the hvc console

You need to workaround this Gentoo bug: http://bugs.gentoo.org/show_bug.cgi?id=242466 Otherwise your install will hang at "Starting local ..." when booting Gentoo.

echo "hvc0:2345:respawn:/sbin/agetty -L 9600 hvc0" >> /mnt/etc/inittab
echo  hvc0 >> /mnt/etc/securetty

You may also need to verify that CONFIG_XEN_DISABLE_SERIAL is set to N in you kernel .config

Installing the kernel

If you want to compile your own, it's very simple to configure. There are a couple of options you need to change from the default kernel.org config. Xen documents this here: http://wiki.xen.org/wiki/Mainline_Linux_Kernel_Configs#Configure_kernel_for_domU_support

Making the grub menu

mkdir /mnt/boot/grub

Edit /mnt/boot/grub/menu.lst:

title Gentoo
root (hd0,0)
kernel /boot/vmlinuz root=/dev/xvda1 console=hvc0 xencons=tty

Get out of the rescue image

cd
umount /mnt
shutdown -h now

Booting into Gentoo

Once you boot into Gentoo, networking won't be set up. Until you install a dhcp client, just type

ifconfig eth0 up

which should connect you if your /etc/resolv.conf is set up correctly.