Difference between pages "BTRFS Fun" and "Funtoo Linux Kernels"

From Funtoo
(Difference between pages)
Jump to: navigation, search
(Changing the point of view on the subvolumes hierarchy)
 
m (Kernel Features and Stability: Updated versions in table)
 
Line 1: Line 1:
 +
This Section will give you an overview of kernels used in funtoo.
  
{{fancyimportant|BTRFS is still '''experimental''' even with latest Linux kernels (3.4-rc at date of writing) so be prepared to lose some data sooner or later or hit a severe issue/regressions/"itchy" bugs. Subliminal message: '''Do not put critical data on BTRFS partitions'''.}}
+
Funtoo Linux provides a number of new kernels for your use. This is the official page for all Funtoo Linux kernel information.  
+
  
= Introduction =
+
Some points of interest:
  
BTRFS is an advanced filesystem mostly contributed by Sun/Oracle whose origins take place in 2007. A good summary is given in
+
* Most Funtoo Linux kernels support the handy <tt>[[#Binary USE|binary]]</tt> USE flag, described below.
[http://lwn.net/Articles/342892/]. BTRFS aims to provide a modern answer for making storage more flexible and efficient. According to its main contributor, Chris Mason, the goal was "to let Linux scale for the storage that will be available. Scaling is not just about addressing the storage but also means being able to administer and to manage it with a clean interface that lets people see what's being used and makes it more reliable." (Ref. [http://en.wikipedia.org/wiki/Btrfs http://en.wikipedia.org/wiki/Btrfs]).
+
* Funtoo Linux offers quality kernels from other Linux Distributions, like <tt>ubuntu-server</tt> and <tt>debian-sources</tt>.
 +
* A detailed [[#Kernel Features and Stability|Kernel Features and Stability]] table can be found below.
 +
* Advanced users may want to take a look at [[Additional Kernel Resources]].
 +
* There is a quick'n dirty howto to compile your own [[kernel]] with initramfs the funtoo way.
  
Btrfs, often compared to ZFS, is offering some interesting features like:
+
== Overview of Kernels ==
  
* Using very few fixed location metadata, thus allowing an existing ext2/ext3 filesystem to be "upgraded" in-place to BTRFS.
+
=== sysrescue-std-sources ===
* Operations are transactional
+
* Online volume defragmentation (online filesystem check is on the radar but is not yet implemented).
+
* Built-in storage pool capabilities (no need for LVM)
+
* Built-in RAID capabilities (both for the data and filesystem metadata). RAID-5/6 is planned for 3.5 kernels
+
* Capabilities to grow/shrink the volume
+
* Subvolumes and snapshots (extremely powerful, you can "rollback" to a previous filesystem state as if nothing had happened).
+
* Copy-On-Write
+
* Usage of B-Trees to store the internal filesystem structures (B-Trees are known to have a logarithmic growth in depth, thus making them more efficient when scanning)
+
  
= Requirements =
+
This kernel is from the [http://www.sysresccd.org SystemRescueCD project], and is based on Fedora 14/15, plus some other patches related to booting from a live CD. It is a quality kernel, and is generally pretty stable. It is not suitable for production servers but is a good choice for Funtoo Linux desktops. Earlier,the [[Funtoo Linux Installation]] Guide recommended this kernel for general users, but now 'debian-sources' is recommended. Note however,  that by design all audio functions are removed from SystemRescue,  ie no sound when using this kernel.
  
A recent Linux kernel (BTRFS metadata format evolves from time to time and mounting using a recent Linux kernel can make the BTRFS volume unreadable with an older kernel revision, e.g. Linux 2.6.31 vs Linux 2.6.30). You must also use sys-fs/btrfs-progs (0.19 or better use -9999 which points to the git repository).
+
=== vanilla-sources ===
  
= Playing with BTRFS storage pool capabilities =
+
This will install the "vanilla" (unmodified) Linux kernel sources. Current recommended version is 3.x. Funtoo Linux fully supports Linux 3.x. The advantages of this kernel include recent improvements to [[Linux Containers]], a very modern networking stack with lots of bug fixes, and high reliability for desktops and servers. The downside is that this kernel must be manually configured by the user and does not have built-in <tt>genkernel</tt> support via the <tt>binary</tt> USE flag at this time.
  
Whereas it would possible to use btrfs just as you are used to under a non-LVM system, it shines in using its built-in storage pool capabilities. Tired of playing with LVM ? :-) Good news: you do not need it anymore with btrfs.
+
=== gentoo-sources ===
  
== Setting up a storage pool ==
+
This kernel tree is based on stable kernels from [https://www.kernel.org/ kernel.org] with genpatches applied [http://dev.gentoo.org/~mpagano/genpatches/about.htm genpatches].
 +
Gentoo patchset aims to support the entire range of Gentoo-supported architectures. List of available genpatched kernels: [http://dev.gentoo.org/~mpagano/genpatches/kernels.htm genpatches-kernels]
  
BTRFS terminology is a bit confusing.  If you already have used another 'advanced' filesystem like ZFS or some mechanism like LVM, it's good to know that there are many correlations.  In the BTRFS world, the word ''volume'' corresponds to a storage ''pool'' (ZFS) or a ''volume group'' (LVM). Ref. [http://www.rkeene.org/projects/info/wiki.cgi/165 http://www.rkeene.org/projects/info/wiki.cgi/165]
+
=== openvz-rhel6-stable ===
  
The test bench uses disk images through loopback devices. Of course, in a real world case, you will use local drives or units though a SAN. To start with, 5 devices of 1 GiB are allocated:
+
This is a RHEL6-based kernel with OpenVZ support. This kernel is now the preferred kernel for production OpenVZ deployments. It requires gcc-4.4.5 to build, which it will use automatically without the user needing to use <tt>gcc-config</tt>. We use this version of gcc since this is the version of gcc used by Red Hat to build this kernel.
  
<pre>
+
=== openvz-rhel5-stable ===
# dd if=/dev/zero of=/tmp/btrfs-vol0.img bs=1G count=1
+
# dd if=/dev/zero of=/tmp/btrfs-vol1.img bs=1G count=1
+
# dd if=/dev/zero of=/tmp/btrfs-vol2.img bs=1G count=1
+
# dd if=/dev/zero of=/tmp/btrfs-vol3.img bs=1G count=1
+
# dd if=/dev/zero of=/tmp/btrfs-vol4.img bs=1G count=1
+
</pre>
+
  
Then attached:
+
This kernel is based on the latest Red Hat Enterprise Linux 5.6 kernel, and contains additional OpenVZ (virtual containers) patches from the [[OpenVZ on Funtoo Linux|OpenVZ]] project. It is a very stable and reliable kernel, and is recommended for use in production environments. The only major downside to this kernel is that it is based on Linux 2.6.18 -- some parts of the kernel are out-of-date, and it is not compatible with modern versions of udev. However, it is pretty trivial to downgrade udev to an earlier version on Funtoo Linux and this kernel has a track-record of being rock-solid. When stability is paramount, you put up with the udev downgrade, use this kernel, and can enjoy hundreds of days of uptime. For more information on how to use this kernel with Funtoo Linux, see the [[RHEL5 Kernel HOWTO]].
  
<pre>
+
=== ubuntu-server ===
# losetup /dev/loop0 /tmp/btrfs-vol0.img
+
# losetup /dev/loop1 /tmp/btrfs-vol1.img
+
# losetup /dev/loop2 /tmp/btrfs-vol2.img
+
# losetup /dev/loop3 /tmp/btrfs-vol3.img
+
# losetup /dev/loop4 /tmp/btrfs-vol4.img
+
</pre>
+
  
== Creating the initial volume (pool) ==
+
This is the kernel from Ubuntu Server. Version <tt>2.6.32.32.62</tt> is the same version used in Ubuntu Server 10.04 LTS, and version <tt>2.6.35.28.50</tt> is the one used in Ubuntu Server 10.10 (currently masked). In our testing of <tt>2.6.32.32.62</tt>, it has been very reliable and offers very good performance. One exception, which is common among 2.6.32-based kernels, is that it's recommended that you emerge <tt>broadcom-netxtreme2</tt> if you have any Broadcom-based NICs, as the in-kernel drivers have compatibility issues with certain models. This kernel is a very good option if you want a relatively modern server kernel and do not need [[OpenVZ]] support. We use gcc-4.4.5 to build this kernel. It will use gcc-4.4.5 automatically, without requiring the user to use <tt>gcc-config</tt>.
  
BTRFS uses different strategies to store data and for the filesystem metadata (ref. [https://btrfs.wiki.kernel.org/index.php/Using_Btrfs_with_Multiple_Devices https://btrfs.wiki.kernel.org/index.php/Using_Btrfs_with_Multiple_Devices]).
+
=== debian-sources ===
  
By default the behavior is:
+
This is the Debian kernel. '''These ebuilds now support the <tt>binary</tt> USE flag.''' Daniel has added a special <tt>config-extract</tt> command which can be used to list all available official Debian kernel configurations, and generate them from the Debian files included with the kernel. This kernel has optional [[OpenVZ]] support, but it is much better to use <tt>openvz-rhel6-stable</tt> if you want a production-quality OpenVZ installation. For more information about how to use <tt>debian-sources</tt> and <tt>config-extract</tt>, see [[#Using Debian-Sources with Genkernel|Using debian-sources with Genkernel]] below.
* metadata is '''replicated''' on all of the devices. If a single device is used the metadata is duplicated inside this single device (useful in case of corruption or bad sector, there is a higher chance that one of the two copies is clean). To tell btrfs to maintain a single copy of the metadata, just use ''single''. Remember: '''dead metadata = dead volume with no chance of recovery.'''
+
* data is '''spread''' amongst all of the devices (this means no redundancy; any data block left on a defective device will be inaccessible)
+
  
To create a BTRFS volume made of multiple devices with default options, use:
+
=== debian-sources-lts ===
  
<pre>
+
This is the Debian long-term stable kernel. '''These ebuilds now support the <tt>binary</tt> USE flag.''' Daniel has added a special <tt>config-extract</tt> command which can be used to list all available official Debian kernel configurations, and generate them from the Debian files included with the kernel.
# mkfs.btrfs /dev/loop0 /dev/loop1 /dev/loop2
+
</pre>
+
  
To create a BTRFS volume made of a single device with a single copy of the metadata (dangerous!), use:
+
== Binary USE ==
  
<pre>
+
Many of the kernel ebuilds in Funtoo Linux support the very useful <tt>binary</tt> USE flag. By enabling this USE flag and emerging the kernel, the ebuild will automatically build a binary kernel image, initramfs and kernel modules and install them to <tt>/boot</tt>. The binary kernel image and initramfs can be used to boot your Funtoo Linux system without requiring any additional configuration. This is a great way to get a Funtoo Linux system up and running quickly. Here's how to do it:
# mkfs.btrfs -m single /dev/loop0
+
</pre>
+
 
+
To create a BTRFS volume made of multiple devices with metadata spread amongst all of the devices, use:
+
  
 
<pre>
 
<pre>
# mkfs.btrfs -m raid0 /dev/loop0 /dev/loop1 /dev/loop2
+
# echo "sys-kernel/openvz-rhel5-stable binary" >> /etc/portage/package.use
 +
# emerge openvz-rhel5-stable
 +
# nano -w /etc/boot.conf
 +
# boot-update
 
</pre>
 
</pre>
  
To create a BTRFS volume made of multiple devices, with metadata spread amongst all of the devices and data mirrored on all of the devices (you probably don't want this in a real setup), use:
+
More information can be found in the [[Funtoo Linux Installation]] Guide.
  
<pre>
+
== Funtoo Linux Genkernel ==
# mkfs.btrfs -m raid0 -d raid1 /dev/loop0 /dev/loop1 /dev/loop2
+
</pre>
+
  
To create a fully redundant BTRFS volume (data and metadata mirrored amongst all of the devices), use:
+
Funtoo Linux contains a forked/enhanced version of genkernel with the following new capabilities:
  
<pre>
+
* genkernel can use a build directory that is separate from the kernel source directory. This is enabled using the new <tt>--build-dst</tt> option.
# mkfs.btrfs -d raid1 /dev/loop0 /dev/loop1 /dev/loop2
+
* <tt>--build-src</tt> is a new option that is equivalent to the <tt>--kerneldir</tt> option.
</pre>
+
* <tt>--fullname</tt> can be used to specify the entire name of the kernel and initramfs images -- everything after <tt>kernel-</tt> and <tt>initramfs-</tt>.
 +
* <tt>--firmware-src</tt> - a new option that works identically to <tt>--firmware-dir</tt>.
 +
* <tt>--firmware-dst</tt> - a new capability - you can now define where genkernel installs firmware.
 +
* Genkernel uses Funtoo Linux <tt>lvm2</tt> rather than building its own.
 +
* Some compile fixes.
  
Technically you can use anything as a physical volume: you can have a volume composed of 2 local hard drives, 3 USB keys, 1 loopback device pointing to a file on a NFS share and 3 logical devices accessed through your SAN (you would be an idiot, but you can, nevertheless). Having different physical volume sizes would lead to issues, but it works :-).
+
== Kernel Features and Stability ==
  
== Checking the initial volume ==
+
This page provides an overview of kernel features and stability information:
  
To verify the devices of which BTRFS volume is composed, just use '''btrfs-show ''device'' ''' (old style) or '''btrfs filesystem show ''device'' ''' (new style). You need to specify one of the devices (the metadata has been designed to keep a track of the what device is linked what other device). If the initial volume was set up like this:
+
{| {{table}}
 +
!Kernel Name
 +
!Version
 +
!USE flags
 +
!Stability
 +
!Extra Features
 +
!Req'd udev
 +
!Notes
 +
|-
 +
|<tt>[[#vanilla-sources|vanilla-sources]]</tt>
 +
|3.12.4
 +
|N/A
 +
|'''Excellent''' - recommended for desktops and servers.
 +
|N/A
 +
|Any
 +
|Recommended for modern networking stack, hardware and [[Linux Containers]] support. This kernel must be manually configured by the user. New Features: [http://kernelnewbies.org/Linux_3.11 kernelnewbies.org/linux_3.11]  New Drivers: [http://kernelnewbies.org/Linux_3.11-DriversArch kernelnewbies/Linux_3.11-DriversArch]
 +
|-
 +
|<tt>[[#gentoo-sources|gentoo-sources]]</tt>
 +
|3.12.4
 +
|N/A
 +
|'''Excellent''' - recommended for desktops and workstations
 +
|N/A
 +
|Any
 +
|Recommended for modern networking stack, hardware and [[Linux Containers]] support. This kernel must be manually configured by the user. New Features: [http://kernelnewbies.org/Linux_3.11 kernelnewbies.org/linux_3.11]  New Drivers: [http://kernelnewbies.org/Linux_3.11-DriversArch kernelnewbies/Linux_3.11-DriversArch]
 +
|-
 +
|<tt>[[#sysrescue-std-sources|sysrescue-std-sources]]</tt>
 +
|3.0.21.302
 +
|<tt>binary</tt>
 +
|''Good'' - recommended for desktops
 +
|N/A
 +
|Any
 +
|Nvidia card users: binary use flag installs nouveau drivers. Not compatible with nvidia-drivers.
 +
|-
 +
|<tt>[[#openvz-rhel6-stable|openvz-rhel6-stable]]</tt>
 +
|2.6.32.042.079.5
 +
|<tt>binary</tt>
 +
|'''Excellent''' - recommended for production servers
 +
|N/A
 +
|Any
 +
|This kernel is built with gcc-4.4.5. <tt>emerge broadcom-netxtreme2</tt> for reliable BCM5709+ support (integrated NIC)
 +
|-
 +
|<tt>[[#openvz-rhel5-stable|openvz-rhel5-stable]]</tt>
 +
|2.6.18.028.095.1
 +
|<tt>binary</tt>
 +
|'''Excellent''' - recommended for production servers
 +
|OpenVZ
 +
|=sys-fs/udev-146*
 +
|Broadcom <tt>bnx2</tt> driver module bundled with kernel appears to be OK. This kernel is built with gcc-4.1.2. Enabling the <tt>binary</tt> USE flag will cause gcc-4.1.2 to be emerged and used for building the kernel.
 +
|-
 +
|<tt>[[#ubuntu-server|ubuntu-server]]</tt>
 +
|2.6.32.32.62
 +
|<tt>binary</tt>
 +
|'''Excellent''' - recommended for production servers (still in extended testing)
 +
| N/A
 +
|Any
 +
|This kernel is built with gcc-4.4.5. <tt>emerge broadcom-netxtreme2</tt> for reliable BCM5709+ support (integrated NIC)
 +
|-
 +
|<tt>[[#ubuntu-server|ubuntu-server]]</tt>
 +
|2.6.35.28.50
 +
|<tt>binary</tt>
 +
|''not yet tested''
 +
| N/A
 +
|Any
 +
|This kernel is built with gcc-4.4.5. <tt>emerge broadcom-netxtreme2</tt> for reliable BCM5709+ support (integrated NIC)
 +
|-
 +
|<tt>[[#debian-sources|debian-sources]]</tt>
 +
|3.11.5
 +
|<tt>openvz</tt>
 +
|''Good'' - default kernel recommended by Funtoo
 +
|OpenVZ (optional)
 +
|Any
 +
|See [[#Using debian-sources with Genkernel]], below.
 +
|-
 +
|}
  
<pre>
+
== Using Debian-Sources with Genkernel ==
# mkfs.btrfs /dev/loop0 /dev/loop1 /dev/loop2
+
  
WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL
+
{{ fancyimportant|Debian-sources is now fully compatible with ''binary'' USE flag and recommended for desktop users. The below example is valid for manual installation. At least 12G of /var/tmp required to build
WARNING! - see http://btrfs.wiki.kernel.org before using
+
}}
 +
This section describes how to build a binary kernel with <tt>debian-sources</tt> and <tt>genkernel</tt>, and it also explains how to use Funtoo Linux's <tt>config-extract</tt> tool to list and create official Debian kernel configurations.
  
adding device /dev/loop1 id 2
+
=== First step: emerging the required packages ===
adding device /dev/loop2 id 3
+
fs created label (null) on /dev/loop0
+
        nodesize 4096 leafsize 4096 sectorsize 4096 size 3.00GB
+
Btrfs Btrfs v0.19
+
</pre>
+
  
It can be checked with one of these commands (They are equivalent):
+
The first step is to emerge:
  
<pre>
+
# The Debian sources
# btrfs filesystem show /dev/loop0
+
# Genkernel itself
# btrfs filesystem show /dev/loop1
+
# btrfs filesystem show /dev/loop2
+
</pre>
+
  
The result is the same for all commands:
+
This is achieved with:
  
 
<pre>
 
<pre>
Label: none  uuid: 0a774d9c-b250-420e-9484-b8f982818c09
+
# emerge sys-kernel/debian-sources sys-kernel/genkernel
        Total devices 3 FS bytes used 28.00KB
+
        devid    3 size 1.00GB used 263.94MB path /dev/loop2
+
        devid    1 size 1.00GB used 275.94MB path /dev/loop0
+
        devid    2 size 1.00GB used 110.38MB path /dev/loop1
+
 
</pre>
 
</pre>
  
To show all of the volumes that are present:
+
Once the Debian kernel sources are deployed, you should find a directory named '''linux-debian-''version''''' (e.g. linux-debian-2.6.32.30) under '''/usr/src'''. Update your the '''linux''' symlink to point on this directory:
 
+
 
<pre>
 
<pre>
# btrfs filesystem show
+
# cd /usr/src
Label: none  uuid: 0a774d9c-b250-420e-9484-b8f982818c09
+
# rm linux
        Total devices 3 FS bytes used 28.00KB
+
# ln -s linux-debian-2.6.32.30 linux
        devid    3 size 1.00GB used 263.94MB path /dev/loop2
+
        devid    1 size 1.00GB used 275.94MB path /dev/loop0
+
        devid    2 size 1.00GB used 110.38MB path /dev/loop1
+
 
+
Label: none  uuid: 1701af39-8ea3-4463-8a77-ec75c59e716a
+
        Total devices 1 FS bytes used 944.40GB
+
        devid    1 size 1.42TB used 1.04TB path /dev/sda2
+
 
+
Label: none  uuid: 01178c43-7392-425e-8acf-3ed16ab48813
+
        Total devices 1 FS bytes used 180.14GB
+
        devid    1 size 406.02GB used 338.54GB path /dev/sda4
+
 
</pre>
 
</pre>
 +
Alternatively, emerge the debian-sources with USE="symlink"
  
BTRFS wiki mentions that '''btrfs device scan''' should be performed, consequence of not doing the incantation? Volume not seen?
+
=== Second step: Grabbing a configuration file ===
  
== Mounting the initial volume ==
+
If is now time to download the kernel configuration file. For this tutorial we will use a configuration file for AMD64 (several others architectures like MIPS or SPARC64 are available.)  To view a complete list of available kernel configurations, type <tt>./config-extract -l</tt> in the Debian kernel source directory:
 
+
BTRFS volumes can be mounted like any other filesystem. The cool stuff at the top on the sundae is that the design of the BTRFS metadata makes it possible to use any of the volume devices. The following commands are equivalent:
+
  
 
<pre>
 
<pre>
# mount /dev/loop0 /mnt
+
ninja1 linux-debian-2.6.32.30 # ./config-extract -l
# mount /dev/loop1 /mnt
+
# mount /dev/loop2 /mnt
+
</pre>
+
  
For every physical device used for mounting the BTRFS volume '''df -h''' reports the same (in all cases 3 GiB of "free" space is reported):
+
====== standard featureset ======
  
<pre>
+
      alpha: alpha-generic, alpha-legacy, alpha-smp
# df -h
+
      amd64
Filesystem      Size  Used Avail Use% Mounted on
+
      armel: iop32x, ixp4xx, kirkwood, orion5x, versatile
/dev/loop1     3.0G  56K  1.8G  1% /mnt
+
        hppa: parisc, parisc-smp, parisc64, parisc64-smp
</pre>
+
        i386: 486, 686, 686-bigmem, amd64
 +
        ia64: itanium, mckinley
 +
        m68k: amiga, atari, bvme6000, mac, mvme147, mvme16x
 +
        mips: 4kc-malta, 5kc-malta, r4k-ip22, r5k-ip32, sb1-bcm91250a, sb1a-bcm91480b
 +
      mipsel: 4kc-malta, 5kc-malta, r5k-cobalt, sb1-bcm91250a, sb1a-bcm91480b
 +
     powerpc: powerpc, powerpc-smp, powerpc64
 +
        s390: s390x, s390x-tape
 +
        sh4: sh7751r, sh7785lcr
 +
      sparc: sparc64, sparc64-smp
 +
    sparc64: sparc64, sparc64-smp
  
The following command prints very useful information (like how the BTRFS volume has been created):
+
====== vserver featureset ======
<pre>
+
# btrfs filesystem df /mnt     
+
Data, RAID0: total=409.50MB, used=0.00
+
Data: total=8.00MB, used=0.00
+
System, RAID1: total=8.00MB, used=4.00KB
+
System: total=4.00MB, used=0.00
+
Metadata, RAID1: total=204.75MB, used=28.00KB
+
Metadata: total=8.00MB, used=0.00
+
</pre>
+
By the way, as you can see, for the btrfs command the mount point should be specified, not one of the physical devices.
+
  
== Shrinking the volume ==
+
      amd64
 +
        i386: 686, 686-bigmem
 +
        ia64: itanium, mckinley
 +
    powerpc: powerpc, powerpc64
 +
        s390
 +
      sparc
 +
    sparc64
  
A common practice in system administration is to leave some head space, instead of using the whole capacity of a storage pool (just in case). With btrfs one can easily shrink volumes. Let's shrink the volume a bit (about 25%):
+
====== xen featureset ======
  
<pre>
+
      amd64
# btrfs filesystem resize -500m /mnt
+
        i386
# dh -h
+
/dev/loop1      2.6G  56K  1.8G  1% /mnt
+
</pre>
+
 
+
And yes, it is an on-line resize, there is no need to umount/shrink/mount. So no downtimes! :-) However, a BTRFS volume requires a minimal size... if the shrink is too aggressive the volume won't be resized:
+
  
<pre>
+
====== openvz featureset ======
# btrfs filesystem resize -1g /mnt 
+
Resize '/mnt' of '-1g'
+
ERROR: unable to resize '/mnt'
+
</pre>
+
  
== Growing the volume ==
+
      amd64
 
+
        i386
This is the opposite operation, you can make a BTRFS grow to reach a particular size (e.g. 150 more megabytes):
+
 
+
<pre>
+
# btrfs filesystem resize +150m /mnt
+
Resize '/mnt' of '+150m'
+
# dh -h
+
/dev/loop1      2.7G  56K  1.8G  1% /mnt
+
 
</pre>
 
</pre>
  
You can also take an ''"all you can eat"'' approach via the '''max''' option, meaning all of the possible space will be used for the volume:
+
Type <tt>config-extract -h</tt> for extended usage information:
  
 
<pre>
 
<pre>
# btrfs filesystem resize max /mnt
+
ninja1 linux-debian-2.6.32.30 # ./config-extract -h
Resize '/mnt' of 'max'
+
This work is free software.
# dh -h
+
/dev/loop1      3.0G  56K  1.8G  1% /mnt
+
</pre>
+
  
== Adding a new device to the BTRFS volume ==
+
Copyright 2011 Funtoo Technologies. You can redistribute and/or modify it under
 +
the terms of the GNU General Public License version 3 as published by the Free
 +
Software Foundation. Alternatively you may (at your option) use any other
 +
license that has been publicly approved for use with this program by Funtoo
 +
Technologies (or its successors, if any.)
  
To add a new device to the volume:
+
usage: config-extract [options] arch [featureset] [subarch]
  
<pre>
+
  -h  --help        print this usage and exit
# btrfs device add /dev/loop4 /mnt
+
  -l  --list        list all available kernel configurations
oxygen ~ # btrfs filesystem show /dev/loop4
+
  -o --outfile    specify kernel config outfile --
Label: none uuid: 0a774d9c-b250-420e-9484-b8f982818c09
+
                    defaults to .config in current directory
        Total devices 4 FS bytes used 28.00KB
+
  [featureset]      defaults to "none" if not specified
        devid    3 size 1.00GB used 263.94MB path /dev/loop2
+
  [subarch]         defaults to the only one available; otherwise required
         devid    4 size 1.00GB used 0.00 path /dev/loop4
+
        devid    1 size 1.00GB used 275.94MB path /dev/loop0
+
        devid    2 size 1.00GB used 110.38MB path /dev/loop1
+
</pre>
+
  
Again, no need to umount the volume first as adding a device is an on-line operation (the device has no space used yet hence the '0.00'). The operation is not finished as we must tell btrfs to prepare the new device (i.e. rebalance/mirror the metadata and the data between all devices):
+
This program was written by Daniel Robbins for Funtoo Linux, for the purpose of
 +
easily and conveniently extracting Debian kernel configurations. To see a nice
 +
list of all available kernel configurations, use the --list option.
  
<pre>
+
Debian's kernel configs are specified internally in arch_featureset_flavor
# btrfs filesystem balance /mnt
+
format, such as: "amd64_openvz_amd64". The featureset typically describes an
# btrfs filesystem show /dev/loop4
+
optional kernel configuration such as "xen" or "openvz", while the flavor in
Label: none  uuid: 0a774d9c-b250-420e-9484-b8f982818c09
+
Debian terminology typically refers to the sub-architecture of the CPU.
        Total devices 4 FS bytes used 28.00KB
+
        devid    3 size 1.00GB used 110.38MB path /dev/loop2
+
        devid    4 size 1.00GB used 366.38MB path /dev/loop4
+
        devid    1 size 1.00GB used 378.38MB path /dev/loop0
+
        devid    2 size 1.00GB used 110.38MB path /dev/loop1
+
</pre>
+
  
Depending on the sizes and what is in the volume a balancing operation could take several minutes or hours.
+
When using this command, you must specify an arch. A featureset of "none" is
 +
assumed unless you specify one, and by default this program will pick the only
 +
available subarch if there is only one to choose from. If not, you will need to
 +
pick one (and the program will remind you to do this.)
  
== Removing a device from the BTRFS volume ==
+
The kernel configuration will be written to ".config" in the current directory,
 
+
or the location you specified using the -o/--outfile option.
<pre>
+
# btrfs device delete /dev/loop2 /mnt
+
# btrfs filesystem show /dev/loop0 
+
Label: none  uuid: 0a774d9c-b250-420e-9484-b8f982818c09
+
        Total devices 4 FS bytes used 28.00KB
+
        devid    4 size 1.00GB used 264.00MB path /dev/loop4
+
        devid    1 size 1.00GB used 268.00MB path /dev/loop0
+
        devid    2 size 1.00GB used 0.00 path /dev/loop1
+
        *** Some devices missing
+
# df -h
+
Filesystem      Size  Used Avail Use% Mounted on
+
/dev/loop1      3.0G  56K  1.5G  1% /mnt
+
 
</pre>
 
</pre>
  
Here again removing a device is totally dynamic and can be done as on-line operation! Note that when a device is removed, its content is transparently redistributed among the other devices.
+
Let's use <tt>config-extract</tt> to create a kernel configuration for an amd64 system:
 
+
Obvious points:
+
* '''** DO NOT UNPLUG THE DEVICE BEFORE THE END OF THE OPERATION, DATA LOSS WILL RESULT**'''
+
* If you have used raid0 in either metadata or data at the BTRFS volume creation you will end in a unusable volume if one of the the devices fails before being properly removed from the volume as some stripes will be lost.
+
 
+
Once you add a new device to the BTRFS volume as a replacement for a removed one, you can cleanup the references to the missing device:
+
 
+
<pre>
+
# btrfs device delete missing
+
</pre>
+
 
+
== Using a BTRFS volume in degraded mode ==
+
 
+
{{fancywarning|It is not possible to use a volume in degraded mode if raid0 has been used for data/metadata and the device had not been properly removed with '''btrfs device delete''' (some stripes will be missing). The situation is even worse if RAID0 is used for the the metadata: trying to mount a BTRFS volume in read/write mode while not all the devices are accessible '''will simply kill the remaining metadata, hence making the BTRFS volume totally unusable'''... you have been warned! :-)}}
+
 
+
If you use raid1 or raid10 for data AND metadata and you have a usable submirror accessible (consisting of 1 drive in case of RAID1 or the two drive of the same RAID0 array in case of RAID10), you can mount the array in degraded mode in the case of some devices are missing (e.g. dead SAN link or dead drive) :
+
 
+
<pre>
+
# mount -o degraded /dev/loop0 /mnt
+
</pre>  
+
 
+
If you use RAID0 (and have one of your drives inaccessible) the metadata or RAID10 but not enough drives are on-line to even get a degraded mode possible, btrfs will refuse to mount the volume:
+
  
 
<pre>
 
<pre>
# mount /dev/loop0 /mnt
+
# cd linux
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
+
# ./config-extract amd64
      missing codepage or helper program, or other error
+
Wrote amd64_none_amd64 kernel configuration to /usr/src/linux-debian-2.6.32.30/.config.
      In some cases useful info is found in syslog - try
+
      dmesg | tail  or so
+
 
</pre>
 
</pre>
  
The situation is no better if you have used RAID1 for the metadata and RAID0 for the data, you can mount the drive in degraded mode but you will encounter problems while accessing your files:
+
<tt>config-extract</tt> also allows you to extract special Debian featuresets, such as settings for Xen and [[OpenVZ]] kernels:
  
 
<pre>
 
<pre>
# cp /mnt/test.dat /tmp
+
# ./config-extract amd64 openvz
cp: reading `/mnt/test.dat': Input/output error
+
Wrote amd64_openvz_amd64 kernel configuration to /usr/src/linux-debian-2.6.32.30/.config.
cp: failed to extend `/tmp/test.dat': Input/output error
+
 
</pre>
 
</pre>
  
= Playing with subvolumes and snapshots =
+
'''It is necessary to name the kernel configuration file something other than ".config" to avoid errors with genkernel.'''
  
== A story of boxes.... ==
 
  
When you think about subvolumes in BTRFS, think about boxes. Each one of those can contain items and other smaller boxes ("sub-boxes") which in turn can also contains items and boxes (sub-sub-boxes) and so on. Each box and items has a number and a name, except for the top level box, which has only a number (zero). Now imagine that all of the boxes are semi-opaque: you can see what they contain if you are outside the box but you can't see outside when you are inside the box. Thus, depending on the box you are in you can view either all of the items and sub-boxes (top level box) or only a part of them (any other box but the top level one). To give you a better idea of this somewhat abstract explanation let's illustrate a bit:
+
After using <tt>config-extract</tt>, run <tt>make oldconfig</tt> and accept all default options by hitting Enter at all prompts.
  
<pre>
+
=== Third step: Building and installing the kernel ===
(0) --+-> Item A (1)
+
      |
+
      +-> Item B (2)
+
      |
+
      +-> Sub-box 1 (3) --+-> Item C (4)
+
      |                  |
+
      |                  +-> Sub-sub-box 1.1 (5) --+-> Item D (6)
+
      |                  |                        |
+
      |                  |                        +-> Item E (7)
+
      |                  |                        |
+
      |                  |                        +-> Sub-Sub-sub-box 1.1.1 (8) ---> Item F (9)
+
      |                  +-> Item F (10)
+
      |
+
      +-> Sub-box 2 (11) --> Item G (12)                   
+
</pre>
+
  
What you see in the hierarchy depends on where you are (note that the top level box numbered 0 doesn't have a name, you will see why later). So:
+
This is simply achieved by:
* If you are in the node named top box (numbered 0) you see everything, i.e. things numbered 1 to 12
+
* If you are in "Sub-sub-box 1.1" (numbered 5), you see only things 6 to 9
+
* If you are in "Sub-box 2" (numbered 11), you only see what is numbered 12
+
 
+
Did you notice? We have two items named 'F' (respectively numbered 9 and 10). This is not a typographic error, this is just to illustrate the fact that every item lives its own peaceful existence in its own box. Although they have the same name, 9 and 10 are two distinct and unrelated objects (of course it is impossible to have two objects named 'F' in the same box, even they would be numbered differently).
+
 
+
== ... applied to BTRFS! (or, "What is a volume/subvolume?") ==
+
 
+
BTRFS subvolumes work in the exact same manner, with some nuances:
+
 
+
* First, imagine a frame that surrounds the whole hierarchy (represented in dots below). This is your BTRFS '''volume'''. A bit abstract at first glance, but BTRFS volumes have no tangible existence, they are just an ''aggregation'' of devices tagged as being clustered together (that fellowship is created when you invoke '''mkfs.btrfs''' or '''btrfs device add''').
+
* Second, the first level of hierarchy contains '''only''' a single box numbered zero which can never be destroyed (because everything it contains would also be destroyed).
+
 
+
If in our analogy of a nested boxes structure we used the word '''"box"''', in the real BTRFS word we use the word '''"subvolume"''' (box => subvolume). Like in our boxes analogy, all subvolumes hold a unique number greater than zero and a name, with the exception of root subvolume located at the very first level of the hierarchy which is ''always'' numbered zero and has no name (BTRFS tools destroy subvolumes by their name not their number so '''no name = no possible destruction'''.  This is a totally intentional architectural choice, not a flaw). 
+
 
+
Here is a typical hierarchy:
+
  
 
<pre>
 
<pre>
.....BTRFS Volume................................................................................................................................
+
# genkernel --kernel-config=config-2.6.32-5-amd64 all
.
+
.  Root subvolume (0) --+-> Subvolume SV1 (258) ---> Directory D1 --+-> File F1
+
.                       |                                          |
+
.                       |                                          +-> File F2
+
.                      |
+
.                      +-> Directory D1 --+-> File F1
+
.                      |                  |
+
.                      |                  +-> File F2
+
.                      |                  |
+
.                      |                  +-> File F3
+
.                      |                  |
+
.                      |                  +-> Directory D11 ---> File F4
+
.                      +-> File F1
+
.                      |
+
.                      +-> Subvolume SV2 (259) --+-> Subvolume SV21 (260)
+
.                                                |
+
.                                                +-> Subvolume SV22 (261) --+-> Directory D2 ---> File F4
+
.                                                                            |
+
.                                                                            +-> Directory D3 --+-> Subvolume SV221 (262) ---> File F5
+
.                                                                            |                  |
+
.                                                                            |                  +-> File F6
+
.                                                                            |                  |
+
.                                                                            |                  +-> File F7
+
.                                                                            |
+
.                                                                            +-> File F8
+
.
+
.....................................................................................................................................
+
 
</pre>
 
</pre>
  
Maybe you have a question: "Okay, What is the difference between a directory and a subvolume? Both can can contain something!". To further confuse you, here is what users get if they reproduce the first level hierarchy on a real machine:
+
* --kernel-config: use the given configfile. If you only give a filename here, it is searched for in your current working dir. You can also use a relative or an absolute path leading to your configfile here (for example: "--kernel-config=/usr/src/linux/configfile").
 +
* all: rebuild the kernel image and the initramfs ramdisk image (aside of kernel modules, the ramdisk image contains tools such as BusyBox and some generic startup scripts, depending on options you use on the command line several additional tools like lvm or raid volume management can be incorporated as well).
  
<pre>
+
{{ fancyimportant|Unless explicitly stated via ''--no-clean'' or ''--no-mrproper'', Genkernel will do a '''make mrproper''' in the kernel source tree, thus cleaning a previous build '''and removing the previous kernel configuration file''' in it.  
# ls -l
+
total 0
+
drwx------ 1 root root 0 May 23 12:48 SV1
+
drwxr-xr-x 1 root root 0 May 23 12:48 D1
+
-rw-r--r-- 1 root root 0 May 23 12:48 F1
+
drwx------ 1 root root 0 May 23 12:48 SV2
+
</pre>
+
 
+
Although subvolumes SV1 and SV2 have been created with special BTRFS commands they appear just as if they were ordinary directories! A subtle nuance exists, however: think again at our boxes analogy we did before and map the following concepts in the following manner:
+
 
+
* a subvolume : the semi-opaque '''box'''
+
* a directory : a ''sort of'' '''item''' (that can contain something even another subvolume)
+
* a file : ''another sort of'' '''item'''
+
 
+
So, in the internal filesystem metadata SV1 and SV2 are stored in a different manner than D1 (although this is transparently handled for users). You can, however see SV1 and SV2 for what they are (subvolumes) by running the following command (subvolume numbered (0) has been mounted on /mnt):
+
 
+
<pre>
+
# btrfs subvolume list /mnt
+
ID 258 top level 5 path SV1
+
ID 259 top level 5 path SV2
+
</pre>
+
 
+
What would we get if we create SV21 and SV22 inside of SV2? Let's try! Before going further you should be aware that a subvolume is created by invoking the magic command '''btrfs subvolume create''':
+
 
+
<pre>
+
# cd /mnt/SV2
+
# btrfs subvolume create SV21
+
Create subvolume './SV21'
+
# btrfs subvolume create SV22
+
Create subvolume './SV22'
+
# btrfs subvolume list /mnt 
+
ID 258 top level 5 path SV1
+
ID 259 top level 5 path SV2
+
ID 260 top level 5 path SV2/SV21
+
ID 261 top level 5 path SV2/SV22
+
</pre>
+
 
+
Again, invoking '''ls''' in /mnt/SV2 will report the subvolumes as being directories:
+
 
+
<pre>
+
# ls -l
+
total 0
+
drwx------ 1 root root 0 May 23 13:15 SV21
+
drwx------ 1 root root 0 May 23 13:15 SV22
+
</pre>
+
 
+
== Changing the point of view on the subvolumes hierarchy ==
+
 
+
At some point in our boxes analogy we have talked about what we see and what we don't see depending on our location in the hierarchy. Here lies a big important point: whereas most of the BTRFS users mount the root subvolume (subvolume id = 0, we will retain the ''root subvolume'' terminology) in their VFS hierarchy thus making visible the whole hierarchy contained in the BTRFS volume, it is absolutely possible to mount only a ''subset'' of it. How that could be possible? Simple: Just specify the subvolume number when you invoke mount. For example, to mount the hierarchy in the VFS starting at subvolume SV22 (261) do the following:
+
 
+
<pre>
+
# mount -o subvolid=261 /dev/loop0 /mnt
+
</pre>
+
 
+
Here lies an important notion not disclosed in the previous paragraph: although both directories and subvolumes can act as containers, '''only subvolumes can be mounted in a VFS hierarchy'''. It is a fundamental aspect to remember: you cannot mount a sub-part of a subvolume in the VFS; you can only mount the subvolume in itself. Considering the hierarchy schema in the previous section, if you want to access the directory D3 you have three possibilities:
+
 
+
# Mount the non-named subvolume (numbered 0) and access D3 through /mnt/SV2/SV22/D3 if the non-named subvolume is mounted in /mnt
+
# Mount the subvolume SV2 (numbered 259) and access D3 through /mnt/SV22/D3 if the the subvolume SV2 is mounted in /mnt
+
# Mount the subvolume SV22 (numbered 261) and access D3 through /mnt/D3 if the the subvolume SV22 is mounted in /mnt
+
 
+
This is accomplished by the following commands, respectively:
+
 
+
<pre>
+
# mount -o subvolid=0 /dev/loop0 /mnt
+
# mount -o subvolid=259 /dev/loop0 /mnt
+
# mount -o subvolid=261 /dev/loop0 /mnt
+
</pre>
+
 
+
{{fancynote|When a subvolume is mounted in the VFS, everything located "above" the subvolume is hidden. Concretely, if you mount the subvolume numbered 261 in /mnt, you only see what is under SV22, you won't see what is located above SV22 like SV21, SV2, D1, SV1, etc. }}
+
 
+
== The default subvolume ==
+
 
+
$100 questions:
+
1. "If I don't put 'subvolid' in the command line, 1. how does the kernel know which one of the subvolumes it has to mount?
+
2. Does Omitting the 'subvolid' means automatically 'mount subvolume numbered 0'?".
+
Answers:
+
1. BTRFS magic! ;-)
+
2. No, not necessarily, you can choose something other than the non-named subvolume.
+
 
+
When you create a brand new BTRFS filesystem, the system not only creates the initial the root subvolume (numbered 0) but also tags it as being the '''default subvolume'''. When you ask the operating system to mount a subvolume contained in a BTRFS volume without specifying a subvolume number, it determines which of the existing subvolumes has been tagged as "default subvolume" and mounts it. If none of the exiting subvolumes has the tag "default subvolume" (e.g. because the default subvolume has been deleted), the mount command gives up with a rather cryptic message:
+
 
+
<pre>
+
# mount /dev/loop0 /mnt
+
mount: No such file or directory
+
</pre>
+
 
+
It is also possible to change at any time which subvolume contained in a BTRFS volume is considered the default volume. This is accomplished with '''btrfs subvolume set-default'''. The following tags the subvolume 261 as being the default:
+
 
+
<pre>
+
# btrfs subvolume set-default 261 /mnt
+
</pre>
+
 
+
After that operation, doing the following is exactly the same:
+
 
+
<pre>
+
# mount /dev/loop0 /mnt
+
# mount -o subvolid=261 /dev/loop0 /mnt
+
</pre>
+
 
+
{{fancynote|The chosen new default subvolume must be visible in the VFS when you invoke ''btrfs subvolume set-default''' }}
+
 
+
== Deleting subvolumes ==
+
 
+
Question: "As subvolumes appear like directories, can I delete a subvolume by doing an rm -rf on it?".
+
Answer: Yes, you ''can'', but that way is not the most elegant, especially when it contains several gigabytes of data scattered on thousands of files, directories and maybe other subvolumes located in the one you want to remove. It isn't elegant because ''rm -rf'' could take several minutes (or even hours!) to complete whereas something else can do the same job in the fraction of a second.
+
 
+
"Huh?" Yes perfectly possible, and here is the cool goodie for the readers who arrived at this point: when you want to remove a subvolume, use '''btrfs subvolume delete''' instead of '''rm -rf'''. That btrfs command will remove the snapshots in a fraction of a second, even it contains several gigabytes of data!
+
 
+
{{fancywarning|* You can '''never''' remove the root subvolume of a BTRFS volume as '''btrfs delete''' expects a subvolume name (again: this is not a flaw in the design of BTRFS; removing the subvolume numbered 0 would destroy the entirety of a BTRFS volume...too dangerous).
+
* If the subvolume you delete was tagged as the default subvolume you will have to designate another default subvolume or explicitly tell the system which one of the subvolumes has to be mounted) }}
+
 
+
An example: considering our initial example given [[BTRFS_Fun#..._applied_to_BTRFS.21_.28or_what_is_a_volume.2Fsubvolume.29|above]] and supposing you have mounted non-named subvolume numbered 0 in /mnt, you can remove SV22 by doing:
+
 
+
<pre>
+
# btrfs subvolume delete /mnt/SV2/SV22
+
</pre>
+
 
+
Obviously the BTRFS volume will look like this after the operation:
+
 
+
<pre>
+
.....BTRFS Volume................................................................................................................................
+
.
+
.  (0) --+-> Subvolume SV1 (258) ---> Directory D1 --+-> File F1
+
.        |                                          |
+
.        |                                          +-> File F2
+
.        |
+
.        +-> Directory D1 --+-> File F1
+
.        |                  |
+
.        |                  +-> File F2
+
.        |                  |
+
.        |                  +-> File F3
+
.        |                  |
+
.        |                  +-> Directory D11 ---> File F4
+
.        +-> File F1
+
.        |
+
.        +-> Subvolume SV2 (259) --+-> Subvolume SV21 (260)
+
.....................................................................................................................................
+
</pre>
+
 
+
== Snapshot and subvolumes ==
+
 
+
If you have a good comprehension of what a subvolume is, understanding what a snapshot is won't be a problem: a snapshot is a subvolume with some initial contents. "Some initial contents" here means an exact copy.
+
 
+
When you think about snapshots, think about copy-on-write: the data blocks are not duplicated between a mounted subvolume and its snapshot unless you start to make changes to the files (a snapshot can occupy nearly zero extra space on the disk). At time goes on, more and more data blocks will be changed, thus making snapshots "occupy" more and more space on the disk. It is therefore recommended to keep only a minimal set of them and remove unnecessary ones to avoid wasting space on the volume.
+
 
+
 
+
The following illustrates how to take a snaphot of the VFS root:
+
<pre>
+
# btrfs subvolume snapshot / /snap-2011-05-23
+
Create a snapshot of '/' in '//snap-2011-05-23'
+
</pre>
+
 
+
Once created, the snapshot will persist in /snap-2011-05-23 as long as you don't delete it. Note that the snapshot contents will remain exactly the same it was at the time is was taken (as long as you don't make changes... BTRFS snapshots are writable!). A drawback of having snapshots: if you delete some files in the original filesystem, the snapshot still contains them and the disk blocks can't be claimed as free space. Remember to remove unwanted snapshots and keep a bare minimal set of them.
+
 
+
== Listing and deleting snaphots ==
+
 
+
As there is no distinction between a snapshot and a subvolume, snapshots are managed with the exact same commands, especially when the time has come to delete some of them. An interesting feature in BTRFS is that snapshots are writable. You can take a snapshot and make changes in the files/directories it contains.  A word of caution: there are no undo capbilities! What has been changed has been changed forever... If you need to do several tests just take several snapshots or, better yet, snapshot your snapshot then do whatever you need in this copy-of-the-copy :-).
+
 
+
== Using snapshots for system recovery (aka Back to the Future) ==
+
 
+
Here is where BTRFS can literally be a lifeboat. Suppose you want to apply some updates via '''emerge -uaDN @world''' but you want to be sure that you can jump back into the past in case something goes seriously wrong after the system update (does libpng14 remind you of anything?!). Here is the "putting-things-together part" of the article!
+
 
+
The following only applies if your VFS root and system directories containing '''/sbin, /bin, /usr, /etc....''' are located on a BTRFS volume. To make things simple, the whole structure is supposed to be located in the SAME subvolume of the same BTRFS volume.
+
 
+
To jump back into the past you have at least two options:
+
 
+
# Fiddle with the default subvolume numbers
+
# Use the kernel command line parameters in the bootloader configuration files
+
 
+
In all cases you must take a snapshot of your VFS root *before* updating the system:
+
 
+
<pre>
+
# btrfs subvolume snapshot / /before-updating-2011-05-24
+
Create a snapshot of '/' in '//before-updating-2011-05-24'
+
</pre>
+
 
+
{{fancynote|Hint: You can create an empty file at the root of your snapshot with the name of your choice to help you easily identify which subvolume is the currently mounted one (e.g. if the snapshot has been named '''before-updating-2011-05-24''', you can use a slightly different name like '''current-is-before-updating-2011-05-24''' <nowiki>=></nowiki> '''touch /before-updating-2011-05-24/current-is-before-updating-2011-05-24'''). This is extremly useful if you are dealing with several snapshots.}}
+
 
+
There is no "better" way; it's just a question of personal preference.
+
 
+
=== Way #1: Fiddle with the default subvolume number ===
+
 
+
'''Hypothesis:
+
* Your "production" VFS root partition resides in the root subvolume (subvolid=0),'''
+
* Your /boot partition (where the bootloader configuration files are stored) is on another standalone partition
+
 
+
First search for the newly created subvolume number:
+
 
+
<pre>
+
# btrfs subvolume list /
+
'''ID 256''' top level 5 path before-updating-2011-05-24
+
</pre>
+
 
+
'256' is the ID to be retained (of course, this ID will differ in your case).
+
 
+
Now, change the default subvolume of the BTRFS volume to designate the subvolume (snapshot) ''before-updating'' and not the root subvolume then reboot:
+
 
+
<pre>
+
# btrfs subvolume set-default 256 /
+
</pre>
+
 
+
Once the system has rebooted, and if you followed the advice in the previous paragraph that suggests to create an empty file of the same name as the snapshot, you should be able to see if the mounted VFS root is the copy hold by the snapshot ''before-updating-2011-05-24'':
+
 
+
<pre>
+
# ls -l /
+
...
+
-rw-rw-rw-  1 root root    0 May 24 20:33 current-is-before-updating-2011-05-24
+
...
+
</pre>
+
 
+
The correct subvolume has been used for mounting the VFS!  Excellent! This is now the time to mount your "production" VFS root (remember the root subvolume can only be accessed via its identification number i.e ''0''):
+
 
+
<pre>
+
# mount -o subvolid=0 /mnt
+
# mount
+
...
+
/dev/sda2 on /mnt type btrfs (rw,subvolid=0)
+
</pre>
+
 
+
Oh by the way, as the root subvolume is now mounted in /mnt let's try something, just for the sake of the demonstration:
+
 
+
<pre>
+
# ls /mnt
+
...
+
drwxr-xr-x  1 root root    0 May 24 20:33 current-is-before-updating-2011-05-24
+
...
+
# btrfs subvolume list /mnt
+
ID 256 top level 5 path before-updating-2011-05-24
+
</pre>
+
 
+
No doubt possible :-)
+
Time to rollback! For this '''rsync''' will be used in the following way:
+
<pre>
+
# rsync --progress -aHAX --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/mnt / /mnt
+
</pre>
+
 
+
Basically we are asking rsync to:
+
* preserve timestamps, hard and symbolic links, owner/group IDs, ACLs and any extended attributes (refer to the rsync manual page for further details on options used) and to report its progression
+
* ignore the mount points where virtual filesystems are mounted (procfs, sysfs...)
+
* avoid a re-recursion by reprocessing /mnt (you can speed up the process by adding some extra directories if you are sure they don't hold any important changes or any change at all like /var/tmp/portage for example).
+
 
+
Be patient! The resync may take several minutes or hours depending on the amount of data amount to process...
+
 
+
Once finished, you will have to set the default subvolume to be the root subvolume:
+
 
+
<pre>
+
# btrfs subvolume set-default 0 /mnt
+
ID 256 top level 5 path before-updating-2011-05-24
+
</pre>
+
 
+
{{fancywarning|'''DO NOT ENTER / instead of /mnt in the above command; it won't work and you will be under the snapshot before-updating-2011-05-24 the next time the machine reboots.'''
+
 
+
The reason is that subvolume number must be "visible" from the path given at the end of the '''btrfs subvolume set-default''' command line. Again refer the boxes analogy: in our context we are in a subbox numbered 256 which is located *inside* the box numbered 0 (so it can't see neither interfere with it). [TODO: better explain]
+
 
}}
 
}}
  
Now just reboot and you should be in business again! Once you have rebooted just check if you are really under the right subvolume:
+
If you use Genkernel to rebuild a Linux kernel on SPARC64, remember to either:
 
+
* Set '''sparc64-unknown-linux-gnu-''' in ''General setup --> Cross-compiler tool prefix''  
<pre>
+
* Put '''--kernel-cross-compile=sparc64-unknown-linux-gnu-''' on the Genkernel command line
# ls /
+
...
+
drwxr-xr-x  1 root root    0 May 24 20:33 current-is-before-updating-2011-05-24
+
...
+
# btrfs subvolume list /
+
ID 256 top level 5 path before-updating-2011-05-24
+
</pre>
+
 
+
At the right place? Excellent! You can now  delete the snapshot if you wish, or better: keep it as a lifeboat of "last good known system state."
+
 
+
=== Way #2: Change the kernel command line in the bootloader configuration files ===
+
 
+
First search for the newly created subvolume number:
+
 
+
<pre>
+
# btrfs subvolume list /
+
'''ID 256''' top level 5 path before-updating-2011-05-24
+
</pre>
+
 
+
'256' is the ID to be retained (can differ in your case).
+
 
+
Now with your favourite text editor, edit the adequate kernel command line in your bootloader configuration. This file contains is typically organized in several sections (one per kernel present on the system plus some global settings), like the excerpt below:
+
 
+
<pre>
+
set timeout=5
+
set default=0
+
 
+
# Production kernel
+
menuentry "Funtoo Linux production kernel (2.6.39-gentoo x86/64)" {
+
  insmod part_msdos
+
  insmod ext2
+
  ...
+
  set root=(hd0,1)
+
  linux /kernel-x86_64-2.6.39-gentoo root=/dev/sda2
+
  initrd /initramfs-x86_64-2.6.39-gentoo
+
}
+
...
+
</pre>
+
 
+
Find the correct kernel line and add one of the following statements after root=/dev/sdX:
+
 
+
<pre>
+
rootflags=subvol=before-updating-2011-05-24
+
  - Or -
+
rootflags=subvolid=256
+
</pre>
+
 
+
{{fancywarning|If the kernel your want to use has been generated with Genkernel, you '''MUST''' use ''real_rootflags<nowiki>=</nowiki>subvol<nowiki>=</nowiki>''... instead of ''rootflags<nowiki>=</nowiki>subvol''<nowiki>=</nowiki>... at the penalty of not having your rootflags taken into consideration by the kernel on reboot. }}
+
 
+
 
+
Applied to the previous example you will get the following if you referred the subvolume by its name:
+
 
+
<pre>
+
set timeout=5
+
set default=0
+
 
+
# Production kernel
+
menuentry "Funtoo Linux production kernel (2.6.39-gentoo x86/64)" {
+
  insmod part_msdos
+
  insmod ext2
+
  ...
+
  set root=(hd0,1)
+
  linux /kernel-x86_64-2.6.39-gentoo root=/dev/sda2 rootflags=subvol=before-updating-2011-05-24
+
  initrd /initramfs-x86_64-2.6.39-gentoo
+
}
+
...
+
</pre>
+
 
+
Or you will get the following if you referred the subvolume by its identification number:
+
 
+
<pre>
+
set timeout=5
+
set default=0
+
 
+
# Production kernel
+
menuentry "Funtoo Linux production kernel (2.6.39-gentoo x86/64)" {
+
  insmod part_msdos
+
  insmod ext2
+
  ...
+
  set root=(hd0,1)
+
  linux /kernel-x86_64-2.6.39-gentoo root=/dev/sda2 rootflags=subvolid=256
+
  initrd /initramfs-x86_64-2.6.39-gentoo
+
}
+
...
+
</pre>
+
 
+
Once the modifications are done, save your changes and take the necessary extra steps to commit the configuration changes on the first sectors of the disk if needed (this mostly applies to the users of LILO; Grub and SILO do not need to be refreshed) and reboot.
+
 
+
Once the system has rebooted and if you followed the advice in the previous paragraph that suggests to create an empty file of the same name as the snapshot, you should be able to see if the mounted VFS root is the copy hold by the snapshot ''before-updating-2011-05-24'':
+
 
+
<pre>
+
# ls -l /
+
...
+
-rw-rw-rw-  1 root root    0 May 24 20:33 current-is-before-updating-2011-05-24
+
...
+
</pre>
+
 
+
The correct subvolume has been used for mounting the VFS!  Excellent! This is now the time to mount your "production" VFS root (remember the root subvolume can only be accessed via its identification number 0):
+
 
+
<pre>
+
# mount -o subvolid=0 /mnt
+
# mount
+
...
+
/dev/sda2 on /mnt type btrfs (rw,subvolid=0)
+
</pre>
+
 
+
Time to rollback! For this '''rsync''' will be used in the following way:
+
<pre>
+
# rsync --progress -aHAX --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/mnt / /mnt
+
</pre>
+
 
+
Here, please refer to what has been said in [[BTRFS_Fun#Way_.231:_Fiddle_with_the_default_subvolume_number|Way #1]] concerning the used options in rsync. Once everything is in place again, edit your bootloader configuration to remove the rootflags/real_rootflags kernel parameter, reboot and check if you are really under the right subvolume:
+
 
+
<pre>
+
# ls /
+
...
+
drwxr-xr-x  1 root root    0 May 24 20:33 current-is-before-updating-2011-05-24
+
...
+
# btrfs subvolume list /
+
ID 256 top level 5 path current-is-before-updating-2011-05-24
+
</pre>
+
 
+
At the right place? Excellent! You can now  delete the snapshot if you wish, or better: keep it as a lifeboat of "last good known system state."
+
 
+
= Some BTRFS practices / returns of experience / gotchas =
+
 
+
* Although BTRFS is still evolving, at the date of writing it (still) is '''an experimental filesystem and should be not be used for production systems and for storing critical data''' (even if the data is non critical, having backups on a partition formatted with a "stable" filesystem like Reiser or ext3/4 is recommended).
+
* From time to time some changes are brought to the metadata (BTRFS format is not definitive at date of writing) and a BTRFS partition could not be used with older Linux kernels (this happened with Linux 2.6.31).
+
* More and more Linux distributions are proposing the filesystem as an alternative for ext4
+
* Some reported gotchas: [https://btrfs.wiki.kernel.org/index.php/Gotchas https://btrfs.wiki.kernel.org/index.php/Gotchas]
+
* Playing around with BTFRS can be a bit tricky especially when dealing with default volumes and mount point (again: the box analogy)
+
* Using compression (e.g. LZO =>> mount -o compress=lzo) on the filesystem can improve the throughput performance, however many files nowadays are already compressed at application level (music, pictures, videos....).
+
* Using space caching capabilities (mount -o space_cache) seems to brings some extra slight performance improvements.
+
* There is very [https://lkml.org/lkml/2010/6/18/144 interesting discussion on BTRFS design limitations with B-Trees] lying on LKML. We ''strongly'' encourage you to read about on
+
 
+
== Deploying a Funtoo instance in a subvolume other than the root subvolume ==
+
 
+
Some Funtoo core devs have used BTRFS for many months and no major glitches have been reported so far (except an non-aligned memory access trap on SPARC64 in a checksum calculation routine; minor latest kernels may brought a correction) except a long time ago but this was more related to a kernel crash due to a bug that corrupted some internal data rather than the filesystem code in itself.
+
 
+
The following can simplify your life in case of recovery '''(not tested)''':
+
 
+
When you prepare the disk space that will hold the root of your future Funtoo instance (and so, will hold /usr /bin /sbin /etc etc...), don't use the root subvolume but take an extra step to define a subvolume like illustrated below:
+
 
+
<pre>
+
# fdisk /dev/sda2
+
....
+
# mkfs.btrfs /dev/sda2
+
# mount /dev/sda2 /mnt/funtoo
+
# subvolume create /mnt/funtoo /mnt/funtoo/live-vfs-root-20110523
+
# chroot /mnt/funtoo/live-vfs-root-20110523 /bin/bash
+
</pre>
+
 
+
Then either:
+
 
+
* Set the default subvolume /live-vfs-root-20110523 as being the default subvolume (btrfs subvolume set-default.... remember to inspect the subvolume identification number)
+
* Use rootflag / real_rootfsflags (always use real_rootfsflags for kernel generated with Genkernel) on the kernel command line in your bootloader configuration file
+
 
+
Technically speaking, it won't change your life BUT at system recovery: when you want to rollback to a functional VFS root copy because something happened (buggy system package, too aggressive cleanup that removed Python, dead compiling toolchain...) you can avoid a time costly rsync but at the cost of putting a bit of overhead over your shoulders when taking a snapshot.
+
 
+
Here again you have two ways to recover the system:
+
 
+
* '''fiddling with the default subvolume:'''
+
** Mount to the no named volume somewhere (e.g. '''mount -o subvolid=0 /dev/sdX /mnt''')
+
** Take a snapshot (remember to check its identification number) of your current subvolume and store it under the root volume you just have just mounted ('''btrfs snapshot create / /mnt/before-updating-20110524''') -- (Where is the "frontier"? If 0 is monted does its contennts also appear in the taken snashot located on the same volume?)
+
** Update your system or do whatever else "dangerous" operation
+
** If you need to return to the latest good known system state, just set the default subvolume to use to the just taken snapshot ('''btrfs subvolume set-default ''<snapshotnumber here>'' /mnt''')
+
** Reboot
+
** Once you have  rebooted, just mount the root subvolume again and delete the subvolume that correspond to the failed system update ('''btrfs subvolume delete /mnt/<buggy VFS rootsnapshot name here>''')
+
 
+
* '''fiddling with the kernel command line:'''
+
** Mount to the no named volume somewhere (e.g. '''mount -o subvolid=0 /dev/sdX /mnt''')
+
** Take a snapshot (remember to check its identification number) of your current subvolume and store it under the root volume you just have just mounted ('''btrfs snapshot create / /mnt/before-updating-20110524''') -- (Where is the "frontier"? If 0 is mounted does its contents also appear in the taken snapshot located on the same volume?)
+
** Update your system or do whatever else "dangerous" operation
+
** If you need to return to the latest good known system state, just set the rootflags/real_rootflags as demonstrated in previous paragraphs in your loader configuration file
+
** Reboot
+
** Once you have  rebooted, just mount the root subvolume again and delete the subvolume that correspond to the failed system update ('''btrfs subvolume delete /mnt/<buggy VFS rootsnapshot name here>''')
+
 
+
== Space recovery / defragmenting the filesystem ==
+
 
+
From time to time it is advised to ask for re-optimizing the filesystem structures and data blocks in a subvolume. In BTRFS terminology this is called a defragmentation and it only be performed when the subvolume is mounted in the VFS (online defragmentation):
+
 
+
<pre>
+
# btrfs filesystem defrag /mnt
+
</pre>
+
 
+
You can still access the subvolume, even change its contents, while a defragmentation is running.
+
 
+
It is also a good idea to remove the snapshots you don't use anymore especially if huge files and/or lots of files are changed because snapshots will still hold some blocks that could be reused.
+
 
+
== SSE 4.2 boost ==
+
 
+
If your CPU supports hardware calculation of CRC32 (e.g. since Intel Nehalem series and later and AMD Bulldozer series), you are encouraged to enable that support in your kernel since BTRFS makes an aggressive use of those. Just check you have enabled ''CRC32c INTEL hardware acceleration'' in  ''Cryptographic API'' either as a module or as a built-in feature
+
 
+
= Recovering an apparent dead BTRFS filesystem =
+
 
+
Dealing with a filesystem metadata coherence is a critical in  a filesystem design. Losing some data blocks (i.e. having some corrupted files) is less critical than having a screwed-up and unmountable filesystem especially if you do backups on a regular basis '''(the rule with BTRFS is *do backups*, BTRFS has no mature filesystem repair tool and you *will* end up in having to re-create your filesystem from scratch again sooner or later).'''
+
 
+
== Mounting with recovery option (Linux 3.2 and beyond) ==
+
 
+
If you are using '''Linux 3.2 and later (only!)''', you can use the ''recovery'' option to make BTRFS seek for a usable copy of tree root (several copies of it exists on the disk). Just mount your filesystem as:
+
 
+
<pre>
+
# mount -o recovery /dev/yourBTFSvolume /mount/point
+
</pre>
+
 
+
== btrfs-select-super / btrfs-zero-log ==
+
 
+
Two other handy tools exist but they are not deployed by default by ''sys-fs/btrfs-progs'' (even ''btrfs-progs-9999'') ebuilds because they only lie in the branch ''"next"'' of the'' btrfs-progs'' Git repository:
+
 
+
* btrfs-select-super
+
* btrfs-zero-log
+
 
+
=== Building the btrfs-progs goodies ===
+
+
The two tools this section is about are not build by default and Funtoo ebuilds does not build them as well for the moment. So you must build them manually:
+
 
+
<pre>
+
# mkdir ~/src
+
# cd ~/src
+
# git clone git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git
+
# cd btrfs-progs
+
# make && make btrfs-select-super && make btrfs-zero-log
+
</pre>
+
 
+
{{fancynote|In the past, ''btrfs-select-super'' and ''btrfs-zero-log'' were lying in the git-next branch, this is no longer the case and those tools are available in the master branch }}
+
 
+
=== Fixing dead superblock ===
+
 
+
In case of a corrupted superblock, start by asking btrfsck to use an alternate copy of the superblock instead of the superblock #0. This is achieved via the -s option followed by the number of the alternate copy you wish to use. In the following example we ask for using the superblock copy #2 of /dev/sda7:
+
 
+
<pre>
+
# ./btrfsck --s 2 /dev/sd7
+
</pre>
+
 
+
When btrfsck is happy, use btrfs-super-select to restore the default superblock (copy #0) with a clean copy.  In the following example we ask for restoring the superblock of /dev/sda7 with its copy #2:
+
 
+
<pre>
+
# ./btrfs-super-select -s 2  /dev/sda7
+
</pre>
+
 
+
Note that this will overwrite all the other supers on the disk, which means you really only get one shot at it. 
+
 
+
'''If you run btrfs-super-select prior prior to figuring out which one is good, you've lost your chance to find a good one.'''
+
 
+
=== Clearing the BTRFS journal ===
+
 
+
''' This will only help with one specific problem! '''
+
 
+
If you are unable to mount a BTRFS partition after a hard shutdown, crash or power loss, it may be due to faulty log playback in kernels prior to 3.2.  The first thing to try is updating your kernel, and mounting.  If this isn't possible, an alternate solution lies in truncating the BTRFS journal, but only if you see "replay_one_*" functions in the oops callstack.
+
 
+
To truncate the journal of a BTRFS partition (and thereby lose any changes that only exist in the log!), just give the filesystem to process to ''btrfs-zero-log'':
+
 
+
<pre>
+
# ./btrfs-zero-log /dev/sda7
+
</pre>
+
 
+
This is not a generic technique, and works by permanently throwing away a small amount of potentially good data.
+
 
+
== Using btrfsck ==
+
 
+
{{fancywarning|Extremely experimental...}}
+
 
+
If one thing is famous in the BTRFS world it would be the so-wished fully functional ''btrfsck''. A read-only version of the tool was existing out there for years, however at the begining of 2012, BTRFS developers made a public and very experimental release: the secret jewel lies in the branch ''dangerdonteveruse'' of the BTRFS Git repository hold by Chris Mason on kernel.org.
+
 
+
<pre>
+
# git clone git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git
+
# cd btrfs-progs
+
# git checkout dangerdonteveruse
+
# make
+
</pre>
+
 
+
So far the tool can:
+
* Fix errors in the extents tree and in blocks groups accounting
+
* Wipe the CRC tree and create a brand new one (you can to mount the filesystem with CRC checking disabled )
+
 
+
To repair:
+
 
+
<pre>
+
# btrfsck --repair /dev/''yourBTRFSvolume''
+
</pre>
+
 
+
To wipe the CRC tree:
+
<pre>
+
# btrfsck --init-csum-tree /dev/''yourBTRFSvolume''
+
</pre>
+
 
+
Two other options exist in the source code: ''--super'' (equivalent of btrfs-select-super ?) and ''--init-extent-tree'' (clears out any extent?)
+
 
+
= Final words =
+
 
+
We give the great lines here but BTRFS can be very tricky especially when several subvolumes coming from several BTRFS volumes are used. And remember: BTRFS is still experimental at date of writing :)
+
  
== Lessons learned ==
+
Once the kernel has been compiled and the ram disk has been generated, the kernel image plus its companion files (initramfs image and System.map) are placed in the /boot directory. You can use your favourite tool to update your bootloader configuration files.
* Very interesting but still lacks some important features present in ZFS like RAID-Z, virtual volumes, management by attributes, filesystem streaming, etc.
+
* Extremly interesting for Gentoo/Funtoo systems partitions (snapshot/rollback capabilities). However not integrated in portage yet.
+
* If possible, use a file monitoring tool like TripWire this is handy to see what file has been corrupted once the filesystem is recovered or if a bug happens
+
* '''It is highly advised to not use the root subvolume when deploying a new Funtoo instance''' or put any kind of data on it in a more general case. Rolling back a data snapshot will be much easier and much less error prone (no copy process, just a matter of 'swapping' the subvolumes).
+
* Backup, backup backup your data! ;)
+
  
[[Category:Labs]]
+
[[Category:Internals]]
[[Category:Articles]]
+
[[Category:Funtoo features]]
[[Category:Featured]]
+
[[Category:Kernel]]
[[Category:Filesystems]]
+

Revision as of 03:26, 10 December 2013

This Section will give you an overview of kernels used in funtoo.

Funtoo Linux provides a number of new kernels for your use. This is the official page for all Funtoo Linux kernel information.

Some points of interest:

  • Most Funtoo Linux kernels support the handy binary USE flag, described below.
  • Funtoo Linux offers quality kernels from other Linux Distributions, like ubuntu-server and debian-sources.
  • A detailed Kernel Features and Stability table can be found below.
  • Advanced users may want to take a look at Additional Kernel Resources.
  • There is a quick'n dirty howto to compile your own kernel with initramfs the funtoo way.

Contents

Overview of Kernels

sysrescue-std-sources

This kernel is from the SystemRescueCD project, and is based on Fedora 14/15, plus some other patches related to booting from a live CD. It is a quality kernel, and is generally pretty stable. It is not suitable for production servers but is a good choice for Funtoo Linux desktops. Earlier,the Funtoo Linux Installation Guide recommended this kernel for general users, but now 'debian-sources' is recommended. Note however, that by design all audio functions are removed from SystemRescue, ie no sound when using this kernel.

vanilla-sources

This will install the "vanilla" (unmodified) Linux kernel sources. Current recommended version is 3.x. Funtoo Linux fully supports Linux 3.x. The advantages of this kernel include recent improvements to Linux Containers, a very modern networking stack with lots of bug fixes, and high reliability for desktops and servers. The downside is that this kernel must be manually configured by the user and does not have built-in genkernel support via the binary USE flag at this time.

gentoo-sources

This kernel tree is based on stable kernels from kernel.org with genpatches applied genpatches. Gentoo patchset aims to support the entire range of Gentoo-supported architectures. List of available genpatched kernels: genpatches-kernels

openvz-rhel6-stable

This is a RHEL6-based kernel with OpenVZ support. This kernel is now the preferred kernel for production OpenVZ deployments. It requires gcc-4.4.5 to build, which it will use automatically without the user needing to use gcc-config. We use this version of gcc since this is the version of gcc used by Red Hat to build this kernel.

openvz-rhel5-stable

This kernel is based on the latest Red Hat Enterprise Linux 5.6 kernel, and contains additional OpenVZ (virtual containers) patches from the OpenVZ project. It is a very stable and reliable kernel, and is recommended for use in production environments. The only major downside to this kernel is that it is based on Linux 2.6.18 -- some parts of the kernel are out-of-date, and it is not compatible with modern versions of udev. However, it is pretty trivial to downgrade udev to an earlier version on Funtoo Linux and this kernel has a track-record of being rock-solid. When stability is paramount, you put up with the udev downgrade, use this kernel, and can enjoy hundreds of days of uptime. For more information on how to use this kernel with Funtoo Linux, see the RHEL5 Kernel HOWTO.

ubuntu-server

This is the kernel from Ubuntu Server. Version 2.6.32.32.62 is the same version used in Ubuntu Server 10.04 LTS, and version 2.6.35.28.50 is the one used in Ubuntu Server 10.10 (currently masked). In our testing of 2.6.32.32.62, it has been very reliable and offers very good performance. One exception, which is common among 2.6.32-based kernels, is that it's recommended that you emerge broadcom-netxtreme2 if you have any Broadcom-based NICs, as the in-kernel drivers have compatibility issues with certain models. This kernel is a very good option if you want a relatively modern server kernel and do not need OpenVZ support. We use gcc-4.4.5 to build this kernel. It will use gcc-4.4.5 automatically, without requiring the user to use gcc-config.

debian-sources

This is the Debian kernel. These ebuilds now support the binary USE flag. Daniel has added a special config-extract command which can be used to list all available official Debian kernel configurations, and generate them from the Debian files included with the kernel. This kernel has optional OpenVZ support, but it is much better to use openvz-rhel6-stable if you want a production-quality OpenVZ installation. For more information about how to use debian-sources and config-extract, see Using debian-sources with Genkernel below.

debian-sources-lts

This is the Debian long-term stable kernel. These ebuilds now support the binary USE flag. Daniel has added a special config-extract command which can be used to list all available official Debian kernel configurations, and generate them from the Debian files included with the kernel.

Binary USE

Many of the kernel ebuilds in Funtoo Linux support the very useful binary USE flag. By enabling this USE flag and emerging the kernel, the ebuild will automatically build a binary kernel image, initramfs and kernel modules and install them to /boot. The binary kernel image and initramfs can be used to boot your Funtoo Linux system without requiring any additional configuration. This is a great way to get a Funtoo Linux system up and running quickly. Here's how to do it:

# echo "sys-kernel/openvz-rhel5-stable binary" >> /etc/portage/package.use
# emerge openvz-rhel5-stable
# nano -w /etc/boot.conf
# boot-update

More information can be found in the Funtoo Linux Installation Guide.

Funtoo Linux Genkernel

Funtoo Linux contains a forked/enhanced version of genkernel with the following new capabilities:

  • genkernel can use a build directory that is separate from the kernel source directory. This is enabled using the new --build-dst option.
  • --build-src is a new option that is equivalent to the --kerneldir option.
  • --fullname can be used to specify the entire name of the kernel and initramfs images -- everything after kernel- and initramfs-.
  • --firmware-src - a new option that works identically to --firmware-dir.
  • --firmware-dst - a new capability - you can now define where genkernel installs firmware.
  • Genkernel uses Funtoo Linux lvm2 rather than building its own.
  • Some compile fixes.

Kernel Features and Stability

This page provides an overview of kernel features and stability information:

Kernel Name Version USE flags Stability Extra Features Req'd udev Notes
vanilla-sources 3.12.4 N/A Excellent - recommended for desktops and servers. N/A Any Recommended for modern networking stack, hardware and Linux Containers support. This kernel must be manually configured by the user. New Features: kernelnewbies.org/linux_3.11 New Drivers: kernelnewbies/Linux_3.11-DriversArch
gentoo-sources 3.12.4 N/A Excellent - recommended for desktops and workstations N/A Any Recommended for modern networking stack, hardware and Linux Containers support. This kernel must be manually configured by the user. New Features: kernelnewbies.org/linux_3.11 New Drivers: kernelnewbies/Linux_3.11-DriversArch
sysrescue-std-sources 3.0.21.302 binary Good - recommended for desktops N/A Any Nvidia card users: binary use flag installs nouveau drivers. Not compatible with nvidia-drivers.
openvz-rhel6-stable 2.6.32.042.079.5 binary Excellent - recommended for production servers N/A Any This kernel is built with gcc-4.4.5. emerge broadcom-netxtreme2 for reliable BCM5709+ support (integrated NIC)
openvz-rhel5-stable 2.6.18.028.095.1 binary Excellent - recommended for production servers OpenVZ =sys-fs/udev-146* Broadcom bnx2 driver module bundled with kernel appears to be OK. This kernel is built with gcc-4.1.2. Enabling the binary USE flag will cause gcc-4.1.2 to be emerged and used for building the kernel.
ubuntu-server 2.6.32.32.62 binary Excellent - recommended for production servers (still in extended testing) N/A Any This kernel is built with gcc-4.4.5. emerge broadcom-netxtreme2 for reliable BCM5709+ support (integrated NIC)
ubuntu-server 2.6.35.28.50 binary not yet tested N/A Any This kernel is built with gcc-4.4.5. emerge broadcom-netxtreme2 for reliable BCM5709+ support (integrated NIC)
debian-sources 3.11.5 openvz Good - default kernel recommended by Funtoo OpenVZ (optional) Any See #Using debian-sources with Genkernel, below.

Using Debian-Sources with Genkernel

Important: Debian-sources is now fully compatible with binary USE flag and recommended for desktop users. The below example is valid for manual installation. At least 12G of /var/tmp required to build

This section describes how to build a binary kernel with debian-sources and genkernel, and it also explains how to use Funtoo Linux's config-extract tool to list and create official Debian kernel configurations.

First step: emerging the required packages

The first step is to emerge:

  1. The Debian sources
  2. Genkernel itself

This is achieved with:

# emerge sys-kernel/debian-sources sys-kernel/genkernel

Once the Debian kernel sources are deployed, you should find a directory named linux-debian-version (e.g. linux-debian-2.6.32.30) under /usr/src. Update your the linux symlink to point on this directory:

# cd /usr/src
# rm linux
# ln -s linux-debian-2.6.32.30 linux

Alternatively, emerge the debian-sources with USE="symlink"

Second step: Grabbing a configuration file

If is now time to download the kernel configuration file. For this tutorial we will use a configuration file for AMD64 (several others architectures like MIPS or SPARC64 are available.) To view a complete list of available kernel configurations, type ./config-extract -l in the Debian kernel source directory:

ninja1 linux-debian-2.6.32.30 # ./config-extract -l

====== standard featureset ======

       alpha: alpha-generic, alpha-legacy, alpha-smp
       amd64
       armel: iop32x, ixp4xx, kirkwood, orion5x, versatile
        hppa: parisc, parisc-smp, parisc64, parisc64-smp
        i386: 486, 686, 686-bigmem, amd64
        ia64: itanium, mckinley
        m68k: amiga, atari, bvme6000, mac, mvme147, mvme16x
        mips: 4kc-malta, 5kc-malta, r4k-ip22, r5k-ip32, sb1-bcm91250a, sb1a-bcm91480b
      mipsel: 4kc-malta, 5kc-malta, r5k-cobalt, sb1-bcm91250a, sb1a-bcm91480b
     powerpc: powerpc, powerpc-smp, powerpc64
        s390: s390x, s390x-tape
         sh4: sh7751r, sh7785lcr
       sparc: sparc64, sparc64-smp
     sparc64: sparc64, sparc64-smp

====== vserver featureset ======

       amd64
        i386: 686, 686-bigmem
        ia64: itanium, mckinley
     powerpc: powerpc, powerpc64
        s390
       sparc
     sparc64

====== xen featureset ======

       amd64
        i386

====== openvz featureset ======

       amd64
        i386

Type config-extract -h for extended usage information:

ninja1 linux-debian-2.6.32.30 # ./config-extract -h
This work is free software.

Copyright 2011 Funtoo Technologies. You can redistribute and/or modify it under
the terms of the GNU General Public License version 3 as published by the Free
Software Foundation. Alternatively you may (at your option) use any other
license that has been publicly approved for use with this program by Funtoo
Technologies (or its successors, if any.)

usage: config-extract [options] arch [featureset] [subarch]

  -h  --help        print this usage and exit
  -l  --list        list all available kernel configurations
  -o  --outfile     specify kernel config outfile --
                    defaults to .config in current directory
  [featureset]      defaults to "none" if not specified
  [subarch]         defaults to the only one available; otherwise required

This program was written by Daniel Robbins for Funtoo Linux, for the purpose of
easily and conveniently extracting Debian kernel configurations. To see a nice
list of all available kernel configurations, use the --list option.

Debian's kernel configs are specified internally in arch_featureset_flavor
format, such as: "amd64_openvz_amd64". The featureset typically describes an
optional kernel configuration such as "xen" or "openvz", while the flavor in
Debian terminology typically refers to the sub-architecture of the CPU.

When using this command, you must specify an arch. A featureset of "none" is
assumed unless you specify one, and by default this program will pick the only
available subarch if there is only one to choose from. If not, you will need to
pick one (and the program will remind you to do this.)

The kernel configuration will be written to ".config" in the current directory,
or the location you specified using the -o/--outfile option.

Let's use config-extract to create a kernel configuration for an amd64 system:

# cd linux
# ./config-extract amd64
Wrote amd64_none_amd64 kernel configuration to /usr/src/linux-debian-2.6.32.30/.config.

config-extract also allows you to extract special Debian featuresets, such as settings for Xen and OpenVZ kernels:

# ./config-extract amd64 openvz
Wrote amd64_openvz_amd64 kernel configuration to /usr/src/linux-debian-2.6.32.30/.config.

It is necessary to name the kernel configuration file something other than ".config" to avoid errors with genkernel.


After using config-extract, run make oldconfig and accept all default options by hitting Enter at all prompts.

Third step: Building and installing the kernel

This is simply achieved by:

# genkernel --kernel-config=config-2.6.32-5-amd64 all
  • --kernel-config: use the given configfile. If you only give a filename here, it is searched for in your current working dir. You can also use a relative or an absolute path leading to your configfile here (for example: "--kernel-config=/usr/src/linux/configfile").
  • all: rebuild the kernel image and the initramfs ramdisk image (aside of kernel modules, the ramdisk image contains tools such as BusyBox and some generic startup scripts, depending on options you use on the command line several additional tools like lvm or raid volume management can be incorporated as well).
Important: Unless explicitly stated via --no-clean or --no-mrproper, Genkernel will do a make mrproper in the kernel source tree, thus cleaning a previous build and removing the previous kernel configuration file in it.

If you use Genkernel to rebuild a Linux kernel on SPARC64, remember to either:

  • Set sparc64-unknown-linux-gnu- in General setup --> Cross-compiler tool prefix
  • Put --kernel-cross-compile=sparc64-unknown-linux-gnu- on the Genkernel command line

Once the kernel has been compiled and the ram disk has been generated, the kernel image plus its companion files (initramfs image and System.map) are placed in the /boot directory. You can use your favourite tool to update your bootloader configuration files.