Difference between pages "LVM Install Guide" and "Building a Kernel from Source"

(Difference between pages)
m (fix typo)
 
m (add some breathing room at "as modules:, as built in:".)
 
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 ;-)
  
{{fancynote|This tutorial will show you how to install Funtoo, including the rootfs, on logical volumes. This guide is meant to complement the regular [[Funtoo_Linux_Installation|Funtoo Installation Guide]]. It is recommended that you open it in another tab/window and follow along with it as we will only be documenting the steps that are different or in addition to the regular guide.}}
+
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 speedy and easy set up.
  
LVM (Logical Volume Management) offers a much more flexible way of managing your storage devices. Not only does it allow you to resize your volumes
+
== Minimum Requirements ==
 +
* '''Understand the command line'''
 +
* '''Know where the kernel files are located'''
  
== Live CD ==
+
== 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]].
  
Please read the [[Funtoo Linux Installation#Live CD|Live CD]] section in the regular guide. The only thing you need in addition to the [[Requirements|requirements]] it mentions is the sys-fs/lvm2 package or equivalent. If you use [http://www.sysresccd.org/ System Rescue CD], it includes the lvm2 package.
+
== Less advanced version ==
 
+
=== Emerging the kernel sources ===
== Prepare the drives and partitions ==
+
To begin, we have to figure out which kernel sources we will use. If you are unsure about which sources are available and what their benefits and drawbacks are, check out the [[Funtoo_Linux_Kernels| Kernels]] page.
 
+
{{fancynote|For this guide, we are assuming you are using MBR, that you have a /dev/sda1 (a boot drive) and /dev/sdb1 (a system drive), and that you are only using LVM with one drive, even though LVM supports adding multiple hard disks and partitions to a volume group. Please adapt these instructions to suit your needs.}}
+
 
+
Preparing the hard disk for an LVM install isn't much different from a normal install except that we won't be creating a bunch of partitions as we are going to use logical volumes instead.
+
 
+
Find the disk:
+
  
 +
After you have made a decsion as to which kernel you want to install, emerge it:
 
<console>
 
<console>
# fdisk -l
+
###i## emerge vanilla-sources
 
</console>
 
</console>
 +
Portage will now go about installing the sources to ''/usr/src''. It will also symlink the kernel-version directory to a directory called ''linux''.
  
Verify the disk:
+
=== Configuring the kernel ===
 
+
Now that the kernel sources are on your system, you should configure them. To do this, change your directory to ''/usr/src/linux''
 
<console>
 
<console>
# fdisk -l /dev/sdb
+
###i## cd /usr/src/linux
 
</console>
 
</console>
 
+
As we are now in the kernel sources directory, we can run a script that allows us to modify them. Run:
Zap the disk:
+
 
+
 
<console>
 
<console>
# sgdisk --zap-all /dev/sdb
+
###i## make menuconfig
 
</console>
 
</console>
  
Create the partition table:
+
While you edit the sources, keep the following in mind:
 +
* To build something into your kernel, press y when you have it selected.
 +
* To exclude something from your kernel, press n when you have it selected.
 +
* To build something as a module, press m.
  
{{fancynote|If you are using MBR, review paritioning [[Funtoo_Linux_Installation#Partitioning_Using_fdisk_.28MBR.29|Partitioning Using fdisk]] and if you are using GPT, review [[Partitioning using gdisk]]. The basic idea is to create what ncessary and then allocate the rest for LVM.}}
 
  
For MBR, this is the boot partition (if you want it on the system drive), every else goes to LVM like so:
+
Things that you may need to include in your kernel:<br />
  
<console>
+
as '''modules''':
# fdisk /dev/sdb
+
* Wireless/LAN drivers
</console>
+
* Support for your graphics card
 +
* Support for your audio card
 +
* Support for USB devices
  
<pre>
 
Disk /dev/sdb: 596.2 GiB, 640135028736 bytes, 1250263728 sectors
 
Units: sectors of 1 * 512 = 512 bytes
 
Sector size (logical/physical): 512 bytes / 512 bytes
 
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
Disklabel type: dos
 
Disk identifier: 0xaa6abfe1
 
  
Device    Boot    Start        End    Blocks  Id System
+
as '''built in''':
/dev/sdb1          2048    264191    131072  83 Linux
+
* scsi sata & or ata controllers
/dev/sdb2        264192 1250263727 624999768  83 Linux
+
* file system used
</pre>
+
  
For GPT, this is the BIOS boot partion and the boot partition (if you want them on the system drive), every else goes to LVM like so:
+
{{fancynote| Many pages on the wiki will tell you the kernel requirements for the application that they are about. Keep your eyes open for the blue background, white text sections of pages. Like on this one: [[uvesafb| uvesafb]]}}
  
 +
=== Building and installing the kernel sources ===
 +
After you finish configuring your kernel sources, you will need to build them. To build your sources, run the following:
 
<console>
 
<console>
# gdisk /dev/sdb
+
###i## make
 
</console>
 
</console>
 +
{{fancytip| You can add -j<number of processing cores + 1> after make to build the kernel more quickly.}}
  
<pre>
+
When the kernel and its modules finish building, install them:
Disk /dev/sdb: 596.2 GiB, 640135028736 bytes, 1250263728 sectors
+
Units: sectors of 1 * 512 = 512 bytes
+
Sector size (logical/physical): 512 bytes / 512 bytes
+
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
Disklabel type: dos
+
Disk identifier: 0x6ba8799c
+
 
+
Device    Boot    Start        End    Blocks  Id System
+
/dev/sdb1          2048      6143      2048  ef EFI (FAT-12/16/32)
+
/dev/sdb2          6144    268287    131072  83 Linux
+
/dev/sdb3        268288 1250263727 624997720  83 Linux
+
</pre>
+
 
+
You'll notice in both cases that a swap partition wasn't created. This is becasue if one is desired, it can be done in LVM.
+
 
+
Create the physical volume:
+
 
+
{{fancynote|As a reminder, for this guide, we are assuming you are using MBR, that you have a /dev/sda1 (a boot drive) and /dev/sdb1 (a system drive), and that you are only using LVM with one drive. Change this to suit your purposes.}}
+
 
+
Our first step is to create a physical volume which basically just tells the lvm where to write the data to.
+
 
+
 
<console>
 
<console>
# pvcreate -f -f /dev/sdb1
+
###i## make modules_install && make install
 
</console>
 
</console>
 +
Now that you have installed your kernel and modules, it is a good idea to install an [[Building_a_Kernel_from_Source#Initramfs| Initramfs]].
 +
* If your system has a separate ''/usr'' partition, is encrypted, or uses some other non-standard configuration, it will probably not boot without an initramfs.
 +
* If your system is unencrypted, with file system, and hard drive controllers compiled in rather than as modules, it will not need an initramfs.
  
<pre>
+
== Advanced version ==
  Physical volume "/dev/sdb1" successfully created
+
=== Getting ready to start ===
</pre>
+
  
Display the physical volume:
+
{{fancynote| 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.}}
 +
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.
  
<console>
+
I would always trust my distribution of choice and take what is has to offer - and funtoo has a lot to offer!
# pvdisplay
+
</console>
+
  
<pre>
+
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]].
  "/dev/sdb1" is a new physical volume of "596.17 GiB"
+
  --- NEW Physical volume ---
+
  PV Name              /dev/sdb1
+
  VG Name             
+
  PV Size              596.17 GiB
+
  Allocatable          NO
+
  PE Size              0 
+
  Total PE              0
+
  Free PE              0
+
  Allocated PE          0
+
  PV UUID              IDDrWr-t3PD-7t31-fRQ3-pay2-eMGy-1NgrD0
+
</pre>
+
  
Create the volume group:
+
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.
  
Now that we have a place to store our data we need to create a volume group for it. A volume group is simply a named group of at least one physical volume. This allows multiple physical volumes to be used to store data. In our simple example we only have one physical volume so we'll create a volume group and add our physical volume to it in one command. We are going to call our volume group "funtoo" but you can name it anything you want.  
+
{{fancynote| 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.}}
  
<console>
+
Let's go!
# vgcreate funtoo /dev/sdb1
+
</console>
+
  
<pre>
+
=== Kernel Sources ===
  Volume group "funtoo" successfully created
+
The source you use on your system is up to you. For a laptop or desktop system, the following are recommended:
</pre>
+
* '''{{Package|sys-kernel/pf-sources}}'''
 +
* '''{{Package|sys-kernel/ck-sources}}'''
 +
* '''{{Package|sys-kernel/gentoo-sources}}'''
 +
* '''{{Package|sys-kernel/git-sources}}'''
 +
* '''{{Package|sys-kernel/sysrescue-std-sources}}'''
 +
* '''{{Package|sys-kernel/debian-sources}}'''
 +
{{fancynote| If you are unsure of which sources you would like to use, emerge <code>gentoo-sources</code>. That's always a safe bet for a general system. For more information on available kernels, check out: [[Funtoo Linux Kernels]]}}
  
Display the volume group:
+
=== Prerequisites ===
  
<console>
+
Regardless of the tools you already have installed, it is recommended to follow the steps below, even if you find them to be redundant.
# vgdisplay
+
First, we edit our <code>/etc/portage/make.conf</code>:
</console>
+
  
 
<pre>
 
<pre>
  --- Volume group ---
+
#These compiler flags are just tweaking (optimazation) and NOT necessary:
  VG Name              funtoo
+
CFLAGS="-O2 -pipe -march=native -ftracer -fforce-addr"
  System ID           
+
CXXFLAGS="${CFLAGS} -fpermissive -fomit-frame-pointer"
  Format                lvm2
+
KDIR=/usr/src/linux
  Metadata Areas        1
+
KERNEL="symlink build"
  Metadata Sequence No  1
+
USE="$KERNEL ....here are your use flags...."
  VG Access            read/write
+
## These modules are available:
  VG Status            resizable
+
## 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"
  MAX LV                0
+
## We will use these modules for LVM / LUKS:
  Cur LV                0
+
DRACUT_MODULES="crypt lvm plymouth biosdevname dmraid crypt-gpg dmsquash-live ssh-client syslog"
  Open LV              0
+
  Max PV                0
+
  Cur PV                1
+
  Act PV                1
+
  VG Size              596.17 GiB
+
  PE Size              4.00 MiB
+
  Total PE              152619
+
  Alloc PE / Size      0 / 0 
+
  Free  PE / Size      152619 / 596.17 GiB
+
  VG UUID              jFubWA-SGaa-w3C7-Zrst-9Hqo-mWPZ-9JqYZ4
+
 
</pre>
 
</pre>
  
Create the logical volumes:
+
Next, we set the package keywords by adding the following to <code>/etc/portage/package.use</code>:
 
+
We now come to the heart of using LVM, logical volumes. Here we get to create logical volumes to store our data. Remember that the best part of LVM is the ability to resize volumes later on the fly so keep that in mind when deciding how big to make volumes. No need to allocate all your space right away. Also keep in mind when choosing a file system type that it must support resizing in order to take advantage of LVM's resizing features.
+
 
+
For our simple example we are only going to create 4 logical volumes and use them for: (SWAP) /(ROOT), /home/my and /home/my/media.
+
 
+
<console>
+
# lvcreate -L 32G -n SWAP funtoo
+
</console>
+
  
 
<pre>
 
<pre>
  Logical volume "SWAP" created
+
sys-kernel/dracut dm net device-mapper crypt lvm
 
</pre>
 
</pre>
  
<console>
+
{{fancynote| If you don't have lvm over encrypted LUKS you just add the "net" keyword here, or "selinux".}}
# lvcreate -L 64G -n ROOT funtoo
+
</console>
+
  
<pre>
 
  Logical volume "ROOT" created
 
</pre>
 
  
 +
Next, we build our packages:
 
<console>
 
<console>
# lvcreate -L 128G -n home_my funtoo
+
###i## emerge -av app-portage/gentoolkit sys-kernel/pf-sources sys-kernel/dracut sys-boot/plymouth sys-boot/plymouth-openrc-plugin
 
</console>
 
</console>
  
<pre>
+
=== Preparing the kernel ===
  Logical volume "home_my" created
+
</pre>
+
  
 +
We go now to the sources directory and enter the following commands to update the kernel's  .config  file:
 
<console>
 
<console>
# lvcreate -L 256G -n home_my_media funtoo
+
###i## cd /usr/src/linux/
 +
###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>
  
<pre>
+
Next, we run <tt>make localmodconfig</tt>. You will get some questions which you can answer mostly with either M (compiled as a module) or Y (compiled directly into the kernel). If you are not sure what to choose, press enter, and the default option will be selected.
  Logical volume "home_my_media" created
+
</pre>
+
 
+
Display the logical volumes:
+
 
+
 
<console>
 
<console>
# lvdisplay
+
###i## make localmodconfig
 +
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)
 
</console>
 
</console>
  
<pre>
+
Now comes the most adventurous part!
  --- Logical volume ---
+
  LV Path                /dev/funtoo/SWAP
+
  LV Name                SWAP
+
  VG Name                funtoo
+
  LV UUID                VkdEAk-Jshp-qcQ0-jU7m-m7f4-fyG6-1FZJlh
+
  LV Write Access        read/write
+
  LV Creation host, time funtoo, 2014-07-24 04:39:19 -0400
+
  LV Status              available
+
  # open                0
+
  LV Size                32.00 GiB
+
  Current LE            8192
+
  Segments              1
+
  Allocation            inherit
+
  Read ahead sectors    auto
+
  - currently set to    256
+
  Block device          253:1
+
 
+
  --- Logical volume ---
+
  LV Path                /dev/funtoo/ROOT
+
  LV Name                ROOT
+
  VG Name                funtoo
+
  LV UUID                2WE7dL-R5BN-dM78-eMx5-hwS8-SjWJ-mUjzL4
+
  LV Write Access        read/write
+
  LV Creation host, time funtoo, 2014-07-24 04:39:24 -0400
+
  LV Status              available
+
  # open                0
+
  LV Size                64.00 GiB
+
  Current LE            16384
+
  Segments              1
+
  Allocation            inherit
+
  Read ahead sectors    auto
+
  - currently set to    256
+
  Block device          253:2
+
 
+
  --- Logical volume ---
+
  LV Path                /dev/funtoo/home_my
+
  LV Name                home_my
+
  VG Name                funtoo
+
  LV UUID                OJnpYM-399Y-8pa3-iMTY-Nle3-IyK1-keDtng
+
  LV Write Access        read/write
+
  LV Creation host, time funtoo, 2014-07-24 04:40:16 -0400
+
  LV Status              available
+
  # open                0
+
  LV Size                128.00 GiB
+
  Current LE            32768
+
  Segments              1
+
  Allocation            inherit
+
  Read ahead sectors    auto
+
  - currently set to    256
+
  Block device          253:3
+
 
+
  --- Logical volume ---
+
  LV Path                /dev/funtoo/home_my_media
+
  LV Name                home_my_media
+
  VG Name                funtoo
+
  LV UUID                tt7cin-igC4-VD85-fDKV-J692-fV3F-auJYcU
+
  LV Write Access        read/write
+
  LV Creation host, time funtoo, 2014-07-24 04:40:30 -0400
+
  LV Status              available
+
  # open                0
+
  LV Size                256.00 GiB
+
  Current LE            65536
+
  Segments              1
+
  Allocation            inherit
+
  Read ahead sectors    auto
+
  - currently set to    256
+
  Block device          253:4
+
</pre>
+
 
+
Activate swap:
+
  
 +
=== Building the Kernel ===
 
<console>
 
<console>
# mkswap /dev/mapper/funtoo-SWAP
+
###i## make -j8  bzImage
 +
###i## make -j8 modules
 +
###i## make modules_install
 +
###i## make install
 
</console>
 
</console>
  
<pre>
+
== Initramfs ==
Setting up swapspace version 1, size = 33554428 KiB
+
{{fancywarning| Make sure that you have built and installed your kernel sources / modules before building an initramfs.}}
no label, UUID=ccc83857-28da-4508-a393-84e974e0eeb1
+
To get your initramfs up and running, check out the [http://www.funtoo.org/Initramfs Initramfs] page. After following all the directions on the page to get your initramfs set up, continue following the ones here.
</pre>
+
  
 +
Update the <tt>grub.cfg</tt> with boot update, then reboot and see how it works!
 
<console>
 
<console>
# swapon /dev/mapper/funtoo-SWAP
+
###i## boot-update -v
 +
###i## reboot
 
</console>
 
</console>
 
Create the filesystems:
 
 
{{fancynote|Before proceeding you should read through the brief section [[Funtoo Linux Installation#Creating filesystems|Creating filesystems]] in the install guide and decide what type of filesystem you would like to use. Do not actually create any file systems though, we will cover that below.}}
 
 
<console>
 
# mkfs.ext2      /dev/sda1
 
</console>
 
 
<pre>
 
[...]
 
</pre>
 
 
<console>
 
# mkfs.ext4      /dev/mapper/funtoo-ROOT
 
</console>
 
 
<pre>
 
mke2fs 1.42.10 (18-May-2014)
 
Creating filesystem with 16777216 4k blocks and 4194304 inodes
 
Filesystem UUID: 0ab8f9ab-e824-4d69-a9c4-201d4ccd99ac
 
Superblock backups stored on blocks:
 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
 
4096000, 7962624, 11239424
 
 
Allocating group tables: done                           
 
Writing inode tables: done                           
 
Creating journal (32768 blocks): done
 
Writing superblocks and filesystem accounting information: done 
 
</pre>
 
 
<console>
 
# mkfs.ext4      /dev/mapper/funtoo-home_my
 
</console>
 
 
<pre>
 
mke2fs 1.42.10 (18-May-2014)
 
Creating filesystem with 33554432 4k blocks and 8388608 inodes
 
Filesystem UUID: 46e394c1-3635-4f13-ba51-10c537d2b5ed
 
Superblock backups stored on blocks:
 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
 
4096000, 7962624, 11239424, 20480000, 23887872
 
 
Allocating group tables: done                           
 
Writing inode tables: done                           
 
Creating journal (32768 blocks): done
 
Writing superblocks and filesystem accounting information: done   
 
</pre>
 
 
<console>
 
# mkfs.xfs        /dev/mapper/funtoo-home_my_media
 
</console>
 
 
<pre>
 
meta-data=/dev/mapper/funtoo-home_my_media isize=256    agcount=4, agsize=16777216 blks
 
        =                      sectsz=512  attr=2, projid32bit=0
 
data    =                      bsize=4096  blocks=67108864, imaxpct=25
 
        =                      sunit=0      swidth=0 blks
 
naming  =version 2              bsize=4096  ascii-ci=0
 
log      =internal log          bsize=4096  blocks=32768, version=2
 
        =                      sectsz=512  sunit=0 blks, lazy-count=1
 
realtime =none                  extsz=4096  blocks=0, rtextents=0
 
</pre>
 
 
Label the filesystems:
 
 
<console>
 
# e2label /dev/sda1 boot
 
</console>
 
 
== Prepare for chroot ==
 
 
Activiate the volumes:
 
 
<console>
 
# vgscan
 
# vgchange -a y
 
</console>
 
 
Mount the filesystems:
 
 
<console>
 
# mkdir -p /mnt/funtoo
 
# mount /dev/mapper/funtoo-ROOT /mnt/funtoo
 
# mkdir -p /mnt/funtoo/boot
 
# mount /dev/sda1 /mnt/funtoo/boot
 
# mkdir -p /mnt/funtoo/home/my
 
# mount /dev/mapper/funtoo-home_my /mnt/funtoo/home/my
 
# mkdir -p /mnt/funtoo/home/my/media
 
# mount /dev/mapper/funtoo-home_my_media /mnt/funtoo/home/my/media
 
</console>
 
 
== Resume from Funtoo Linux Installation ==
 
 
You may safely resume from [http://www.funtoo.org/Funtoo_Linux_Installation#Installing_the_Stage_3_tarball Installing the Stage 3 tarball] with few exceptions:
 
 
=== fstab ===
 
 
<pre>
 
# <filesystem>                  <mountpoint>        <type>      <opts>      <dump>      <pass>
 
/dev/funtoo/SWAP                none                swap        sw          0          0
 
/dev/funtoo/ROOT                /                  ext4        noatime    0          1
 
LABEL=boot                      /boot              ext2        noatime    0          0
 
/dev/funtoo/home_my            /home/my            ext4        noatime    0          2
 
/dev/funtoo/home_my_media      /home/my/media      xfs        noatime    0          2
 
</pre>
 
 
=== kernel ===
 
 
Enable kernel options:
 
{{kernelop
 
|title=
 
|desc=
 
General setup --->
 
      [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
 
}}
 
{{kernelop
 
|title=
 
|desc=
 
Device Drivers --->
 
      Generic Driver Options --->
 
      [*] Maintain a devtmpfs filesystem to mount at /dev
 
}}
 
{{kernelop
 
|title=
 
|desc=
 
Device Drivers --->
 
      [*] Multiple devices driver support --->
 
      <*>Device Mapper Support
 
}}
 
 
Build initramfs (genkernel):
 
 
{{fancynote|This builds only an initramfs with lvm support. It does not build the whole kernel so you still have to do that.}}
 
 
<console>
 
# genkernel --lvm initramfs
 
</console>
 
 
=== boot-update ===
 
 
<pre>
 
boot {
 
  generate grub
 
  default "Funtoo Linux"
 
  timeout 3
 
}
 
 
"Funtoo Linux" {
 
  kernel kernel-genkernel-x86_64-3.14.13
 
  initrd initramfs-genkernel-x86_64-3.14.13
 
  params += dolvm real_root=/dev/mapper/funtoo-ROOT rootfstype=ext4 resume=swap:/dev/mapper/funtoo-SWAP quiet
 
}
 
</pre>
 
 
=== software ===
 
 
<console>
 
# emerge -va lvm2
 
</console>
 
 
For the most part, LVM "just works" without any additional configuration. This is especially true for versions below 2.02.107. If you are using >=sys-fs/lvm2-2.02.107 with Funtoo, there are two features be desired that are turned off by default:
 
 
The Metadata Daemon ([https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/metadatadaemon.html lvmetad])
 
 
Thinly-Provisioned Logical Volumes ([https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/thinprovisioned_volumes.html Thin Volumes])
 
 
Enabling either is simply a matter of enabling their USE flags.
 
 
== Cleaning up ==
 
 
<console>
 
# exit
 
# cd /
 
# cat /proc/mounts | grep funtoo | awk '{print $2}' | grep "^$MOUNTPOINT" | sort -r | xargs umount
 
# umount /mnt/funtoo
 
# swapoff -v /dev/mapper/funtoo-SWAP
 
# vgchange -a n
 
# init 0
 
</console>
 
 
== Special notes ==
 
 
=== Resizing ===
 
 
{{fancynote|Resizing is filesystem specific. Most can be grown but cannot be shrunk.}}
 
 
==== Growing /home/my by 8G ====
 
 
<console>
 
# lvextend -L+8G /dev/mapper/funtoo-home_my
 
</console>
 
 
===== ext2/ext3/ext4 =====
 
 
<console>
 
# resize2fs /mnt/funtoo/home/my
 
</console>
 
 
===== xfs =====
 
 
<console>
 
# xfs_growfs /mnt/funtoo/home/my
 
</console>
 
 
==== Shrinking /home/my by 8G ====
 
 
{{fancynote|You generally need to umount first.}}
 
 
===== ext2/ext3/ext4 =====
 
 
<console>
 
# umount /mnt/funtoo/home/my
 
# lvreduce -r -L -8G /dev/mapper/funtoo-home_my
 
</console>
 
 
===== xfs =====
 
 
XFS cannot be shrunk.
 
 
== Beyond the basics ==
 
 
The [[LVM Fun]] page may be of interest.
 
 
As well as these pages from Red Hat: [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/snapshot_command.html Creating Snapshot Volumes]
 
[https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/thinly_provisioned_volume_creation.html Creating Thinly-Provionsed Logical Volumes]
 
[https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/mirror_create.html Creating Mirrored Volumes]
 
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
[[Category:Install]]
+
[[Category:Featured]]
[[Category:Official Documentation]]
+
[[Category:Kernel]]

Revision as of 10:50, September 23, 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 speedy and easy set up.

Minimum Requirements

  • Understand the command line
  • Know where the kernel files are located

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.

Less advanced version

Emerging the kernel sources

To begin, we have to figure out which kernel sources we will use. If you are unsure about which sources are available and what their benefits and drawbacks are, check out the Kernels page.

After you have made a decsion as to which kernel you want to install, emerge it:

# emerge vanilla-sources 

Portage will now go about installing the sources to /usr/src. It will also symlink the kernel-version directory to a directory called linux.

Configuring the kernel

Now that the kernel sources are on your system, you should configure them. To do this, change your directory to /usr/src/linux

# cd /usr/src/linux

As we are now in the kernel sources directory, we can run a script that allows us to modify them. Run:

# make menuconfig

While you edit the sources, keep the following in mind:

  • To build something into your kernel, press y when you have it selected.
  • To exclude something from your kernel, press n when you have it selected.
  • To build something as a module, press m.


Things that you may need to include in your kernel:

as modules:

  • Wireless/LAN drivers
  • Support for your graphics card
  • Support for your audio card
  • Support for USB devices


as built in:

  • scsi sata & or ata controllers
  • file system used

Note

Many pages on the wiki will tell you the kernel requirements for the application that they are about. Keep your eyes open for the blue background, white text sections of pages. Like on this one:  uvesafb

Building and installing the kernel sources

After you finish configuring your kernel sources, you will need to build them. To build your sources, run the following:

# make

Tip

You can add -j<number of processing cores + 1> after make to build the kernel more quickly.

When the kernel and its modules finish building, install them:

# make modules_install && make install

Now that you have installed your kernel and modules, it is a good idea to install an Initramfs.

  • If your system has a separate /usr partition, is encrypted, or uses some other non-standard configuration, it will probably not boot without an initramfs.
  • If your system is unencrypted, with file system, and hard drive controllers compiled in rather than as modules, it will not need an initramfs.

Advanced version

Getting ready to start

Note

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.

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.

Note

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

The source you use on your system is up to you. For a laptop or desktop system, the following are recommended:

  • sys-kernel/pf-sources (package not on wiki - please add)
  • sys-kernel/ck-sources (package not on wiki - please add)
  • sys-kernel/gentoo-sources (package not on wiki - please add)
  • sys-kernel/git-sources (package not on wiki - please add)
  • sys-kernel/sysrescue-std-sources (package not on wiki - please add)
  • sys-kernel/debian-sources (package not on wiki - please add)

Note

If you are unsure of which sources you would like to use, emerge gentoo-sources. That's always a safe bet for a general system. For more information on available kernels, check out: Funtoo Linux Kernels

Prerequisites

Regardless of the tools you already have installed, it is recommended to follow the steps below, even if you find them to be redundant. First, we edit our /etc/portage/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 by adding the following to /etc/portage/package.use:

sys-kernel/dracut dm net device-mapper crypt lvm

Note

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


Next, we build our packages:

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

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

Next, we run 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). If you are not sure what to choose, press enter, and the default option will be selected.

# make localmodconfig
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)

Now comes the most adventurous part!

Building the Kernel

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

Initramfs

Warning

Make sure that you have built and installed your kernel sources / modules before building an initramfs.

To get your initramfs up and running, check out the Initramfs page. After following all the directions on the page to get your initramfs set up, continue following the ones here.

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

# boot-update -v
# reboot