I present for your amusement, a series of scripts which will, if I haven't forgotten something, completely install gentoo with a minimum of human involvement. while these components are atrocious from a usability standpoint, the addition of a user interface with appropriate checking on top of these scripts could take the sharp knives and missing fingers gentoo install into something you can engage in and still count to 10 afterwards. Still need to do something about Xorg however.
at the very least, it would be a really cool hack to the install CD to detect a usb flash with these programs and do the install based on them with a single command.
component summary:
config: configuration data for the entire operation (in theory) you should be able to control most important installation things you need from here.
phase1.sh: everything that happens outside of the chroot environment as defined by the installation manual. ID network setup, ssh, disk partition name, disk formatting setting up various configuration files, stage install, etc.
phase2.sh: everything that happens inside the chroot environment as defined by the installation manual. portage update, installing base packages, Grub
phase3.sh: (user-defined) whatever you want to script after phase 3 that takes place inside of the chroot environment.
go_chroot.sh: handy little script which places you into the chroot environment and leaves you in a shell so you can do your dastardly deeds.
execution environment:
I run all these programs out of a usb flash big enough to hold these programs plus one stage 3 install tarball. the flash is mounted on /mnt/flash. the content should be located in the flash relative directory "gentoo" and the stage 3 tarball is in "gentoo/stages" so that the final path is "/mnt/flash/gentoo/..."
invoke as /mnt/flash/gentoo/phase1.sh and stand back. **It does not wait for you to give permission to do anything.** It assumes that if you haven't, you will and without reservation.
this tool has lots of really sharp edges that has cut me on more than one occasion. But no problem, I reboot, fix the problem, and start over.
if folks feel adventurous and want to experiment with this, please I would truly welcome feedback and bug fixes. hope this is useful to others.
---eric (I really should get some sleep one of these days)
-- http://www.wired.com/wired/archive/13.03/view.html?pg=5
The result of the duopoly that currently defines "competition" is that prices and service suck. We're the world's leader in Internet technology - except that we're not.
# config variables HOST_NAME=rufus DOMAIN_NAME=harvee.org DRIVE=/dev/hda
# CPUTYPE="i686"
CPUTYPE="pentium3"
MKFS2="mke2fs"
MKFS3="mke2fs -j"
MKFSR="mkreiserfs -q"
MKSWP="mkswap"
#PART_SWAP=2
# format of the filesystem list is:
# partition number:filesystem command
# create the entries in the order in which they will be created and
# mounted.
PART_ORDER=(1 2 3)
PART_LIST[1]="3:/mnt/gentoo:${MKFSR}"
PART_LIST[2]="1:/mnt/gentoo/boot:${MKFS3}"
PART_LIST[3]="2::${MKSWP}"
# proxy configurations to say to wear and tear gentoo servers
# replicated below in constructing make.conf
SYNC="rsync://192.168.25.11/gentoo-portage"
http_proxy=http://192.168.25.11:8080
RESUMECOMMAND=" /usr/bin/wget -t 5 --passive-ftp \${URI} -O
\${DISTDIR}/\${FILE}"
# if ethernet module is not detected automatically, list module here
ETHERMODULE=""
# DHCP usually requires nothing but if module is manually loaded.
# activate command here
DHCPCD_CMD="dhcp"
#otherwise enter static IP information. Note, DHCP takes priority
#over static information
# static IP address
IP_ADDR=192.168.25.11
BROADCAST=192.168.25.0
NETMASK=255.255.255.0
GATEWAY=192.168.25.254
NAMESERVER=192.168.25.1
# partitions
# describe your partitions here in sfdisk format
PARTITIONS=`mktemp `|| exit 1
cat > $PARTITIONS <<EOF
0,200,L
,1000,S
,,L
;
EOF
# your default make.conf
MAKE_CONF=`mktemp `|| exit 1
cat > $MAKE_CONF <<EOF
MAKEOPTS="-j3"
AUTOCLEAN="yes"
PORTDIR_OVERLAY=/usr/local/portage
USE="mmx sse alsa oss aim emacs fastcgi gphoto2 imap maildir mozilla pcmcia
python usb gdbm pam png berkdb apache2 perl qt readline gif gtk gtk2 ldap mbox
mcal ncurses ssl wxwindows zlib"
SYNC="rsync://xeno/gentoo-portage"
http_proxy=http://xeno:8080
RESUMECOMMAND=" /usr/bin/wget -t 5 --passive-ftp \${URI} -O \${DISTDIR}/\${FILE
}"
EOF
#!/bin/bash
#phase one of gentoo install
. /mnt/flash/gentoo/config
# changes passwd
#passwd
### place network configuration set up here
# if ethernet module is not detected automatically, load it here
# modprobe <your Ethernet module here>
if [ -n "$ETHERMODULE" ] ; then
modprobe $ETHERMODULE
fi
if [ -n "$DHCPCD_CMD" ] ; then
eval $DHCPCD_CMD
else
ifconfig eth0 ${IP_ADDR} broadcast ${BROADCAST} netmask ${NETMASK} up
route add default gw ${GATEWAY}
cat > /etc/resolv.conf <<EOF
nameserver ${NAMESERVER}
EOF
fi
# start sshd
/etc/init.d/sshd start
# get portage if no copy locally. This won't get the latest copy
# unless there is none
if [ ! -f /mnt/flash/gentoo/stages/portage ]; then
# ask the user for a portage mirror site
eval X`mirrorselect -i -o`
# grab the first selection
PORTAGE_SITE=`echo ${XGENTOO_MIRRORS}| cut -f1 -d" "`
PORTAGE_PATH=${PORTAGE_SITE}snapshots/
wget --proxy=off -O /tmp/index.html $PORTAGE_PATH
PORTAGE=`cat /tmp/index.html | egrep -v "md5sum|gpgsig"| grep portage| \
tail -n 1| cut -d" " -f 8| cut -f 2 -d">"| cut -f 1 -d"<"`
wget --proxy=off ${PORTAGE_PATH}/${PORTAGE} -O
/mnt/flash/gentoo/stages/portage
fi
# partition your disk.
# *CAUTION* this can really screw up your system.
# this creates four partitions. First field is the start, second field
# is the size in MB, and third field is the Linux or swap.
# it should be possible to add extended partitions but I haven't needed
# them yet
/sbin/sfdisk -uM ${DRIVE} < $PARTITIONS
# create swap space and file systems on the partitions created
# previously
for x in ${PART_ORDER[*]}
do
i=${PART_LIST[$x]}
echo "---| $i"
PART=`echo $i | cut -d":" -f1`
MNTPT=`echo $i | cut -d":" -f2`
MKFS=`echo $i | cut -d":" -f3`
eval $MKFS ${DRIVE}${PART}
#echo "|| $MKFS ${DRIVE}${PART}"
if [ "${MKFS}" == "${MKSWP}" ]; then
swapon ${DRIVE}${PART}
else
# mount up partitions
mkdir -p $MNTPT
mount ${DRIVE}${PART} $MNTPT
fi
done
# install the stage you want. It's probably a good idea to download and
# store the appropriate stage image on the USB flash. Saves trying to
# figure out which mirror to get from and its just convenient.
cd /mnt/gentoo
tar -xjpf /mnt/flash/gentoo/stages/stage?-${CPUTYPE}*.tar.bz2 -C /mnt/gentoo
tar -xjf /mnt/flash/gentoo/stages/portage -C /mnt/gentoo/usr
# for testing components going into different phases
cat $MAKE_CONF >> /mnt/gentoo/etc/make.conf
# and add the gentoo mirrors
mirrorselect -a -s4 -o |grep 'GENTOO_MIRRORS=' >> /mnt/gentoo/etc/make.conf
# set up DNS for the new system
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
# set up domain name
echo ${HOST_NAME} > /mnt/gentoo/etc/hostname
echo ${DOMAIN_NAME} > /mnt/gentoo/etc/dnsdomainname
rc-update add domainname default
# and set up the /proc environment.
mount -t proc none /mnt/gentoo/proc
# copy all of the phases to the new drive in preparation
# for the rest of the installation process
cp /mnt/flash/gentoo/phase*.sh /mnt/gentoo/
if [[ -f /kernel_config ]]; then
cp /mnt/flash/gentoo/kernel_config /mnt/gentoo/
fi
# set up the network interface
if [ -z "${DHCPCD_CMD}" ] ; then
grep -v "^iface_eth0" /mnt/gentoo/etc/conf.d/net > /tmp/net
echo iface_eth0=\"${IP_ADDR} broadcast ${BROADCAST} netmask ${NETMASK}\">>
/tmp/net
echo gateway=\"eth0/${GATEWAY}\" >> /tmp/net
cp /tmp/net /mnt/gentoo/etc/conf.d/net
else
echo "iface_eth0=\"$DHCPCD_CMD\"" >> /mnt/gentoo/etc/conf.d/net
fi
# directories to build
mkdir /mnt/gentoo/usr/local/portage
# launch phase 2
chroot /mnt/gentoo /bin/bash -c "bash phase2.sh"
#!/bin/bash
#this is the chroot side of the installation process
#set up the new environment
env-update
source /etc/profile
# update the portage tree
emerge --sync
#get the kernel
emerge vanilla-sources
# at this point, one could copy in a predefined configuration
# file or one could just manually configure.
cd /usr/src/linux
#let's manually configure
if [[ -f /kernel_config ]]; then
cp /kernel_config /usr/src/linux/.config
else
make menuconfig
fi
# then build the kernel
make && make modules_install
# move it
cd /usr/src
KERNEL_VERSION=`ls -d linux-*`
cd /usr/src/${KERNEL_VERSION}/
cp arch/i386/boot/bzImage /boot/${KERNEL_VERSION}
cp System.map /boot/System.map-${KERNEL_VERSION}
cp .config /boot/config-${KERNEL_VERSION}
emerge syslog-ng
rc-update add syslog-ng default
emerge vixie-cron
rc-update add vixie-cron default
emerge slocate
emerge reiserfsprogs
emerge grub
emerge gentoolkit
# setup grub.conf
cat > /boot/grub/grub.conf <<EOF
# Which listing to boot as default. 0 is the first, 1 the second etc.
default 0
# How many seconds to wait before the default listing is booted.
timeout 30
# Nice, fat splash-image to spice things up :)
# Comment out if you don't have a graphics card installed
#splashimage=(hd0,0)/grub/splash.xpm.gz
title=Gentoo ${KERNEL_VERSION}
# Partition where the kernel image (or operating system) is located
root (hd0,0)
kernel /${KERNEL_VERSION} root=/dev/sda3
EOF
# more start up processes
rc-update add net.eth0 default
rc-update add sshd default
if [ -f /phase3 ] ; then
bash /phase3
if
#!/bin/bash
TARGET=/dev/sda
if [ ! -f /mnt/gentoo/etc/make.conf ]; then
mount ${TARGET}3 /mnt/gentoo
mount ${TARGET}1 /mnt/gentoo/boot
fi
cat >/mnt/gentoo/catch_chroot.sh <<EOF
#set up the new environment
env-update
source /etc/profile
bash
EOF
chroot /mnt/gentoo /bin/bash -c "bash /catch_chroot.sh"

