Search:  
Gentoo Wiki

Gentoo_Install_Script

Gentoo Install Script

This is a script i made in about 5 minutes. It performs a standard by the book install compleate with partioning the drive and compiling the kernel. Please feel free to modify the original script but please provide credit. Just some information on how to use this or what to use it for.

  1. Goto the Gentoo mirror list and download a verision, either the LIVE CD or minimal CD [1]
  2. Burn the image and boot the CD, more information can be found in the Gentoo Documentation [2]
  3. Aquire an IP address and start SSH (sshd)
  4. SSH into the server
  5. Copy and paste the script below into a text editor (vim, emacs, etc...)
  6. Save the file and change the permisions to reflect execution rights
  7. Run the script and follow the instructions
#!/bin/bash
# GENTOO INSTALL SCRIPT FROM BASE INSTALL AND DEFAULT CONFIGS
# Created by: Morpheus (YYC)
#

# Display Introduction
echo "Welcome to the GENTOO install script, please note you must be at your system for instructions"
echo "this script will perform a majority of the configurations for you however certain interaction"
echo "may be required on your part."
echo
echo
echo "NOTE: THIS WILL RESULT IN DATA LOSS OF THE CURRENT DRIVE"
echo "Please press enter when your ready to continue."
read

# Configure hard disk
echo "The following is a list of found Hard Disk devices (sda/hda):"
ls /dev/ | grep -E [s:h]da$
echo
echo "Please enter the device you would like to install to:"
read HD_DEVICE
HDD="/dev/${HD_DEVICE}"

# warn user last time
echo
echo "THIS IS YOUR LAST CHANCE TO CANCEL, Press CTRL+C to cancel this install or ENTER to continue"
read
echo "p" | fdisk $HDD
echo "Please specifiy the total number of partitions:"
read PARTS

#TODO: add integer checking
echo -n "Generating fdisk operation file"
# Create fdisc auto file
((i = 1))
while (( i < PARTS ))
do
echo "d" >> fdisc.in
echo "$i" >> fdisc.in
((i += 1))
done
echo "d" 	>> fdisc.in	# Delete last sector
echo "n" 	>> fdisc.in	# New Partiton
echo "p" 	>> fdisc.in	# Primary
echo "1" 	>> fdisc.in	# Partion 1
echo "" 	>> fdisc.in	# default
echo "+32M" 	>> fdisc.in	# 32 MB size
echo "a" 	>> fdisc.in	# Set flag
echo "1" 	>> fdisc.in	# bootable
echo -n "."
echo "n" 	>> fdisc.in	# New Partion
echo "p" 	>> fdisc.in	# Primary
echo "2" 	>> fdisc.in	# Partion 2
echo "" 	>> fdisc.in	# default
echo "+512M" 	>> fdisc.in	# 512 MB size
echo "t" 	>> fdisc.in	# Set partition type
echo "2" 	>> fdisc.in	# Partition 2
echo "82" 	>> fdisc.in	# 82 = SWAP
echo -n "."
echo "n" 	>> fdisc.in	# New Partition
echo "p" 	>> fdisc.in	# Primary
echo "3" 	>> fdisc.in	# Partition 2
echo "" 	>> fdisc.in	# default
echo "" 	>> fdisc.in	# new Line
echo -n "."
echo "w" 	>> fdisc.in	# Write partion table
echo "q" 	>> fdisc.in	# Quit
echo ". Done"
# Execute file
echo "Executing fdisk script ..."
echo
fdisk $HDD < fdisc.in
#clean up
rm -f fdisc.in
echo ""
echo "Partions created"
echo "Applying filesystem to partitions"
mke2fs /dev/${HD_DEVICE}1
mke2fs -j /dev/${HD_DEVICE}3
mkswap /dev/${HD_DEVICE}2
echo "Activating swap partition"
swapon /dev/${HD_DEVICE}2
echo ""
echo "Mounting partitions"
mount /dev/${HD_DEVICE}3 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/${HD_DEVICE}1 /mnt/gentoo/boot
echo "Starting STAGE 3 Install"
echo ""
cd /mnt/gentoo
wget http://gentoo.osuosl.org/releases/x86/current/stages/stage3-x86-2008.0.tar.bz2
tar xvjpf stage3-*.tar.bz2
echo ""
echo "Installing portage..."
cd /mnt/gentoo
wget http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2
tar xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /mnt/gentoo/usr
echo "Cleaning up..."
rm -f portage-latest.tar.bz2
rm -f stage3-x86-2006.1.tar.bz2
echo ""
echo "Getting ready to CHROOT"
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
echo "Chrooted"
echo "Updating portage..."
sleep 2
chroot /mnt/gentoo emerge --sync
echo "Patching portage..."
chroot /mnt/gentoo emerge portage
echo "Portage updated, downloading kernel source..."
sleep 2

echo "#!/bin/bash" > /mnt/gentoo/portage
echo 'USE="-doc symlink" emerge gentoo-sources' >> /mnt/gentoo/portage
chmod 700 /mnt/gentoo/portage
chroot /mnt/gentoo ./portage
rm -f /mnt/gentoo/portage

echo "#!/bin/bash" > /mnt/gentoo/portage
echo 'cd /usr/src/linux' >> /mnt/gentoo/portage
echo 'echo ""' >> /mnt/gentoo/portage
echo 'echo "***************************************************"' >> /mnt/gentoo/portage
echo 'echo "**            KERNEL CONFIGURATION               **"' >> /mnt/gentoo/portage
echo 'echo "***************************************************"' >> /mnt/gentoo/portage
echo 'echo "* You will now be prompted with the linux kernel  *"' >> /mnt/gentoo/portage
echo 'echo "*menu configurator, please ensure that you specify*"' >> /mnt/gentoo/portage
echo 'echo "*the right settings, as once you exit this script *"' >> /mnt/gentoo/portage
echo 'echo "*will compile and install the new kernel          *"' >> /mnt/gentoo/portage
echo 'echo "***************************************************"' >> /mnt/gentoo/portage
echo 'echo ""' >> /mnt/gentoo/portage
echo 'echo "Please press enter to continue"' >> /mnt/gentoo/portage
echo 'read' >> /mnt/gentoo/portage
echo 'make menuconfig' >> /mnt/gentoo/portage
echo 'make && make modules_install' >> /mnt/gentoo/portage
echo 'cp arch/i386/boot/bzImage /boot/originalKernel' >> /mnt/gentoo/portage
echo 'echo ""' >> /mnt/gentoo/portage
chmod 700 /mnt/gentoo/portage
chroot /mnt/gentoo ./portage
rm -f /mnt/gentoo/portage

echo "Generating FSTAB"
#GENERATE FSTAB
echo "# /etc/fstab: static file system information." > /mnt/gentoo/etc/fstab
echo "#" >> /mnt/gentoo/etc/fstab
echo "# noatime turns off atimes for increased performance (atimes normally aren't" >> /mnt/gentoo/etc/fstab
echo "# needed; notail increases performance of ReiserFS (at the expense of storage" >> /mnt/gentoo/etc/fstab
echo "# efficiency).  It's safe to drop the noatime options if you want and to" >> /mnt/gentoo/etc/fstab
echo "# switch between notail / tail freely." >> /mnt/gentoo/etc/fstab
echo "#" >> /mnt/gentoo/etc/fstab
echo "# The root filesystem should have a pass number of either 0 or 1." >> /mnt/gentoo/etc/fstab
echo "# All other filesystems should have a pass number of 0 or greater than 1." >> /mnt/gentoo/etc/fstab
echo "#" >> /mnt/gentoo/etc/fstab
echo "# See the manpage fstab(5) for more information." >> /mnt/gentoo/etc/fstab
echo "#" >> /mnt/gentoo/etc/fstab
echo "" >> /mnt/gentoo/etc/fstab
echo "# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>" >> /mnt/gentoo/etc/fstab
echo "" >> /mnt/gentoo/etc/fstab
echo "# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts." >> /mnt/gentoo/etc/fstab
echo "/dev/${HD_DEVICE}1               /boot           ext2            noauto,noatime  1 2" >> /mnt/gentoo/etc/fstab
echo "/dev/${HD_DEVICE}3               /               ext3            noatime         0 1" >> /mnt/gentoo/etc/fstab
echo "/dev/${HD_DEVICE}2               none            swap            sw              0 0" >> /mnt/gentoo/etc/fstab
echo "#/dev/cdroms/cdrom0      /mnt/cdrom      iso9660         noauto,ro       0 0" >> /mnt/gentoo/etc/fstab
echo "#/dev/fd0               /mnt/floppy     auto            noauto          0 0" >> /mnt/gentoo/etc/fstab
echo "" >> /mnt/gentoo/etc/fstab
echo "# NOTE: The next line is critical for boot!" >> /mnt/gentoo/etc/fstab
echo "proc                    /proc           proc            defaults        0 0" >> /mnt/gentoo/etc/fstab
echo "" >> /mnt/gentoo/etc/fstab
echo "# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for" >> /mnt/gentoo/etc/fstab
echo "# POSIX shared memory (shm_open, shm_unlink)." >> /mnt/gentoo/etc/fstab
echo "# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will" >> /mnt/gentoo/etc/fstab
echo "#  use almost no memory if not populated with files)" >> /mnt/gentoo/etc/fstab
echo "shm                     /dev/shm        tmpfs           nodev,nosuid,noexec     0 0" >> /mnt/gentoo/etc/fstab
cat /mnt/gentoo/etc/fstab
echo ""
echo "Configuring rc scripts"
chroot /mnt/gentoo rc-update add net.eth0 default
chroot /mnt/gentoo rc-update add sshd default
echo "*************** ROOT PASSWORD ********************"
echo "YOU ARE NOW REQUIRED TO ENTER A NEW ROOT PASSWORD "
echo "**************************************************"
chroot /mnt/gentoo passwd
echo "Installing tools..."
chroot /mnt/gentoo emerge syslog-ng vixie-cron slocate dhcpcd
chroot /mnt/gentoo rc-update add syslog-ng default
chroot /mnt/gentoo rc-update add vixie-cron
echo ""
echo ""
echo "Installing LILO"
chroot /mnt/gentoo emerge lilo
echo "boot=/dev/${HD_DEVICE}       # Install LILO in the MBR" >> /mnt/gentoo/etc/lilo.conf
echo "prompt                    # Give the user the chance to select another section" >> /mnt/gentoo/etc/lilo.conf
echo "timeout=50                # Wait 5 (five) seconds before booting the default section" >> /mnt/gentoo/etc/lilo.conf
echo "default=gentoo            # When the timeout has passed, boot the "gentoo" section" >> /mnt/gentoo/etc/lilo.conf
echo "" >> /mnt/gentoo/etc/lilo.conf
echo "# For non-genkernel users" >> /mnt/gentoo/etc/lilo.conf
echo "image=/boot/originalKernel" >> /mnt/gentoo/etc/lilo.conf
echo "        label=gentoo            # Name we give to this section" >> /mnt/gentoo/etc/lilo.conf
echo "        read-only               # Start with a read-only root. Do not alter!" >> /mnt/gentoo/etc/lilo.conf
echo "        root=/dev/${HD_DEVICE}3          # Location of the root filesystem" >> /mnt/gentoo/etc/lilo.conf
chroot /mnt/gentoo lilo
cd /
umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo
echo "Done"
echo "****************************"
echo "****************************"
echo "** SYSTEM WILL NOW REBOOT **"
echo "****************************"
echo "****************************"
sleep 5
reboot
Retrieved from "http://www.gentoo-wiki.info/Gentoo_Install_Script"

Last modified: Thu, 04 Sep 2008 05:29:00 +0000 Hits: 1,820