Difference between revisions of "Gentoo Workshop"

From CSLabsWiki
Jump to: navigation, search
m (Finised up day 2)
Line 14: Line 14:
 
FAQs and HOWTOs:
 
FAQs and HOWTOs:
 
* http://www.gentoo.org/doc/en/index.xml?catid=desktop
 
* http://www.gentoo.org/doc/en/index.xml?catid=desktop
* http://en.gentoo-wiki.com/wiki/Main_Page
+
* https://wiki.gentoo.org/wiki/Main_Page
  
 
= Spring 2012 =
 
= Spring 2012 =

Revision as of 08:32, 26 May 2016

Introduction

The Gentoo Workshop is intended to broaden interest in Gentoo Linux. Participants learn how to install and maintain Gentoo, such that they will be able to carry out these steps outside of the structured environment of the workshop.

The workshop was originally conducted by Mark Platek. Christian Mesh will be presenting it in the beginning 2012.

Resources

Gentoo Handbook:

Gentoo Forums:

FAQs and HOWTOs:

Spring 2012

Based off of http://www.gentoo.org/doc/en/handbook/handbook-x86.xml and Mark Platek's guide from 2010 (below).

About Gentoo

Gentoo is a "metadistribution", due to it's nearly unlimited configurability.

All programs, libraries, etc. are compiled from source, similar to LFS. However, Gentoo includes Portage, a tool that automates some compilation tasks.

Gentoo performs marginally better than binary distributions due to compiled programs being tuned to the host machine, but that's not as important as the extremely high degree of control over the system that Gentoo affords.

The cost of this power is complexity and effort. But, it's hard to go back to binary distributions once you grok Gentoo.

We Begin!

  • A good backup never hurt anyone :)
  • Make sure your machine is connected to the external Clarkson network via ethernet.
  • Boot the live cd. All of the defaults should be adequate.
  • You are now inside a environment in which you can start building.

Networking

  • `ping www.google.com` If this works youre networking is setup properly
  • ethX is your primary adapter where X the number of your netork card
  • `ifconfig` If you see your adapter shows up (ethX) procede to dhcpcd
  • `ifconfig -a` This shows all of your network adapters
  • `ifconfig ethX up` This makes sure your adapter is enabled
  • `dhcpcd ethX` this will attempt to obtain an IP address for ethX
  • `ping www.google.com`

Partitioning

For the next few steps, we are assuming you wish to use /dev/sda for your gentoo installation. If you wish to install to a different drive, from here on /dev/sda will be /dev/sdX where X is the letter of the target device

/dev/sda1 /boot ext2 100MB /dev/sda2 swap linux-swap 1-4GB /dev/sda3 / ext4 or xfs the rest

  • / is the root of your filesystem
  • /boot will store your kernel image(s) and grub (a boot loader)
  • swap is how linux uses space on a hard drive as ram. This is usually only used if you run out of physical memory

We will use the `parted` to format the disk.

!!!WARNING!!! The data on /dev/sda will be destroyed

  • `parted /dev/sda`
  • `mklabel msdos` or `mlabel gpt` This creates the partition table
  • `mkpart primary ext2 0MB 100MB` Create the boot partition
  • `mkpart primary linux-swap 100MB 2GB` Create a swap partition close to 2GB
  • `mkpart primary ext4 2GB -1s` Use the rest of the drive for /
  • `p` Verify everthing worked properly
  • `q` Exit the utility

Formatting

  • `mkfs.ext2 /dev/sda1`
  • `mkswap /dev/sda2`
  • `mkfs.ext4` or `mkfs.xfs` /dev/sda3

Mounting

/mnt/gentoo will serve as the location where we will start our build

  • `mount /dev/sda3 /mnt/gentoo`
  • `mkdir /mnt/gentoo/boot`
  • `mount /dev/sda1 /mnt/gentoo/boot`
  • `swapon /dev/sda2`

Date

This may seem like a odd time to worry about such things. Tar checks the timestamps on archived files and will holler bloody murder if you try to extract files from the future.

  • `date` If this is close to correct, you can move on
  • `date MMDDhhmmYYYY`

Stages

There are three possible “stages” from which to install Gentoo:

  • stage1: closer to LFS, you must compile the entire toolchain from scratch before you can proceed. (no longer supported ­ officially)
  • stage2: no longer supported at all
  • stage3: the toolchain is provided in a binary form

The stage3 tarball we are about to download contains binaries of GCC and other toolchain utilities. However, you can recompile the entire toolchain to emulate a stage1 install from a stage3. This process will give you a toolchain built for your specific machine by the most recent version of GCC. The downside? It takes about 6 hours if you have a good machine. In the interests of time, we will only do a stage3 install.


Installing stage3

We will use a text based web browser (links) to download the necessary files

  • `cd /mnt/gentoo/`
  • `links http://mirror.clarkson.edu/gentoo/`
  • Download "releases/(your architecture)/current-stage3/stage3-i686-______.tar.bz2"
  • Download "snapshots/portage-latest.tar.bz2"
  • 'q' Exit links

Next we will extract the stage3 and portage tarballs

  • `tar xvjpf stage3-*.tar.bz2`
  • `tar xvjf portage-latest.tar.bz2 -C /mnt/gentoo/usr`


The stage3 tarball will create the skeleton of a linux system. The portage snapshot contains a recent portage tree, portage is gentoo's interpretation of a "package manager"

Setting up make.conf

  • `nano /mnt/gentoo/etc/make.conf`

/etc/make.conf is portage's main configuration file. It lets you specify information on how portage should build and install pacakges for your system.

CFLAGS are your flags for gcc, CXXFLAGS are your flags for g++

  • Optimization
    • -O1 lowest optimization
    • -O2 safe optimization
    • -O3 unsafe optimization
  • -fomit-frame-pointer causes programs that don't use a frame pointer to be compiled without one. This can make debugging quite difficult.
  • -pipe use pipes to pass files where possible, increased speed, slightly more memory usage
  • -march=___ causes optimazation for your processor, see: http://en.gentoo-wiki.com/wiki/Safe_Cflags

gcc and g++ can use mutiple threads to take advantage of computers that have multiple cpu cores.

  • MAKEOPTS="-jN" where N is the number of cores + 1

Set mirror info for portage

Preparing to chroot

Copy over DNS info

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

Mount /dev /proc

  • mount -t proc none /mnt/gentoo/proc
  • mount --rbind /dev /mnt/gentoo/dev

Chrooting!

Chrooting allows you to enter the environment you created and run commands as if it is actually running.

  • chroot /mnt/gentoo /bin/bash

Setup your environment

  • env-update (refresh environment variables)
  • source /etc/profile (export new variables)
  • export PS1 = "(chroot)$PS1)"

You are now inside your new gentoo installation!

Portage

Commands

  • `emerge` is the command used to install and remove packages
  • `equery` is used to find information on a package
  • `eselect` is used to configure system parameters like gcc version and kernel version
  • `revdep-rebuild` is used to make sure the libraries on your system are in the right version

Examples

  • `emerge --sync` updates your portage tree
  • `emerge -uDN world` updates the entire system
  • `emerge -s sl` search for a package called sl
  • `eselect kernel list` lists available kernels

Run `emerge --sync`

Emerge the text editor of your choice

Ex:

  • emerge vim

Setting your locale

edit /etc/locale.gen

  • uncomment en_US.UTF-8 ...

`locale-gen`

Set your timezone

  • `ls /usr/share/zoneinfo/` list available timezones
  • `cp /usr/share/zoneinfo/EST /etc/localtime`

Running updates

Run `emerge -puDN world` to make sure everything checks out, then run `emerge -uDN world`

The Linux Kernel

We will be using the gentoo-sources package. It includes the generic Linux kernel with a few nice patches. Genkernel is a program that will build a kernel with a more generic config. When you use genkernel to build your kernel, your system will generally detect all your hardware at boot-time. It is not as fun to use genkernel so we will be configuring our kernel by hand.

  • `emerge gentoo-sources`
  • `cd /usr/src/linux`
  • /usr/src/linux points to /usr/src/linux-version. It is configured using eselect kernel. We only have one version at this time so the step is not necessary.
  • `make menuconfig`

We now can see a curses based menu system that will guide us through configuring our kernel. Items marked with a * will be built directly into the kernel. Items marked with a M will be built as a module and can be loaded at a later time. This allows you to include items like extra file systems and drivers without automatically loading them on boot.

General Setup

Here you can change options such as supporting swap, initramfs, kernel size optimization, and other such options. We can leave most of this alone, but it is a good place to look when you want to try some new things.

Module Support

We will leave this alone for now.

Enable the block layer

Take a look at the IO schedulers. The deadline scheduler was used by default until 2.6.18 when it was replaced by CFQ. CFQ (Completely Fair Queuing) tries to minimize costly disk seeks. What if disk seeks are of no concern? Say we have a SSD, we could use the No-op scheduler. No-op does not waste CPU time calculating the best seek pattern.

Processor type and features

First let's set the Processor family. We can also set the preemption mode for the kernel. This has a large impact on the performance of your system.

  • The safest is no preemption, but the kernel will be slower to react.
  • Full preemption allows the kernel to interrupt any process anytime. This decreases response time to user events but can lead to issues with high work loads.
  • Voluntary preemption is a compromise between the two.

You can disable features that do not pertain to your processor, such as Intel microcode update on a AMD system. There is lots of cool options in here that are just not in the scope of this workshop.

PM and ACPI

ACPI is one way for a computer to report it's state to the OS, for example laptop batteries.

Frequency Scaling support lets the OS set the frequency of the CPU. This is especially useful on laptops.

I would recommend disabling Hibernate. I have found it is easier to setup hibernation when that is not enabled in the kernel.

Bus Options

You might want to disable pc card support and pci hotplug here. There are some really cool hotplug features available in linux that I encourage you to take a look at.

Executable file Formats

I would recommend those of us doing 64bit build enable "IA32 a.out support".

Networking support

Networking Options does not really need to be changed, take a look though it is interesting. Unless you are part of K2CC, you can disable Amateur radio support. If you have bluetooth, make sure it is enabled here. If you have a desktop and want to disable wireless, we will come back to it. You can also disable ipv6 if you don't think you will need it.

Device Drivers

Here is a fun part that you want to get right. In general, if you are unsure about which driver to pick, choose all relevant ones. You can all ways come back to it later.

To find out what devices you have without looking at the manual, use `lspci` in another console (CTRL+ALT+F1-6).

SATA and PATA drivers

This is the first section that you really need to concern yourself with. I recommend selecting all options that pertain to your chipset manufacturer if you are unsure.

RAID and LVM

These can be disabled if you don't plan to use RAID or LVM.

Network Device Support

Disable Token Ring support. You will most likely never use this. You can also disable FDDI if you don't have a fiber optic connection to your computer.

Ethernet

Here you should enable the driver specific to your card only. If you are unsure, include all from your manufacturer.

Wireless

Here you should enable the driver specific to your card only. If you are unsure, include all from your manufacturer. If the manufacturer is Broadcom, good luck :(

If you are a desktop user, disable this option and go to Networking Support. You can now disable Wireless there.

Hardware Monitoring

Here you should enable monitoring for your processor if available.

Multimedia Support

Use this option if you want to have your webcam supported. The specifics are case by case, time to google it!

Graphics Support

This is another option where google is your best friend.

Sound Card Support

Here you want to enter ALSA config and select the proper device.

File Systems

Here you want to enable support for at least ext2 and ext4. Dos/FAT filesystems contains modules for mounting mircosoft partitions. NFS is a type of filesystem over a network. You can remove several partition types if you deem them unnessesary.

Kernel Hacking

This is generally a kernel by kernel basis. There is some really interesting stuff in here.

Security Options

If you don't want to deal with SELinux, disable it here.

Exit and save your config.

Compiling the Linux Kernel

Let's time it and see who has the fastest machine!

`time make -jN` (where N is the number of cores you have +1)

When that finishes, run make modules_install. This installs loadable modules into the proper directory.

It's time to copy the compiled kernel to /boot

`cp arch/x86/boot/bzImage /boot/kernel-3.2.2-gentoo` The kernel version should be the version you previously emerged

Setting up grub

`emerge -av grub`

edit /boot/grub/grub.conf

  • uncomment everything except initrd and vim info.
  • update the kernel version
  • remove real_root and change root to /dev/sda3

`grub --no-floppy`

  • root (hd0,0)
  • setup (hd0)
  • quit

Passwords

Time to set your root password, choose wisely.

`passwd`

/etc/fstab

This tells the os what partions should be mounted where and how.

edit /etc/fstab

  • change BOOT to sda1
  • change ROOT to sda3
  • change SWAP to sda2
  • comment out the floppy drive

dhcpcd

This will let you get an ip address when you reboot into your system

`emerge -av dhcpcd`

Rebooting!!!

Time to see if all of your hard work payed off.

  • `exit` (exit chroot)
  • `reboot` (tell the livecd to reboot
  • cross your fingers :}

Spring 2011 Slides

Session 1: http://web2.clarkson.edu/projects/cosi/fa2010/students/platekme/workshop1.pdf

Session 2: http://web2.clarkson.edu/projects/cosi/fa2010/students/platekme/workshop2.pdf

Session 3: http://web2.clarkson.edu/projects/cosi/fa2010/students/platekme/workshop3.pdf

Session 4: http://web2.clarkson.edu/projects/cosi/fa2010/students/platekme/workshop4.pdf

These slideshow presentations are Copyright © 2011 by Mark Platek and are licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.