Difference between pages "Funtoo Linux Installation" and "Building a Kernel from Source"

From Funtoo
(Difference between pages)
Jump to: navigation, search
m (we had /sys mounted too)
 
m
 
Line 1: Line 1:
== Introduction ==
+
Setting up a proper kernel yourself - lean, mean and tailored to your hardware,  is the challenge by which a linux user can graduate to becoming a Funtoo knight ;-)
  
This document was written to help you install Funtoo Linux as concisely as possible, with a minimum number of distracting options regarding system configuration.  
+
Even though many of us are using enterprise-ready kernels in datacenters, there is almost nobody who hasn't at least considered building a kernel for his laptop / PC.
 +
We are showing here how an intermediate Linux user can use an alternative to the standard beginners "genkernel" approach, to compile a custom kernel,  in a relatively still speedy and easy set up.
  
These docs assume you have a "PC compatible" computer system with a standard PC BIOS. Many new computers support UEFI for booting, which is a new firmware interface that replaces the old-fashioned MBR-based BIOS. If you have a system with UEFI, you will want to use this documentation along with the [[UEFI Install Guide]], which will augment these instructions and explain how to get your system to boot. You may need to change your PC BIOS settings to enable or disable UEFI booting. The [[UEFI Install Guide]] has more information on this, and steps on how to determine if your system supports UEFI.
+
=== Minimum Requirements ===
 +
You should understand the way how things work in a terminal and how to use an editor and tweak config files. This is crucial.
 +
You don't need much knowledge about the linux kernel and it's internals. Nevertheless, you have to know at least where the files are located, how they are used and what is the file logic behind the overall structure. Otherwise you should consider using a non source based linux distribution.
 +
If you are scared now, don't worry - we are going to build a kernel the Funtoo way and you will pick up everthing necessary to accomplish this challenge, step by step, so the next time you do it yourself and become a real Funtoo knight!
  
We also offer a [[ZFS Install Guide]], which augment the instructions on this page for those who want to install Funtoo Linux on ZFS.  If you are installing Funtoo Linux on [[Funtoo Linux Installation on ARM|ARM]] architecture, please see [[Funtoo Linux Installation on ARM]] for notable differences regarding ARM support. An experimental Funtoo Linux build also exists for [[Funtoo Linux Installation on SPARC|SPARC]] platforms. See [[Funtoo Linux Installation on SPARC]].
+
=== Assumptions ===
 +
You start from an installed Funtoo system on the disk, or at least, you are on stage3 in a chrooted environment from a live cd, following somehow the Funto [[Installation (Tutorial)|Installation Tutorial]].
  
If you've had previous experience installing Gentoo Linux then a lot of steps will be familiar, but you should still read through as there are a few differences.
+
In this case we are building a kernel that is booting root in LVM over encrypted LUKS container.
 +
If you don't have this setup, don't worry, you just don't need all the modules, but everything else is similar.
  
== Installation Overview ==
 
  
This is a basic overview of the Funtoo installation process:
+
= Getting everything in order to start =
  
# [[#Live CD|Download and boot the live CD of your choice]].
+
First there is the decision which linux kernel sources we need.
# [[#Prepare Hard Disk|Prepare your disk]].
+
There are plenty of them in the repositories around, often it is not easy to distinguish between them.
# [[#Creating filesystems|Create]] and [[#Mounting filesystems|mount]] filesystems.
+
# [[#Installing the Stage 3 tarball|Install the Funtoo stage tarball]] of your choice.
+
# [[#Chroot into Funtoo|Chroot into your new system]].
+
# [[#Downloading the Portage tree|Download the Portage tree]].
+
# [[#Configuring your system|Configure your system]] and [[#Configuring your network|network]].
+
# [[#Configuring and installing the Linux kernel|Install a kernel]].
+
# [[#Installing a Bootloader|Install a bootloader]].
+
# [[#Finishing Steps|Complete final steps]].
+
# [[#Restart your system|Reboot and enjoy]].
+
  
=== Live CD ===
+
I would always trust my distribution of choice and take what is has to offer - and funtoo has a lot to offer!
  
Funtoo doesn't provide an "official" Funtoo Live CD, but there are plenty of good ones out there to choose from. A great choice is the Gentoo-based [http://www.sysresccd.org/ SystemRescueCd] as it contains lots of tools and utilities and supports both 32-bit and 64-bit systems.
+
I really do recommend (especially if it is your first time) to build a debian-sourced genkernel like described in chapter 5 "Using Debian-Sources with Genkernel" in the [[Funtoo_Linux_Kernels| Funtoo Kernels Tutorial]].
  
It is also possible to install Funtoo Linux using many other Linux-based live CDs. Generally, any modern bootable Linux live CD or live USB media will work. See [[Requirements|requirements]] for an overview of what the Live Media must provide to allow a problem-free install of Funtoo Linux.
+
From there you should have a running system booting nicely from your own build (just little bit bloated) kernel. This is more than you can expect from any other ready to go distribution.
  
To begin a Funtoo Linux installation, download SystemRescueCD from:
+
'''Attention'''
 +
We are using RedHat's dracut in order to build a nice initramfs (containing all the necessary tools and extra drivers our kernel might need to start the system).
  
* Main US mirror: [http://ftp.osuosl.org/pub/funtoo/distfiles/sysresccd/sysresccd-3.7.1_zfs_0.6.2.iso The Oregon State University Open Source Lab]
+
Although dracut is the way to go, more sophisticated and not as buggy as gentoo's genkernel approach, more and more funtoo geeks start using slashbeast's better-initramfs, which we will cover at the end of this howto!
* Main EU mirror: [http://ftp.heanet.ie/mirrors/funtoo/distfiles/sysresccd/sysresccd-3.7.1_zfs_0.6.2.iso HEAnet] or use your preferred live media. Insert it into your disc drive, and boot from it. If using an older version of SystemRescueCD, '''be sure to select the <tt>rescue64</tt> kernel at the boot menu if you are installing a 64-bit system'''. By default, SystemRescueCD used to boot in 32-bit mode though the latest version attempts to automatically detect 64-bit processors.
+
  
=== Prepare Hard Disk ===
+
So after having set up a genkernel from debian or gentoo sources we are going to build a kernel with either (or both) dracut or/and better-initramfs.
==== Partitions ====
+
So gentoo sources with genkernel is always my backup if anything is not working correctly on my system. For the slightly more geeky approach with my own initram I am using pf-sources, ck-sources or any other more or less heavily patched sources.
  
Funtoo Linux fully supports traditional MBR partitions, as well as newer GPT/GUID partition formats. Funtoo Linux recommends the use of the GPT partitioning scheme, since it is newer and more flexible. Here are the various trade-offs between each partitioning scheme:
+
Let's go!
  
===== GPT Partitions =====
+
== Kernel Sources ==
 +
We are going to use the kernel sources from the funtoo git repository.
  
* Newer, preferred format for Linux systems
+
The source you use on your system is up to you and your needs.
* Supports 2 TB+ hard drives for booting
+
For a laptop or desktop system, we recommend the following:
* Supports hundreds of partitions per disk of any size
+
* Requires legacy BIOS boot partition (~32 MB) to be created if system does not use EFI
+
* Requires bootloader with support for GPT such as GRUB 2, EXTLINUX, or a patched version of GRUB Legacy
+
  
===== MBR Partitions =====
+
* '''sys-kernel/pf-sources'''
 +
* '''sys-kernel/ck-sources'''
 +
* '''sys-kernel/gentoo-sources'''
 +
* '''sys-kernel/git-sources'''
 +
* '''sys-kernel/sysrescue-std-sources'''
 +
* '''sys-kernel/debian-sources'''
  
* Legacy, DOS partitioning scheme
+
Please, have a look in the ebuild description, look onto their homepage and take the one that suits you best!
* Only 4 primary partitions per disk; after that, you must use "logical" partitions
+
If you are unsure for now, use sys-kernel/gentoo-sources. That's always a safe bet for a general system.
* Does not support 2 TB+ disks for booting
+
* Compatible with certain problematic systems (such as the HP ProBook 4520)
+
* Dual-boot with Windows for BIOS systems (Windows handle GPT only on true EFI systems, whatever version it is)
+
* Multiple boot loader options, e.g. GRUB 2, GRUB Legacy, lilo
+
  
{{fancyimportant|If you plan to use partitions of 2 TB or greater, you ''must'' partition using the GPT/GUID format. Also note that there are small percentage of PCs that will not boot properly with GPT. For these systems, using MBR partitions or a primary drive with an MBR partition may be required in order to boot.}}
+
It is not a problem to have various kernels installed parallel, so go on with any one of them.
  
==== Partitioning Using gdisk ====
+
I am going to use the sys-kernel/pf-sources now, as I already had the gentoo-sources installed.
  
===== Notes Before We Begin =====
+
== Prerequisites ==
  
These install instructions assume you are installing Funtoo Linux to an empty hard disk using GUID partition tables (GPT). If you are installing Funtoo Linux on a machine where another OS is installed, or there is an existing Linux distribution on your system that you want to keep, then you will need to adapt these instructions to suit your needs.
+
I don't know which tools you have already installed, so some information here might be redundant.
 +
It doesn't harm to just copy and paste and do some steps again.
  
If you are going to create a legacy MBR partition table instead of GUID/GPT, you will use the <tt>fdisk</tt> command instead of <tt>gdisk</tt>, and you will not need to create the GRUB boot loader partition. See the table under [[#Partitioning Recommendations|Partitioning Recommendations]], in particular the
+
First, we look into our <code>/etc/make.conf</code>:
'''MBR Block Device (<tt>fdisk</tt>)''' and '''MBR Code''' columns. <tt>fdisk</tt> works just like <tt>gdisk</tt>, but creates legacy MBR partition tables instead of the newer GPT/GUID partition tables.
+
 
+
Advanced users may be interested in the following topics:
+
 
+
* [[GUID Booting Guide]]
+
* [[Rootfs over encrypted lvm]]
+
* [[Rootfs over encrypted lvm over raid-1 on GPT]]
+
* '''NEW!''' '''[[ZFS Install Guide]] (Also contains instructions for Rootfs over Encrypted ZFS!)'''
+
 
+
===== Using gdisk =====
+
 
+
The first step after booting SystemRescueCd is to use <tt>gdisk</tt> to create GPT (also known as GUID) partitions, specifying the disk you want to use, which is typically <tt>/dev/sda</tt>, the first disk in the system:
+
 
+
<console># ##i##gdisk /dev/sda</console>
+
You should find <tt>gdisk</tt> very similar to <tt>fdisk</tt>. Here is the partition table we want to end up with:
+
 
+
<console>Command (? for help): ##i##p
+
Disk /dev/sda: 234441648 sectors, 111.8 GiB
+
Logical sector size: 512 bytes
+
Disk identifier (GUID): A4E5208A-CED3-4263-BB25-7147DC426931
+
Partition table holds up to 128 entries
+
First usable sector is 34, last usable sector is 234441614
+
Partitions will be aligned on 2048-sector boundaries
+
Total free space is 2014 sectors (1007.0 KiB)
+
 
+
Number  Start (sector)    End (sector)  Size      Code  Name
+
  1            2048          206847  500.0 MiB  8300  Linux filesystem
+
  2          206848          272383  32.0 MiB    EF02  BIOS boot partition
+
  3          272384        8660991  4.0 GiB    8200  Linux swap
+
  4        8660992      234441614  107.7 GiB  8300  Linux filesystem
+
 
+
Command (? for help): </console>
+
 
+
Above, you'll see that we have a 500 MiB boot partition, a 32 MiB "BIOS boot partition" (also known as the GRUB boot loader partition), 4 GiB of swap, and the remaining disk used by a 107.7 GiB root partition.
+
 
+
===== For new <tt>gdisk</tt> users =====
+
 
+
These partitions were created using the "<tt>n</tt>" command from within <tt>gdisk</tt>. The <tt>gdisk</tt> commands to create the partition table above are as follows. Adapt sizes as necessary, although these defaults will work for most users. The partition codes entered below can be found in the [[#Partitioning Recommendations|Partitioning Recommendations]] table below, in the GPT Code column.
+
 
+
Within <tt>gdisk</tt>, follow these steps:
+
 
+
'''Create Partition 1''' (boot):
+
  
 
<console>
 
<console>
Command: ##i##n ↵
+
##i### nano /etc/make.conf
Partition Number: ##i##1 ↵
+
#These compiler flags are just tweaking (optimazation) and NOT necessary:
First sector: ##i##↵
+
CFLAGS="-O2 -pipe -march=native -ftracer -fforce-addr"
Last sector: ##i##+500M ↵
+
CXXFLAGS="${CFLAGS} -fpermissive -fomit-frame-pointer"
Hex Code: ##i##↵
+
KDIR=/usr/src/linux
 +
KERNEL="symlink build"
 +
USE="$KERNEL ....here are your use flags...."
 +
## These modules are available:
 +
## DRACUT_MODULES="dracut_modules_biosdevname dracut_modules_btrfs dracut_modules_caps dracut_modules_crypt dracut_modules_crypt-gpg dracut_modules_dmraid dracut_modules_dmsquash-live dracut_modules_gensplash dracut_modules_iscsi dracut_modules_livenet dracut_modules_lvm dracut_modules_mdraid dracut_modules_multipath dracut_modules_nbd dracut_modules_nfs dracut_modules_plymouth dracut_modules_ssh-client dracut_modules_syslog"
 +
## We will use these modules for LVM / LUKS:
 +
DRACUT_MODULES="crypt lvm plymouth biosdevname dmraid crypt-gpg dmsquash-live ssh-client syslog"
 
</console>
 
</console>
  
'''Create Partition 2''' (GRUB):
+
Next, we set the package keywords:
 
+
 
<console>
 
<console>
Command: ##i##n ↵
+
/etc/portage/package.use/dracut:
Partition Number: ##i##2 ↵
+
sys-kernel/dracut dm net device-mapper crypt lvm
First sector: ##i##↵
+
Last sector: ##i##+32M ↵
+
Hex Code: ##i##EF02 ↵
+
 
</console>
 
</console>
  
'''Create Partition 3''' (swap):
+
{{Note}} If you don't have lvm over encrypted LUKS you probably just add the "net" keyword here, or "selinux".
 
+
<console>
+
Command: ##i##n ↵
+
Partition Number: ##i##3 ↵
+
First sector: ##i##↵
+
Last sector: ##i##+4G ↵
+
Hex Code: ##i##8200 ↵
+
</console>
+
  
'''Create Partition 4''' (root):
 
  
 +
After that we are going to build our packages:
 
<console>
 
<console>
Command: ##i##n ↵
+
# ##i##emerge -av app-portage/gentoolkit sys-kernel/pf-sources sys-kernel/dracut sys-boot/plymouth sys-boot/plymouth-openrc-plugin
Partition Number: ##i##4 ↵
+
First sector: ##i##↵
+
Last sector: ##i##↵##!i## (for rest of disk)
+
Hex Code: ##i##
+
 
</console>
 
</console>
  
Along the way, you can type "<tt>p</tt>" and hit Enter to view your current partition table. If you make a mistake, you can type "<tt>d</tt>" to delete an existing partition that you created. When you are satisfied with your partition setup, type "<tt>w</tt>" to write your configuration to disk:
+
Finished? Well, then let's go on and
  
'''Write Partition Table To Disk''':
+
== Preparing the kernel ==
  
 +
We go now to the sources directory and enter the following commands to update the kernel's  .config  file:
 
<console>
 
<console>
Command: ##i##w ↵
+
##i### cd /usr/src/linux/
Do you want to proceed? (Y/N): ##i##Y ↵
+
##i### make clean
 +
  CLEAN  .
 +
  CLEAN  arch/x86/kernel/acpi/realmode
 +
  CLEAN  arch/x86/kernel/cpu
 +
  CLEAN  arch/x86/kernel
 +
  CLEAN  arch/x86/vdso
 +
  CLEAN  arch/x86/lib
 +
  CLEAN  drivers/gpu/drm/radeon
 +
  CLEAN  drivers/net/wan
 +
  CLEAN  drivers/scsi/aic7xxx
 +
  CLEAN  drivers/tty/vt
 +
  CLEAN  drivers/video/logo
 +
  CLEAN  firmware
 +
  CLEAN  kernel
 +
  CLEAN  lib/raid6
 +
  CLEAN  lib
 +
  CLEAN  security/apparmor
 +
  CLEAN  security/selinux
 +
  CLEAN  usr
 +
  CLEAN  arch/x86/boot/compressed
 +
  CLEAN  arch/x86/boot
 +
  CLEAN  .tmp_versions
 +
  CLEAN  vmlinux System.map .tmp_kallsyms2.S .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms1.S .tmp_vmlinux1 .tmp_vmlinux2 .tmp_System.map
 +
##i### zcat /proc/config.gz > /usr/src/linux/.config
 
</console>
 
</console>
 
The partition table will now be written to disk and <tt>gdisk</tt> will close.
 
 
Now, your GPT/GUID partitions have been created, and will show up as the following ''block devices'' under Linux:
 
 
* <tt>/dev/sda1</tt>, which will be used to hold the <tt>/boot</tt> filesystem,
 
* <tt>/dev/sda2</tt>, which will be used directly by the new GRUB,
 
* <tt>/dev/sda3</tt>, which will be used for swap space, and
 
* <tt>/dev/sda4</tt>, which will hold your root filesystem.
 
 
===== For Previous fdisk users =====
 
 
If you have installed Gentoo Linux before, the one thing that is likely new to you here is the GRUB boot loader partition, which is listed as "BIOS boot partition" within <tt>gdisk</tt>. This partition is required for GRUB 2 to boot GPT/GUID boot disks. What is it? In GRUB-speak, this partition is essentially the location of the meat of GRUB's boot loading code. If you've used GRUB Legacy in the past, this partition is where the new GRUB stores the equivalent of the <tt>stage1_5</tt> and <tt>stage2</tt> files in legacy GRUB. Since GPT-based partition tables have less dead space at the beginning of the disk than their MBR equivalents, an explicitly defined partition of code <tt>EF02</tt> is required to hold the guts of the boot loader.
 
 
In all other respects, the partition table is similar to that which you might create for an MBR-based disk during a Gentoo Linux installation. We have a boot and a root partition with code <tt>0700</tt>, and a Linux swap partition with code <tt>8200</tt>.
 
 
===== Partitioning Recommendations =====
 
 
Below are our partitioning recommendations in table form. For GPT-based partitions, use the GPT Block Device and GPT Code columns with <tt>gdisk</tt>. For legacy MBR-based partitions, use the MBR Block Device and MBR code columns with <tt>fdisk</tt>:
 
 
{| {{table}}
 
!Partition
 
!Size
 
!MBR Block Device (<tt>fdisk</tt>)
 
!GPT Block Device (<tt>gdisk</tt>)
 
!Filesystem
 
!MBR Code
 
!GPT Code
 
|-
 
|<tt>/boot</tt>
 
|500 MB
 
|<tt>/dev/sda1</tt>
 
|<tt>/dev/sda1</tt>
 
|ext2
 
|83
 
|8300
 
|-
 
|GRUB boot loader partition
 
|32 MB
 
| ''not required for MBR''
 
|<tt>/dev/sda2</tt>
 
|For GPT/GUID only, skip for MBR - no filesystem.
 
|''N/A''
 
|EF02
 
|-
 
|swap
 
|2x RAM for low-memory systems and production servers; otherwise 2GB.
 
|<tt>/dev/sda2</tt>
 
|<tt>/dev/sda3</tt>
 
|swap (default)
 
|82
 
|8200
 
|-
 
|<tt>/</tt> (root)
 
|Rest of the disk, minimum of 10GB.
 
|<tt>/dev/sda3</tt>
 
|<tt>/dev/sda4</tt>
 
|XFS recommended, alternatively ext4
 
|83
 
|8300
 
|-
 
|<tt>/home</tt> (optional)
 
|User storage and media. Typically most of the disk.
 
|<tt>/dev/sda4</tt> (if created)
 
|<tt>/dev/sda5</tt> (if created)
 
|XFS recommended, alternatively ext4
 
|83
 
|8300
 
|-
 
| LVM (optional)
 
| If you want to create an LVM volume.
 
| <tt>/dev/sda4</tt> (PV, if created)
 
| <tt>/dev/sda5</tt> (PV, if created)
 
| LVM PV
 
| 8E
 
| 8E00
 
|}
 
 
==== Creating filesystems ====
 
 
Before your newly-created partitions can be used, the block devices need to be initialized with filesystem ''metadata''. This process is known as ''creating a filesystem'' on the block devices. After filesystems are created on the block devices, they can be mounted and used to store files.
 
 
You will not create a filesystem on your swap partition, but will initialize it using the <tt>mkswap</tt> command so that it can be used as disk-based virtual memory. Then we'll run the <tt>swapon</tt> command to make your newly-initialized swap space active within the live CD environment, in case it is needed during the rest of the install process.
 
 
Note that we will not create a filesystem on the GRUB boot loader partition, as GRUB writes binary data directly to that partition when the boot loader is installed, which we'll do later.
 
 
You can see the commands you will need to type below. Like the rest of this document, it assumes that you are using a GPT partitioning scheme. If you are using MBR, your root filesystem will likely be created on <tt>/dev/sda3</tt> instead and you will need to adjust the target block devices. If you are following our recommendations, then simply do this:
 
  
 
<console>
 
<console>
# ##i##mke2fs -t ext2 /dev/sda1
+
##i### make localmodconfig
# ##i##mkfs.xfs /dev/sda4
+
# ##i##mkswap /dev/sda3
+
# ##i##swapon /dev/sda3
+
 
</console>
 
</console>
  
 +
You will get some questions which you can answer mostly with either M (compiled as a module) or Y (compiled directly into the kernel).
 +
<pre>
 +
Enable different security models (SECURITY) [Y/n/?] y
 +
Enable the securityfs filesystem (SECURITYFS) [Y/?] y
 +
Socket and Networking Security Hooks (SECURITY_NETWORK) [Y/?] y
 +
Security hooks for pathname based access control (SECURITY_PATH) [Y/?] y
 +
Low address space for LSM to protect from user allocation (LSM_MMAP_MIN_ADDR) [65536] 65536
 +
NSA SELinux Support (SECURITY_SELINUX) [Y/n/?] y
 +
  NSA SELinux boot parameter (SECURITY_SELINUX_BOOTPARAM) [N/y/?] n
 +
  NSA SELinux runtime disable (SECURITY_SELINUX_DISABLE) [N/y/?] n
 +
  NSA SELinux Development Support (SECURITY_SELINUX_DEVELOP) [Y/n/?] y
 +
  NSA SELinux AVC Statistics (SECURITY_SELINUX_AVC_STATS) [Y/n/?] y
 +
  NSA SELinux checkreqprot default value (SECURITY_SELINUX_CHECKREQPROT_VALUE) [1] 1
 +
  NSA SELinux maximum supported policy format version (SECURITY_SELINUX_POLICYDB_VERSION_MAX) [Y/n/?] y
 +
    NSA SELinux maximum supported policy format version value (SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE) [19] 19
 +
TOMOYO Linux Support (SECURITY_TOMOYO) [Y/n/?] y
 +
  Default maximal count for learning mode (SECURITY_TOMOYO_MAX_ACCEPT_ENTRY) [2048] 2048
 +
  Default maximal count for audit log (SECURITY_TOMOYO_MAX_AUDIT_LOG) [1024] 1024
 +
  Activate without calling userspace policy loader. (SECURITY_TOMOYO_OMIT_USERSPACE_LOADER) [Y/n/?] y
 +
AppArmor support (SECURITY_APPARMOR) [Y/n/?] y
 +
  AppArmor boot parameter default value (SECURITY_APPARMOR_BOOTPARAM_VALUE) [1] 1
 +
Integrity Measurement Architecture(IMA) (IMA) [Y/n/?] y
 +
EVM support (EVM) [N/y/?] (NEW)
 +
Default security module
 +
  1. SELinux (DEFAULT_SECURITY_SELINUX)
 +
  2. TOMOYO (DEFAULT_SECURITY_TOMOYO)
 +
  3. AppArmor (DEFAULT_SECURITY_APPARMOR)
 +
> 4. Unix Discretionary Access Controls (DEFAULT_SECURITY_DAC)
 +
choice[1-4?]: 4
 +
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
 +
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
 +
#
 +
# configuration written to .config
 +
#
 +
warning: (GFS2_FS) selects DLM which has unmet direct dependencies (EXPERIMENTAL && INET && SYSFS && CONFIGFS_FS && (IPV6 || IPV6=n))
 +
warning: (IMA) selects TCG_TPM which has unmet direct dependencies (HAS_IOMEM && EXPERIMENTAL)
 +
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
 +
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
 +
root@[~src/linux] #
  
XFS filesystem is incompatible with CONFIG_USER_NS config option in kernel (required for LXC)
+
</pre>
for XFS filesystem:
+
<console>
+
# ##i##mke2fs -t ext2 /dev/sda1
+
# ##i##mkfs.xfs /dev/sda4
+
# ##i##mkswap /dev/sda3
+
# ##i##swapon /dev/sda3
+
</console>
+
 
+
==== Mounting filesystems ====
+
  
Mount the newly-created filesystems as follows, creating <tt>/mnt/funtoo</tt> as the installation mount point:
+
Now comes the most adventurous part!
  
 +
= Building the Kernel =
 
<console>
 
<console>
# ##i##mkdir /mnt/funtoo
+
##i### make -j8  bzImage
# ##i##mount /dev/sda4 /mnt/funtoo
+
##i### make -j8 modules
# ##i##mkdir /mnt/funtoo/boot
+
##i### make modules_install
# ##i##mount /dev/sda1 /mnt/funtoo/boot
+
##i### make install
 
</console>
 
</console>
  
Optionally, if you have a separate filesystem for <tt>/home</tt> or anything else:
 
  
<console>
+
'''Building an initramfs or not?'''
# ##i##mkdir /mnt/funtoo/home
+
# ##i##mount /dev/sda5 /mnt/funtoo/home
+
</console>
+
  
If you have <tt>/tmp</tt> or <tt>/var/tmp</tt> on a separate filesystem, be sure to change the permissions of the mount point to be globally-writeable after mounting, as follows:
+
The reason to build a kernel with an initramfs is mostly for interoperability (e.g. live-cd's) and special features like an included busybox, ssh, etc.  But mostly, and that's why we are doing this here now, to have a proper kernel up and running quick'n dirty in a reasonable time without fighting hours and days until a more or less exotic hardware is perfectly run by the kernel.
 +
After having a proper basic kernel running with the help of an initramfs, I really recommend you to go a step further and build a true kernel with all features includes without an initramfs. But this could be pain in the ass and very time consuming - so we do it the funtoo way here - at least in the second example when we stick to better-initramfs instead of Red-Hat's ''dracut''.
  
<console>
+
= Option one: Initrd with dracut =
# ##i##chmod 1777 /mnt/funtoo/tmp
+
</console>
+
  
=== Installing the Stage 3 tarball ===
+
To build the initrd we just execute
==== Stage 3 tarball ====
+
 
+
After creating filesystems, the next step is downloading the initial Stage 3 tarball. The Stage 3 is a pre-compiled system used as a starting point to install Funtoo Linux. Visit the [[Download]] page and copy the URL to the Stage 3 tarball you want to use. We will download it soon.
+
 
+
{{fancyimportant|If your system's date and time are too far off (typically by months or years,) then it may prevent Portage from properly downloading source tarballs. This is because some of our sources are downloaded via HTTPS, which use SSL certificates and are marked with an activation and expiration date.}}
+
 
+
Now is a good time to verify the date and time are correctly set to UTC. Use the <tt>date</tt> command to verify the date and time:
+
  
 
<console>
 
<console>
# ##i##date
+
# ##i##dracut -f --fstab --xz /boot/initramfs-3.2.6-pf.img  3.2.6-pf
Fri Jul 15 19:47:18 UTC 2011
+
 
</console>
 
</console>
  
If the date and/or time need to be corrected, do so using <tt>date MMDDhhmmYYYY</tt>, keeping in mind <tt>hhmm</tt> are in 24-hour format. The example below changes the date and time to "July 16th, 2011 @ 8:00PM" UTC:
+
Generally, this really should be enough!
 +
If you experience booting problems like missing modules / drivers then just boot from the genkernel section and fix the initrd building. You can look into the man page to tweak the command a bit (e.g. --add-drivers "xz dm_crypt" etc...).
  
<console>
+
Ok let's go on and finish the taks, we are going to tell now grub how to boot off correctly!
# ##i##date 071620002011
+
Fri Jul 16 20:00:00 UTC 2011
+
</console>
+
  
Once you are in your Funtoo Linux root filesystem, use <tt>wget</tt> to download the Stage 3 tarball you have chosen from the [[Download]] page to use as the basis for your new Funtoo Linux system. It should be saved to the <tt>/mnt/funtoo</tt> directory as follows:
+
<pre>
 +
root@[~src/linux] # nano /etc/boot.conf
  
<console># ##i##cd /mnt/funtoo
+
boot {
# ##i##wget http://ftp.osuosl.org/pub/funtoo/funtoo-current/x86-64bit/generic_64/stage3-latest.tar.xz
+
        generate grub
</console>
+
        default "Funtoo Linux dracut"
 +
        timeout 3
 +
}
  
 +
"Funtoo Linux genkernel" {
 +
        kernel kernel-genkernel[-v]
 +
        initrd initramfs-genkernel[-v]
 +
        params = quiet rootfstype=ext4
 +
        params += luks enc_root=/dev/sda3
 +
        params += lvm root=/dev/mapper/vg-root
 +
}
  
Note that 64-bit systems can run 32-bit or 64-bit stages, but 32-bit systems can only run 32-bit stages. Make sure that you select a Stage 3 build that is appropriate for your CPU. If you are not certain, it is a safe bet to choose the <tt>generic_64</tt> or <tt>generic_32</tt> stage. Consult the [[Download]] page for more information.
+
"Funtoo Linux dracut" {
 +
        kernel vmlinuz[-v]
 +
## this is the better-initramfs generated initrd
 +
        initrd initramfs[-v].img
 +
        params  = quiet rootfstype=ext4
 +
        params += luks enc_root=/dev/sda3
 +
        params += lvm root=/dev/mapper/vg-root
 +
}
  
Once the stage is downloaded, extract the contents with the following command, substituting in the actual name of your stage 3 tarball:
 
<console>
 
# ##i##tar xJpf stage3-latest.tar.xz
 
</console>
 
 
{{fancyimportant|It is very important to use <tt>tar</tt>'s "<tt>p</tt>" option when extracting the Stage 3 tarball - it tells <tt>tar</tt> to ''preserve'' any permissions and ownership that exist within the archive. Without this option, your Funtoo Linux filesystem permissions will be incorrect.}}
 
 
=== Chroot into Funtoo ===
 
Before chrooting into your new system, there's a few things that need to be done first. You will need to mount /proc and /dev inside your new system. Use the following commands:
 
<console>
 
# ##i##cd /mnt/funtoo
 
# ##i##mount -t proc none proc
 
# ##i##mount --rbind /sys sys
 
# ##i##mount --rbind /dev dev
 
</console>
 
 
You'll also want to copy over <tt>resolv.conf</tt> in order to have proper DNS name resolution from inside the chroot:
 
<console>
 
# ##i##cp /etc/resolv.conf etc
 
</console>
 
 
Now you can chroot into your new system. Use <tt>env</tt> before <tt>chroot</tt> to ensure that no environment variables from the installation media are used by your new system:
 
 
<console>
 
# ##i##env -i HOME=/root TERM=$TERM chroot . bash -l
 
</console>
 
 
{{fancynote|Users of live CDs with 64-bit kernels: Some software may use <tt>uname -r</tt> to check whether the system is 32 or 64-bit. You may want append linux32 to the chroot command as a workaround, but it's generally not needed.}}
 
{{fancyimportant|If you receive the error "<tt>chroot: failed to run command `/bin/bash': Exec format error</tt>", it is probably because you are running a 32-bit kernel and trying to execute 64-bit code. SystemRescueCd boots with a 32-bit kernel by default.}}
 
 
It's also a good idea to change the default command prompt while inside the chroot. This will avoid confusion if you have to change terminals. Use this command:
 
<console>
 
# ##i##export PS1="(chroot) $PS1"
 
</console>
 
 
Congratulations! You are now chrooted inside a Funtoo Linux system. Now it's time to get Funtoo Linux properly configured so that Funtoo Linux will boot successfully when your system is restarted.
 
 
=== Downloading the Portage tree ===
 
 
{{fancynote|For an alternative way to do this, see [[Installing Portage From Snapshot]].}}
 
Now it's time to install a copy of the Portage repository, which contains package scripts (ebuilds) that tell portage how to build and install thousands of different software packages. To create the Portage repository, simply run <tt>emerge --sync</tt> from within the chroot. This will automatically clone the portage tree from [http://github.com/ GitHub]:
 
 
<console>
 
(chroot) # ##i##emerge --sync
 
</console>
 
 
{{fancyimportant|If you receive the error with initial <tt>emerge --sync</tt> due to git protocol restrictions, change <tt>SYNC</tt> variable in <tt>/etc/portage/make.conf</tt>}}
 
<pre>
 
SYNC="https://github.com/funtoo/ports-2012.git"
 
 
</pre>
 
</pre>
  
 +
That's it almost!
  
=== Configuring your system ===
+
Now write to the grub.cfg with the new handy boot-update script from funtoo:
As is expected from a Linux distribution, Funtoo Linux has its share of configuration files. The one file you are absolutely required to edit in order to ensure that Funtoo Linux boots successfully is <tt>/etc/fstab</tt>. The others are optional. Here are a list of files that you should consider editing:
+
 
+
{| {{table}}
+
!File
+
!Do I need to change it?
+
!Description
+
|-
+
|<tt>/etc/fstab</tt>
+
|'''YES - required'''
+
|Mount points for all filesystems to be used at boot time. This file must reflect your disk partition setup. We'll guide you through modifying this file below.
+
|-
+
|<tt>/etc/localtime</tt>
+
|''Maybe - recommended''
+
|Your timezone, which will default to UTC if not set. This should be a symbolic link to something located under /usr/share/zoneinfo (e.g. /usr/share/zoneinfo/America/Montreal)
+
|-
+
|<tt>/etc/make.conf<br/>/etc/portage/make.conf&nbsp;(new&nbsp;location)</tt>
+
|''Maybe - recommended''
+
|Parameters used by gcc (compiler), portage, and make. It's a good idea to set MAKEOPTS. This is covered later in this document.
+
|-
+
|<tt>/etc/conf.d/hostname</tt>
+
|''Maybe - recommended''
+
|Used to set system hostname. Set to the fully-qualified (with dots) name. Defaults to <tt>localhost</tt> if not set.
+
|-
+
|<tt>/etc/hosts</tt>
+
|''No''
+
| You no longer need to manually set the hostname in this file. This file is automatically generated by <tt>/etc/init.d/hostname</tt>.
+
|-
+
|<tt>/etc/conf.d/keymaps</tt>
+
|Optional
+
|Keyboard mapping configuration file (for console pseudo-terminals). Set if you have a non-US keyboard. See [[Funtoo Linux Localization]].
+
|-
+
|<tt>/etc/conf.d/hwclock</tt>
+
|Optional
+
|How the time of the battery-backed hardware clock of the system is interpreted (UTC or local time). Linux uses the battery-backed hardware clock to initialize the system clock when the system is booted.
+
|-
+
|<tt>/etc/conf.d/modules</tt>
+
|Optional
+
|Kernel modules to load automatically at system startup. Typically not required. See [[Additional Kernel Resources]] for more info.
+
|-
+
|<tt>profiles</tt>
+
|Optional
+
|Some useful portage settings that may help speed up intial configuration.
+
|}
+
 
+
If you're installing an English version of Funtoo Linux, you're in luck as most of the configuration files can be used as-is. If you're installing for another locale, don't worry. We will walk you through the necessary configuration steps on the [[Funtoo Linux Localization]] page, and if needed, there's always plenty of friendly, helpful support. (See [[#Community portal|Community]])
+
 
+
Let's go ahead and see what we have to do. Use <tt>nano -w <name_of_file></tt> to edit files -- the "<tt>-w</tt>" disables word-wrapping, which is handy when editing configuration files. You can copy and paste from the examples.
+
 
+
{{fancywarning|It's important to edit your <tt>/etc/fstab</tt> file before you reboot! You will need to modify both the "fs" and "type" columns to match the settings for your partitions and filesystems that you created with <tt>gdisk</tt> or <tt>fdisk</tt>. Skipping this step may prevent Funtoo Linux from booting successfully.}}
+
 
+
==== /etc/fstab ====
+
 
+
<tt>/etc/fstab</tt> is used by the <tt>mount</tt> command which is ran when your system boots. Statements of this file inform <tt>mount</tt> about partitions to be mounted and how they are mounted. In order for the system to boot properly, you must edit <tt>/etc/fstab</tt> and ensure that it reflects the partition configuration you used earlier:
+
 
+
 
<console>
 
<console>
(chroot) # ##i##nano -w /etc/fstab
+
root@[~src/linux] # boot-update -v
 
</console>
 
</console>
 
You can use arrow keys to move around and hit Control-X to exit. If you want to save your changes, type "<tt>Y</tt>" when asked if you want to save the modified buffer, or hit Control-O before closing <tt>nano</tt>. Otherwise your changes will be discarded.
 
 
 
<pre>
 
<pre>
# The root filesystem should have a pass number of either 0 or 1.
+
root@[~src/linux] # sudo boot-update -v
# All other filesystems should have a pass number of 0 or greater than 1.
+
#
+
# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
+
#
+
# See the manpage fstab(5) for more information.
+
#
+
# <fs>     <mountpoint>  <type>  <opts>        <dump/pass>
+
  
/dev/sda1    /boot         ext2    noatime        1 2
+
boot-update 1.5.2 / Copyright 2009-2011 Funtoo Technologies
/dev/sda3    none          swap    sw            0 0
+
/dev/sda4    /            ext4    noatime        0 1
+
#/dev/cdrom  /mnt/cdrom    auto    noauto,ro      0 0
+
</pre>
+
  
==== /etc/localtime ====
+
[use option "-l" for license info, "-h" for help]
  
<tt>/etc/localtime</tt> is used to specify the timezone that your machine is in, and defaults to UTC. If you would like your Funtoo Linux system to use local time, you should replace <tt>/etc/localtime</tt> with a symbolic link to the timezone that you wish to use.  
+
* Generating config for grub...
  
<console>
+
DEFAULT > Funtoo Linux - vmlinuz-3.2.6-pf
(chroot) # ##i##ln -sf /usr/share/zoneinfo/America/Montreal /etc/localtime
+
          Funtoo Linux genkernel - kernel-genkernel-x86_64-3.2.6-pf
</console>
+
  
The above sets the timezone to Eastern Time Canada. Go to <tt>/usr/share/zoneinfo</tt> to see which values to use.
+
* Completed successfully.
 
+
==== /etc/make.conf ====
+
 
+
{{fancynote|This file is the symlink to /etc/portage/make.conf, new default location, edit /etc/portage/make.conf.}}
+
 
+
MAKEOPTS can be used to define how many parallel compilations should occur when you compile a package, which can speed up compilation significantly. A rule of thumb is the number of CPUs (or CPU threads) in your system plus one. If for example you have a dual core processor without [[wikipedia:Hyper-threading|hyper-threading]], then you would set MAKEOPTS to 3:
+
 
+
<pre>
+
MAKEOPTS="-j3"
+
 
</pre>
 
</pre>
  
If you are unsure about how many processors/threads you have then use /proc/cpuinfo to help you.
+
Okay,... here you go..! :)
<console>
+
(chroot) # ##i##grep "processor" /proc/cpuinfo | wc -l
+
16
+
</console>
+
  
Set MAKEOPTS to this number plus one:
+
Reboot and see how it works!
 
+
<pre>
+
MAKEOPTS="-j17"
+
</pre>
+
  
USE flags define what functionality is enabled when packages are built. It is not recommended to add a lot of them during installation; you should wait until you have a working, bootable system before changing your USE flags. A USE flag prefixed with a minus ("<tt>-</tt>") sign tells Portage not to use the flag when compiling.  A Funtoo guide to USE flags will be available in the future. For now, you can find out more information about USE flags in the [http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml?part=2&chap=2 Gentoo Handbook].
+
= Option two: using better-initramfs =
  
LINGUAS tells Portage which local language to compile the system and applications in (those who use LINGUAS variable like OpenOffice). It is not usually necessary to set this if you use English. If you want another language such as French (fr) or German (de), set LINGUAS appropriately:
+
Piotr's better-initramfs is another approach that is tiny, nice and shiny and seems to become more and more a favourite among funtoo'ers. The biggest plus is that, once built it is kernel version independant.
  
 +
For using this you just do the following steps:
 
<pre>
 
<pre>
LINGUAS="fr"
+
1. download sources
 +
2. build kernel with "make bzImage"
 +
3. download better-initramfs
 +
4. run better-initramfs
 +
5. adjust /etc/boot.conf
 
</pre>
 
</pre>
  
==== /etc/conf.d/hwclock ====
+
Here is how in detail:
If you dual-boot with Windows, you'll need to edit this file and change '''clock''' to '''local''', because Windows will set your hardware clock to local time every time you boot Windows. Otherwise you normally wouldn't need to edit this file.
+
<console>
+
(chroot) # ##i##nano -w /etc/conf.d/hwclock
+
</console>
+
  
==== Localization ====
+
Assuming you did install already a genkernel backup or at least you have a working bzImage + modules installed, we rush forward to step 3:
  
By default, Funtoo Linux is configured with Unicode (UTF-8) enabled, and for the US English locale and keyboard. If you would like to configure your system to use a non-English locale or keyboard, see [[Funtoo Linux Localization]].
+
=== download better-initramfs ===
 
+
==== Profiles ====
+
 
+
[[Funtoo 1.0 Profile|Funtoo profiles]] are used to define defaults for Portage specific to your needs. There are 4 basic profile types: arch, build, [[Flavors and Mix-ins|flavor, and mix-ins]]:
+
 
+
;arch: typically <tt>x86-32bit</tt> or <tt>x86-64bit</tt>, this defines the processor type and support of your system. This is defined when your stage was built and should not be changed.
+
;build: defines whether your system is a <tt>current</tt>, <tt>stable</tt> or <tt>experimental</tt> build. <tt>current</tt> systems will have newer packages unmasked than <tt>stable</tt> systems.
+
;flavor: defines the general type of system, such as <tt>server</tt> or <tt>desktop</tt>, and will set default USE flags appropriate for your needs.
+
;mix-ins: define various optional settings that you may be interested in enabling.
+
 
+
One arch, build and flavor must be set for each Funtoo Linux system, while mix-ins are optional and you can enable more than one if desired.
+
 
+
Remember that profiles can often be inherited. For example, the <tt>desktop</tt> flavor inherits the <tt>workstation</tt> flavor settings, which in turn inherits the <tt>X</tt> and <tt>audio</tt> mix-ins. You can view this by using eselect:
+
  
 
<console>
 
<console>
(chroot) # ##i##eselect profile show
+
# cd /usr/src/;
Currently set profiles:
+
➜ # git clone https://github.com/slashbeast/better-initramfs.git
    arch: gentoo:funtoo/1.0/linux-gnu/arch/x86-64bit
+
  build: gentoo:funtoo/1.0/linux-gnu/build/current
+
  flavor: gentoo:funtoo/1.0/linux-gnu/flavor/desktop
+
mix-ins: gentoo:funtoo/1.0/linux-gnu/mix-ins/kde
+
 
+
Automatically enabled profiles:
+
mix-ins: gentoo:funtoo/1.0/linux-gnu/mix-ins/print
+
mix-ins: gentoo:funtoo/1.0/linux-gnu/mix-ins/X
+
mix-ins: gentoo:funtoo/1.0/linux-gnu/mix-ins/audio
+
mix-ins: gentoo:funtoo/1.0/linux-gnu/mix-ins/dvd
+
mix-ins: gentoo:funtoo/1.0/linux-gnu/mix-ins/media
+
mix-ins: gentoo:funtoo/1.0/linux-gnu/mix-ins/console-extras
+
 
+
  
 +
➜ # /src #  cd better-initramfs
 +
➜ # better-initramfs git:(master) ls
 +
AUTHORS    LICENSE  README.rst  bootstrap  output  sourceroot
 +
ChangeLog  Makefile  TODO        examples  scripts
 
</console>
 
</console>
  
To view installed profiles:
+
=== build the better-initramfs ===
<console>
+
(chroot) # ##i##eselect profile list
+
</console>
+
 
+
To change the profile flavor:
+
<console>
+
(chroot) # ##i##eselect profile set-flavor 7
+
</console>
+
 
+
To add a mix-in:
+
 
+
<console>
+
(chroot) # ##i##eselect profile add 10
+
</console>
+
 
+
=== Configuring and installing the Linux kernel ===
+
 
+
Now it's time to build and install a Linux kernel, which is the heart of any Funtoo Linux system. In the past, the process of creating a kernel that actually booted your system could be time-consuming and require a great deal of trial and error. Fortunately, Funtoo Linux offers an option to automatically build a kernel for you that will boot nearly all systems.
+
 
+
If you are unfamiliar with how to manually configure your own kernel, or you simply want to get your system up and running quickly, you can emerge <tt>debian-sources</tt> with the <tt>binary</tt> USE flag set, which will automatically build the kernel and an initrd that will boot nearly all Funtoo Linux systems. This kernel is based on a linux-3.2 LTS official debian kernel package and is an easy way to get your system up and running relatively quickly.
+
 
+
Click [http://wiki.debian.org/DebianKernel here] for a list of all architectures the Debian kernel supports.
+
 
+
{{fancyimportant|<tt>debian-sources</tt> with <tt>binary</tt> USE flag requires at least 12GB in /var/tmp}}
+
 
+
<console>
+
(chroot) # ##i##cat /proc/mounts > /etc/mtab
+
(chroot) # ##i##echo "sys-kernel/debian-sources binary" >> /etc/portage/package.use
+
(chroot) # ##i##emerge debian-sources</console>
+
 
+
All done!
+
 
+
{{fancynote|NVIDIA card users: the <tt>binary</tt> USE flag installs the Nouveau drivers which cannot be loaded at the same time as the proprietary drivers, and cannot be unloaded at runtime because of KMS. You need to blacklist it under <tt>/etc/modprobe.d/</tt>.}}
+
{{fancynote|For an overview of other kernel options for Funtoo Linux, see [[Funtoo Linux Kernels]]. There maybe modules that the Debian kernel doesn't include, a situation where [http://www.funtoo.org/wiki/Funtoo_Linux_Kernels#Using_Debian-Sources_with_Genkernel genkernel] would be useful. Also be sure to see [[:Category:Hardware Compatibility|hardware compatibility]] information. We have compiled a very good reference for [[Dell PowerEdge 11G Servers]] that includes kernel compatibility information as well..}}
+
 
+
 
+
The next step is to configure your boot loader so that your new kernel loads when the system boots.
+
 
+
=== Installing a Bootloader ===
+
 
+
==== Installing Grub ====
+
 
+
The boot loader is responsible for loading the kernel from disk when your computer boots. For new installations, GRUB 2 and Funtoo's boot-update tool should be used as a boot loader. GRUB supports both GPT/GUID and legacy MBR partitioning schemes.
+
 
+
To use this recommended boot method, first emerge <tt>boot-update</tt>. This will also cause <tt>grub-2</tt> to be merged, since it is a dependency of <tt>boot-update</tt>.
+
 
+
 
<console>
 
<console>
(chroot) # ##i##emerge boot-update
+
➜ # better-initramfs git:(master) sudo bootstrap/bootstrap-all
 +
Passwort: xxx
 +
# from here go and grab a coffee
 +
# sudo make prepare
 +
# sudo make image
 +
# sudo mv output/initramfs.cpio.gz /boot
 
</console>
 
</console>
  
Then, edit <tt>/etc/boot.conf</tt> and specify "<tt>Funtoo Linux genkernel</tt>" as the <tt>default</tt> setting at the top of the file, replacing <tt>"Funtoo Linux"</tt>.
+
=== adjust grub ===
  
<tt>/etc/boot.conf</tt> should now look like this:
+
Taking the above setup we edit the /etc/boot.conf
 +
as I installed genkernel first, and dracut after - you see this setup:
  
 
<pre>
 
<pre>
 
boot {
 
boot {
 
         generate grub
 
         generate grub
         default "Funtoo Linux genkernel"
+
         default "Funtoo Linux"
         timeout 3  
+
         timeout 3
 
}
 
}
 +
 +
# Rootfs over lvm over luks
 +
# /dev/sda3 - encrypted lvm's pv
 +
# /dev/mapper/vg-root - rootfs's lv
  
 
"Funtoo Linux" {
 
"Funtoo Linux" {
 
         kernel bzImage[-v]
 
         kernel bzImage[-v]
        # params += nomodeset
+
## this is the better-initramfs generated initrd
 +
        initrd initramfs.cpio.gz
 +
        params  = quiet rootfstype=ext4
 +
        params += luks enc_root=/dev/sda3
 +
        params += lvm root=/dev/mapper/vg-root
 
}
 
}
 +
 +
"Funtoo Linux dracut" {
 +
        kernel vmlinuz[-v]
 +
## this is the dracut generated initrd
 +
        initrd initramfs[-v].img
 +
        params  = quiet rootfstype=ext4
 +
        params += luks enc_root=/dev/sda3
 +
        params += lvm root=/dev/mapper/vg-root
 +
}
 +
  
 
"Funtoo Linux genkernel" {
 
"Funtoo Linux genkernel" {
         kernel kernel[-v]
+
         kernel kernel-genkernel[-v]
         initrd initramfs[-v]
+
         initrd initramfs-genkernel[-v]
         params += real_root=auto
+
        params = quiet rootfstype=ext4
         # params += nomodeset
+
         params += luks enc_root=/dev/sda3
}  
+
         params += lvm root=/dev/mapper/vg-root
 +
}
 
</pre>
 
</pre>
+
Okay,... here you go..! :)
Please read <tt>man boot.conf</tt> for further details.
+
  
===== Running grub-install and boot-update =====
+
update the grub.cfg, then reboot and see how it works!
 
+
Finally, we will need to actually install the GRUB boot loader to your disk, and also run <tt>boot-update</tt> which will generate your boot loader configuration file:
+
  
 
<console>
 
<console>
(chroot) # ##i##grub-install --no-floppy /dev/sda
+
root@[~src/linux-3.2.6-pf] # boot-update -v   
(chroot) # ##i##boot-update
+
</console>
+
  
You only need to run <tt>grub-install</tt> when you first install Funtoo Linux, but you need to re-run <tt>boot-update</tt> every time you modify your <tt>/etc/boot.conf</tt> file, so your changes are applied on next boot.
+
boot-update 1.5.2 / Copyright 2009-2011 Funtoo Technologies
  
OK - your system should be ready to boot! Well, there are a few more loose ends...
+
[use option "-l" for license info, "-h" for help]
  
==== Installing Syslinux/Extlinux ====
+
* Generating config for grub...
  
An alternate Bootloader is Extlinux, for installing it see the [[Extlinux|extlinux Guide]].
+
DEFAULT > Funtoo Linux better-initramfs - vmlinuz-3.2.6-pf
 +
          Funtoo Linux dracut - vmlinuz-3.2.6-pf
 +
          Funtoo Linux genkernel - kernel-genkernel-x86_64-3.2.6-ck
  
=== Configuring your network ===
+
* Completed successfully.
  
It's important to ensure that you will be able to connect to your local-area network after you reboot into Funtoo Linux. There are three approaches you can use for configuring your network: NetworkManager, dhcpcd, and the [[Funtoo Linux Networking]] scripts. Here's how to choose which one to use based on the type of network you want to set up.
+
root@[~src/linux-3.2.6-pf] #
  
==== Wi-Fi ====
+
root@[~src/linux-3.2.6-pf] # reboot
  
For laptop/mobile systems where you will be using Wi-Fi and connecting to various networks, NetworkManager is strongly recommended. The Funtoo version of NetworkManager is fully functional even from the command-line, so you can use it even without X or without the Network Manager applet. Here are the steps involved in setting up NetworkManager:
+
System going down for reboot!
  
<console>
 
# ##i##emerge linux-firmware
 
# ##i##emerge networkmanager
 
# ##i##rc-update add NetworkManager default
 
 
</console>
 
</console>
  
Above, we installed linux-firmware which contains a complete collection of available firmware for many hardware devices including Wi-Fi adapters, plus NetworkManager to manage our network connection. Then we added NetworkManager to the <tt>default</tt> runlevel so it will start when Funtoo Linux boots.
 
 
After you reboot into Funtoo Linux, you will be able to add a Wi-Fi connection this way:
 
 
<console>
 
# ##i##addwifi -S wpa -K 'wifipassword' mywifinetwork
 
</console>
 
 
The <tt>addwifi</tt> command is used to configure and connect to a WPA/WPA2 Wi-Fi network named <tt>mywifinetwork</tt> with the password <tt>wifipassword</tt>. This network configuration entry is stored in <tt>/etc/NetworkManager/system-connections</tt> so that it will be remembered in the future. You should only need to enter this command once for each Wi-Fi network you connect to.
 
 
==== Desktop (Wired Ethernet) ====
 
 
For a home desktop or workstation with wired Ethernet that will use DHCP, the simplest and most effective option to enable network connectivity is to simply add <tt>dhcpcd</tt> to the default runlevel:
 
 
<console>
 
# ##i##rc-update add dhcpcd default
 
</console>
 
 
When you reboot, <tt>dhcpcd</tt> will run in the background and manage all network interfaces and use DHCP to acquire network addresses from a DHCP server.
 
 
==== Server (Static IP) ====
 
 
For servers, the [[Funtoo Linux Networking]] scripts are recommended. They are optimized for static configurations and things like virtual ethernet bridging for virtualization setups. See [[Funtoo Linux Networking]] for information on how to use Funtoo Linux's template-based network configuration system.
 
 
=== Finishing Steps ===
 
 
==== Set your root password ====
 
It's imperative that you set your root password before rebooting so that you can log in.
 
<console>
 
(chroot) # ##i##passwd
 
</console>
 
 
===Restart your system ===
 
 
Now is the time to leave chroot, to unmount Funtoo Linux partitions and files and to restart your computer. When you restart, the GRUB boot loader will start, load the Linux kernel and initramfs, and your system will begin booting.
 
 
Leave the chroot, change directory to /, unmount your Funtoo partitions, and reboot.
 
<console>
 
(chroot) # ##i##exit
 
# ##i##cd /
 
# ##i##umount -l /mnt/funtoo/boot /mnt/funtoo/dev /mnt/funtoo/proc /mnt/funtoo/sys /mnt/funtoo
 
# ##i##reboot
 
</console>
 
 
You should now see your system reboot, the GRUB boot loader appear for a few seconds, and then see the Linux kernel and initramfs loading. After this, you should see Funtoo Linux itself start to boot, and you should be greeted with a <tt>login:</tt> prompt. Funtoo Linux has been successfully installed!
 
 
===Next Steps===
 
 
If you are brand new to Funtoo Linux and Gentoo Linux, please check out [[Funtoo Linux First Steps]], which will help get you acquainted with your new system.
 
 
We also have a number of pages dedicated to setting up your system, which you can find below. If you are interested in adding a page to this list, add it to the "First Steps" MediaWiki category.
 
 
{{#ask: [[Category:First Steps]] | format=category }}
 
 
If your system did not boot correctly, see [[Installation Troubleshooting]] for steps you can take to resolve the problem.
 
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
[[Category:Install]]
+
[[Category:Featured]]
 +
[[Category:Kernel]]

Revision as of 15:14, 9 January 2014

Setting up a proper kernel yourself - lean, mean and tailored to your hardware, is the challenge by which a linux user can graduate to becoming a Funtoo knight ;-)

Even though many of us are using enterprise-ready kernels in datacenters, there is almost nobody who hasn't at least considered building a kernel for his laptop / PC. We are showing here how an intermediate Linux user can use an alternative to the standard beginners "genkernel" approach, to compile a custom kernel, in a relatively still speedy and easy set up.

Contents

Minimum Requirements

You should understand the way how things work in a terminal and how to use an editor and tweak config files. This is crucial. You don't need much knowledge about the linux kernel and it's internals. Nevertheless, you have to know at least where the files are located, how they are used and what is the file logic behind the overall structure. Otherwise you should consider using a non source based linux distribution. If you are scared now, don't worry - we are going to build a kernel the Funtoo way and you will pick up everthing necessary to accomplish this challenge, step by step, so the next time you do it yourself and become a real Funtoo knight!

Assumptions

You start from an installed Funtoo system on the disk, or at least, you are on stage3 in a chrooted environment from a live cd, following somehow the Funto Installation Tutorial.

In this case we are building a kernel that is booting root in LVM over encrypted LUKS container. If you don't have this setup, don't worry, you just don't need all the modules, but everything else is similar.


Getting everything in order to start

First there is the decision which linux kernel sources we need. There are plenty of them in the repositories around, often it is not easy to distinguish between them.

I would always trust my distribution of choice and take what is has to offer - and funtoo has a lot to offer!

I really do recommend (especially if it is your first time) to build a debian-sourced genkernel like described in chapter 5 "Using Debian-Sources with Genkernel" in the Funtoo Kernels Tutorial.

From there you should have a running system booting nicely from your own build (just little bit bloated) kernel. This is more than you can expect from any other ready to go distribution.

Attention We are using RedHat's dracut in order to build a nice initramfs (containing all the necessary tools and extra drivers our kernel might need to start the system).

Although dracut is the way to go, more sophisticated and not as buggy as gentoo's genkernel approach, more and more funtoo geeks start using slashbeast's better-initramfs, which we will cover at the end of this howto!

So after having set up a genkernel from debian or gentoo sources we are going to build a kernel with either (or both) dracut or/and better-initramfs. So gentoo sources with genkernel is always my backup if anything is not working correctly on my system. For the slightly more geeky approach with my own initram I am using pf-sources, ck-sources or any other more or less heavily patched sources.

Let's go!

Kernel Sources

We are going to use the kernel sources from the funtoo git repository.

The source you use on your system is up to you and your needs. For a laptop or desktop system, we recommend the following:

  • sys-kernel/pf-sources
  • sys-kernel/ck-sources
  • sys-kernel/gentoo-sources
  • sys-kernel/git-sources
  • sys-kernel/sysrescue-std-sources
  • sys-kernel/debian-sources

Please, have a look in the ebuild description, look onto their homepage and take the one that suits you best! If you are unsure for now, use sys-kernel/gentoo-sources. That's always a safe bet for a general system.

It is not a problem to have various kernels installed parallel, so go on with any one of them.

I am going to use the sys-kernel/pf-sources now, as I already had the gentoo-sources installed.

Prerequisites

I don't know which tools you have already installed, so some information here might be redundant. It doesn't harm to just copy and paste and do some steps again.

First, we look into our /etc/make.conf:

# nano /etc/make.conf
#These compiler flags are just tweaking (optimazation) and NOT necessary:
CFLAGS="-O2 -pipe -march=native -ftracer -fforce-addr"
CXXFLAGS="${CFLAGS} -fpermissive -fomit-frame-pointer"
KDIR=/usr/src/linux
KERNEL="symlink build"
USE="$KERNEL ....here are your use flags...."
## These modules are available:
## DRACUT_MODULES="dracut_modules_biosdevname dracut_modules_btrfs dracut_modules_caps dracut_modules_crypt dracut_modules_crypt-gpg dracut_modules_dmraid dracut_modules_dmsquash-live dracut_modules_gensplash dracut_modules_iscsi dracut_modules_livenet dracut_modules_lvm dracut_modules_mdraid dracut_modules_multipath dracut_modules_nbd dracut_modules_nfs dracut_modules_plymouth dracut_modules_ssh-client dracut_modules_syslog"
## We will use these modules for LVM / LUKS:
DRACUT_MODULES="crypt lvm plymouth biosdevname dmraid crypt-gpg dmsquash-live ssh-client syslog"

Next, we set the package keywords:

/etc/portage/package.use/dracut:
sys-kernel/dracut dm net device-mapper crypt lvm

Note Note: If you don't have lvm over encrypted LUKS you probably just add the "net" keyword here, or "selinux".


After that we are going to build our packages:

# emerge -av app-portage/gentoolkit sys-kernel/pf-sources sys-kernel/dracut sys-boot/plymouth sys-boot/plymouth-openrc-plugin

Finished? Well, then let's go on and

Preparing the kernel

We go now to the sources directory and enter the following commands to update the kernel's .config file:

# cd /usr/src/linux/
# make clean
  CLEAN   .
  CLEAN   arch/x86/kernel/acpi/realmode
  CLEAN   arch/x86/kernel/cpu
  CLEAN   arch/x86/kernel
  CLEAN   arch/x86/vdso
  CLEAN   arch/x86/lib
  CLEAN   drivers/gpu/drm/radeon
  CLEAN   drivers/net/wan
  CLEAN   drivers/scsi/aic7xxx
  CLEAN   drivers/tty/vt
  CLEAN   drivers/video/logo
  CLEAN   firmware
  CLEAN   kernel
  CLEAN   lib/raid6
  CLEAN   lib
  CLEAN   security/apparmor
  CLEAN   security/selinux
  CLEAN   usr
  CLEAN   arch/x86/boot/compressed
  CLEAN   arch/x86/boot
  CLEAN   .tmp_versions
  CLEAN   vmlinux System.map .tmp_kallsyms2.S .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms1.S .tmp_vmlinux1 .tmp_vmlinux2 .tmp_System.map
# zcat /proc/config.gz > /usr/src/linux/.config
# make localmodconfig

You will get some questions which you can answer mostly with either M (compiled as a module) or Y (compiled directly into the kernel).

Enable different security models (SECURITY) [Y/n/?] y
Enable the securityfs filesystem (SECURITYFS) [Y/?] y
Socket and Networking Security Hooks (SECURITY_NETWORK) [Y/?] y
Security hooks for pathname based access control (SECURITY_PATH) [Y/?] y
Low address space for LSM to protect from user allocation (LSM_MMAP_MIN_ADDR) [65536] 65536
NSA SELinux Support (SECURITY_SELINUX) [Y/n/?] y
  NSA SELinux boot parameter (SECURITY_SELINUX_BOOTPARAM) [N/y/?] n
  NSA SELinux runtime disable (SECURITY_SELINUX_DISABLE) [N/y/?] n
  NSA SELinux Development Support (SECURITY_SELINUX_DEVELOP) [Y/n/?] y
  NSA SELinux AVC Statistics (SECURITY_SELINUX_AVC_STATS) [Y/n/?] y
  NSA SELinux checkreqprot default value (SECURITY_SELINUX_CHECKREQPROT_VALUE) [1] 1
  NSA SELinux maximum supported policy format version (SECURITY_SELINUX_POLICYDB_VERSION_MAX) [Y/n/?] y
    NSA SELinux maximum supported policy format version value (SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE) [19] 19
TOMOYO Linux Support (SECURITY_TOMOYO) [Y/n/?] y
  Default maximal count for learning mode (SECURITY_TOMOYO_MAX_ACCEPT_ENTRY) [2048] 2048
  Default maximal count for audit log (SECURITY_TOMOYO_MAX_AUDIT_LOG) [1024] 1024
  Activate without calling userspace policy loader. (SECURITY_TOMOYO_OMIT_USERSPACE_LOADER) [Y/n/?] y
AppArmor support (SECURITY_APPARMOR) [Y/n/?] y
  AppArmor boot parameter default value (SECURITY_APPARMOR_BOOTPARAM_VALUE) [1] 1
Integrity Measurement Architecture(IMA) (IMA) [Y/n/?] y
EVM support (EVM) [N/y/?] (NEW)
Default security module
  1. SELinux (DEFAULT_SECURITY_SELINUX)
  2. TOMOYO (DEFAULT_SECURITY_TOMOYO)
  3. AppArmor (DEFAULT_SECURITY_APPARMOR)
> 4. Unix Discretionary Access Controls (DEFAULT_SECURITY_DAC)
choice[1-4?]: 4
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
#
# configuration written to .config
#
warning: (GFS2_FS) selects DLM which has unmet direct dependencies (EXPERIMENTAL && INET && SYSFS && CONFIGFS_FS && (IPV6 || IPV6=n))
warning: (IMA) selects TCG_TPM which has unmet direct dependencies (HAS_IOMEM && EXPERIMENTAL)
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
root@[~src/linux] #

Now comes the most adventurous part!

Building the Kernel

# make -j8  bzImage
# make -j8 modules
# make modules_install
# make install


Building an initramfs or not?

The reason to build a kernel with an initramfs is mostly for interoperability (e.g. live-cd's) and special features like an included busybox, ssh, etc. But mostly, and that's why we are doing this here now, to have a proper kernel up and running quick'n dirty in a reasonable time without fighting hours and days until a more or less exotic hardware is perfectly run by the kernel. After having a proper basic kernel running with the help of an initramfs, I really recommend you to go a step further and build a true kernel with all features includes without an initramfs. But this could be pain in the ass and very time consuming - so we do it the funtoo way here - at least in the second example when we stick to better-initramfs instead of Red-Hat's dracut.

Option one: Initrd with dracut

To build the initrd we just execute

# dracut -f --fstab --xz /boot/initramfs-3.2.6-pf.img  3.2.6-pf

Generally, this really should be enough! If you experience booting problems like missing modules / drivers then just boot from the genkernel section and fix the initrd building. You can look into the man page to tweak the command a bit (e.g. --add-drivers "xz dm_crypt" etc...).

Ok let's go on and finish the taks, we are going to tell now grub how to boot off correctly!

root@[~src/linux] # nano /etc/boot.conf

boot {
        generate grub
        default "Funtoo Linux dracut"
        timeout 3
}

"Funtoo Linux genkernel" {
        kernel kernel-genkernel[-v]
        initrd initramfs-genkernel[-v]
        params = quiet rootfstype=ext4
        params += luks enc_root=/dev/sda3
        params += lvm root=/dev/mapper/vg-root
}

"Funtoo Linux dracut" {
        kernel vmlinuz[-v]
## this is the better-initramfs generated initrd
        initrd initramfs[-v].img
        params  = quiet rootfstype=ext4
        params += luks enc_root=/dev/sda3
        params += lvm root=/dev/mapper/vg-root
}

That's it almost!

Now write to the grub.cfg with the new handy boot-update script from funtoo:

root@[~src/linux] # boot-update -v
root@[~src/linux] # sudo boot-update -v

 boot-update 1.5.2 / Copyright 2009-2011 Funtoo Technologies

 [use option "-l" for license info, "-h" for help]

 * Generating config for grub...

 DEFAULT > Funtoo Linux - vmlinuz-3.2.6-pf
           Funtoo Linux genkernel - kernel-genkernel-x86_64-3.2.6-pf

 * Completed successfully.

Okay,... here you go..! :)

Reboot and see how it works!

Option two: using better-initramfs

Piotr's better-initramfs is another approach that is tiny, nice and shiny and seems to become more and more a favourite among funtoo'ers. The biggest plus is that, once built it is kernel version independant.

For using this you just do the following steps:

1. download sources
2. build kernel with "make bzImage"
3. download better-initramfs
4. run better-initramfs
5. adjust /etc/boot.conf

Here is how in detail:

Assuming you did install already a genkernel backup or at least you have a working bzImage + modules installed, we rush forward to step 3:

download better-initramfs

➜ # cd /usr/src/;
➜ # git clone https://github.com/slashbeast/better-initramfs.git

➜ # /src #  cd better-initramfs
➜ # better-initramfs git:(master) ls
AUTHORS    LICENSE   README.rst  bootstrap  output   sourceroot
ChangeLog  Makefile  TODO        examples   scripts

build the better-initramfs

➜ # better-initramfs git:(master) sudo bootstrap/bootstrap-all
Passwort: xxx 
# from here go and grab a coffee
➜ # sudo make prepare
➜ # sudo make image
➜ # sudo mv output/initramfs.cpio.gz /boot

adjust grub

Taking the above setup we edit the /etc/boot.conf as I installed genkernel first, and dracut after - you see this setup:

boot {
        generate grub
        default "Funtoo Linux"
        timeout 3
}

# Rootfs over lvm over luks
# /dev/sda3 - encrypted lvm's pv
# /dev/mapper/vg-root - rootfs's lv

"Funtoo Linux" {
        kernel bzImage[-v]
## this is the better-initramfs generated initrd
        initrd initramfs.cpio.gz
        params  = quiet rootfstype=ext4
        params += luks enc_root=/dev/sda3
        params += lvm root=/dev/mapper/vg-root
}

"Funtoo Linux dracut" {
        kernel vmlinuz[-v]
## this is the dracut generated initrd
        initrd initramfs[-v].img
        params  = quiet rootfstype=ext4
        params += luks enc_root=/dev/sda3
        params += lvm root=/dev/mapper/vg-root
}


"Funtoo Linux genkernel" {
        kernel kernel-genkernel[-v]
        initrd initramfs-genkernel[-v]
        params = quiet rootfstype=ext4
        params += luks enc_root=/dev/sda3
        params += lvm root=/dev/mapper/vg-root
}

Okay,... here you go..! :)

update the grub.cfg, then reboot and see how it works!

root@[~src/linux-3.2.6-pf] # boot-update -v     

 boot-update 1.5.2 / Copyright 2009-2011 Funtoo Technologies

 [use option "-l" for license info, "-h" for help]

 * Generating config for grub...

 DEFAULT > Funtoo Linux better-initramfs - vmlinuz-3.2.6-pf
           Funtoo Linux dracut - vmlinuz-3.2.6-pf
           Funtoo Linux genkernel - kernel-genkernel-x86_64-3.2.6-ck

 * Completed successfully.

root@[~src/linux-3.2.6-pf] #

root@[~src/linux-3.2.6-pf] # reboot

System going down for reboot!