Tuesday, September 24, 2013

Ubuntu and broken or missing aufs with default kernels

Aufs included in Ubuntu kernels is broken, what a surprise. In addition it has been dropped from newer kernels with claims that overlayfs does exactly same thing. It doesn't and everyone knows it except that one developer who decided it does and can't admit he made mistake. It seems aufs (and overlayfs) in Ubuntu is not really supposed to be used but only be part of install process. If so you guys shouldn't include it outside installer.. WontFix you too.



Therefore we need new kernel with recent aufs. Some notes below. Proceed at your own risk as usual.

# Switch to mainline kernel without Ubuntu patches
# We do this so we have "known good" kernel to troubleshoot
# if something goes wrong and also for suitable kernel config file
mkdir -p /opt/src/3.11
cd /opt/src/3.11
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.11.1-saucy/linux-headers-3.11.1-031101-generic_3.11.1-031101.201309141102_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.11.1-saucy/linux-headers-3.11.1-031101_3.11.1-031101.201309141102_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.11.1-saucy/linux-image-3.11.1-031101-generic_3.11.1-031101.201309141102_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.11.1-saucy/0001-base-packaging.patch
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.11.1-saucy/0002-debian-changelog.patch
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.11.1-saucy/0003-configs-based-on-Ubuntu-3.11.0-7.13.patch
dpkg -i linux-*3.11.1*.deb

# Deps for compiling kernel
apt-get -y install git-core kernel-package fakeroot build-essential ncurses-dev

# Download aufs, must match with kernel installed
mkdir -p /opt/src/aufs
cd /opt/src/aufs
git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git aufs3-standalone.git
cd aufs3-standalone.git
git checkout origin/aufs3.11

# Get kernel source
mkdir -p /opt/src/3.11aufs
cd /opt/src/3.11aufs
wget http://www.kernel.org/pub/linux/kernel/v3.x/linux-3.11.1.tar.bz2

# Extract and patch with Ubuntu configs
tar xvjf linux-3.11.1.tar.bz2
cd linux-3.11.1
patch -p1 </opt/src/3.11/0001-base-packaging.patch
patch -p1 </opt/src/3.11/0002-debian-changelog.patch
patch -p1 </opt/src/3.11/0003-configs-based-on-Ubuntu-3.11.0-7.13.patch

# Apply aufs patches
patch -p1 </opt/src/aufs/aufs3-standalone.git/aufs3-base.patch
patch -p1 </opt/src/aufs/aufs3-standalone.git/aufs3-standalone.patch

# Compile kernel and generate new dpkgs
#cp /boot/config-$(uname -r) ./.config
cp /boot/config-3.11.1-031101-generic .config
make olddefconfig
CONCURRENCY_LEVEL=8 fakeroot make-kpkg --initrd --append-to-version=-aufs kernel_image kernel_headers

# Make sure ohci-pci USB driver is loaded during initramfs
echo "ohci-pci" >>/etc/initramfs-tools/modules

# Install new kernel
cd ..
dpkg -i linux-headers-3.11.1-aufs_3.11.1-aufs-10.00.Custom_amd64.deb \
        linux-image-3.11.1-aufs_3.11.1-aufs-10.00.Custom_amd64.deb

# Prevent future kernel updates breaking things
echo "linux-image-3.11.1-aufs hold"             | dpkg --set-selections
echo "linux-headers-3.11.1-aufs hold"           | dpkg --set-selections
echo "linux-image-3.11.1-031101-generic hold"   | dpkg --set-selections
echo "linux-headers-3.11.1-031101-generic hold" | dpkg --set-selections

# For new Ubuntu versions with silly grub submenu layout
# https://help.ubuntu.com/community/Grub2/Submenus#Setting_a_Submenu_entry_as_the_default
sed -i.bak /etc/default/grub \
    -e's|^GRUB_DEFAULT=.*|GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 3.11.1-aufs"|g'

# For older versions such as 12.04
sed -i.bak /etc/default/grub \
    -e's|^GRUB_DEFAULT=.*|GRUB_DEFAULT="Ubuntu, with Linux 3.11.1-aufs"|g'

# and run update-grub
update-grub

# Reboot

# Next aufs module
cd /opt/src/aufs/aufs3-standalone.git/

# Enable hnotify, allows direct access to branches bypassing aufs
sed -i.bak config.mk \
    -e's|^CONFIG_AUFS_HNOTIFY.*|CONFIG_AUFS_HNOTIFY = y|g' \
    -e's|^CONFIG_AUFS_HFSNOTIFY.*|CONFIG_AUFS_HFSNOTIFY = y|g'

# Fix missing binary that prevents compiling aufs
cd /opt/src/3.11aufs/linux-3.11.1/scripts/
gcc unifdef.c -o unifdef
cd -

# Compile aufs
make

# Install aufs
make install
depmod -a

# We skip aufs-utils install as they're pointless

# Additionally if you want ddbridge DVB card drivers do this

# DVB
mkdir -p /opt/src/3.11-dvb
cd /opt/src/3.11-dvb
# Grab version with required drivers
hg clone http://linuxtv.org/hg/~endriss/media_build_experimental
cd media_build_experimental
# Use latest version
#sed -i.bak linux/Makefile \
#    -e's|^LATEST_TAR :=.*|LATEST_TAR := http://linuxtv.org/downloads/drivers/linux-media-2013-09-04.tar.bz2|g' \
#    -e's|^LATEST_TAR_MD5 :=.*|LATEST_TAR_MD5 := http://linuxtv.org/downloads/drivers/linux-media-LATEST.tar.bz2.md5|g'
sed -i.bak linux/Makefile \
    -e's|^LATEST_TAR :=.*|LATEST_TAR := http://linuxtv.org/downloads/drivers/linux-media-LATEST.tar.bz2|g' \
    -e's|^LATEST_TAR_MD5 :=.*|LATEST_TAR_MD5 := http://linuxtv.org/downloads/drivers/linux-media-LATEST.md5|g'
# Download
make download
# Fix download source from slooooow dyndns to proper mirror
# Difference? 60+ minutes vs. 5 seconds. Yes, really.
sed -i.bak experimental/add-drivers \
    -e's|fetch_hg_repo "http://powarman.dyndns.org/hg/v4l-dvb-saa716x" "v4l-dvb-saa716x" \|\| ||g'
# Unpack and download more
make untar
#make menuconfig
# Compile
make
# Install
make install

# Reboot since it's not possible to unload and reload ddbridge driver without crashing kernel
reboot

2 comments:

  1. I have used this guide several times for this process, thank you!

    ReplyDelete
  2. Спасибо за подробную инструкцию! Буду пробовать компилировать свежее ядро.
    P.S. Если все знают, что overlayfs не работает, как надо, почему снова не включат aufs в свежие ядра? Один разработчик сильнее всего сообщества?

    ReplyDelete

Got something to say?!