Welcome! Log In Create A New Profile

Advanced

Howto: Patch the 3.0.0 Debian testing (wheezy) kernel to boot on GoFlex Net/Home (tested with Debian squeeze)

Posted by Vlad 
Here's a quick howto on patching the 3.0.0 kernel from Debian testing (Wheezy repo) to work with GoFlex Net and GoFlex Home.

Why not just take a self-compiled vanilla kernel? Well, when you start exploring some advanced Debian features, certain things may not work as expected with a vanilla kernel. With my new patched Debian 3.0.0 kernel everything works like a charm.

Moreover, those who have UBIT v0.6 have probably already noticed, that they can't boot the official Debian kernel, even if they set their arcNumber to the arcNumber of the Dockstar. With this custom kernel, you can enjoy full support of you GoFlex Net/Home and all the nice Debian patches from the testing repo. BTW, the Howto also works for the Dockstar, although Dockstar will boot the unmodified kernel as well.

For convenience I attached Arch Linux ARM patch and the Debian's kernel config to this post, although you can also download them elsewhere

I did this on Kubuntu 11.04 but I guess that every other Debian based distro should be fine as well.

First we should install the necessary packages:
sudo apt-get install aptitude libncurses5 libncurses5-dev qt3-dev-tools libqt3-mt-dev build-essential fakeroot kernel-package libncurses5 libncurses5-dev patch
Now we want to setup the codesourcery compiler via setup_codesourcery.sh script by Matthias "Maddes" Buecher. I attached the script to this post, but you can find this script on many sites, for example here. We can simply get the script via wget
mkdir ~/Kernel
cd ~/Kernel
wget http://ftp.maddes.net/hardware/Linkstation/setup_codesourcery.sh
Now let's install the compiler
chmod +x setup_codesourcery.sh
sudo ./setup_codesourcery.sh
Download the kernel patch for GoFlex Net and GoFlex Home provided my the Arch Linux ARM Project as well as Debian kernel sources and patches .
wget https://raw.github.com/archlinuxarm/PKGBUILDs/master/core/linux/archlinuxarm.patch
wget http://ftp.ch.debian.org/debian/pool/main/l/linux-2.6/linux-source-3.0.0_3.0.0-3_all.deb
wget http://ftp.ch.debian.org/debian/pool/main/l/linux-2.6/linux-patch-debian-3.0.0_3.0.0-3_all.deb
wget http://ftp.ch.debian.org/debian/pool/main/l/linux-2.6/linux-support-3.0.0-1_3.0.0-3_all.deb
Install the source packages
sudo dpkg -i linux-source-3.0.0_3.0.0-3_all.deb
sudo dpkg -i linux-support-3.0.0-1_3.0.0-3_all.deb
sudo dpkg -i linux-patch-debian-3.0.0_3.0.0-3_all.deb
Extract kernel source to the current directory
tar jxf /usr/src/linux-source-3.0.0.tar.bz2
cd linux-source-3.0.0
Apply Debian patches and subsequently the GoFlex patch
/usr/src/kernel-patches/all/3.0.0/apply/debian
patch -p1 < ../archlinuxarm.patch
Get Debian kernel config for armel
wget http://kernel.alioth.debian.org/config/3.0.0-5/config_armel_none_kirkwood --directory-prefix ../
cp ../config_armel_none_kirkwood .config
Go to the crosscompile environment and import the config.
codesourcery-arm-2009q3.sh
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- oldconfig
You will be asked two questions
Seagate GoFlex Net (MACH_GOFLEXNET) [N/y/?] (NEW)
Seagate GoFlex Home (MACH_GOFLEXHOME) [N/y/?] (NEW)
answer both of them with "y"
Here you can perform the custom configuration of your kernel.
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- xconfig
Very important! Disable mv_cesa completely! It doesn't work properly with the 3.0.0 kernel. If your system has more than one CPU, you can also do this to speed up the compilation process. The rule of thumb is number of CPUs + 1, which makes 3 for a Dual Core
export CONCURRENCY_LEVEL=3
Clean up the mess
make-kpkg clean
Let's go
make-kpkg --rootcmd fakeroot --arch armel --cross-compile arm-none-linux-gnueabi- --append-to-version=-goflex --revision=1.1 --initrd kernel_image
This will take some time depending on the power of your machine. After that, it's a good idea to compile kernel-headers too, just in case you'll need them someday.
make-kpkg --rootcmd fakeroot --arch armel --cross-compile arm-none-linux-gnueabi- --append-to-version=-goflex --revision=1.1 --initrd kernel_headers
When finished, in ~/Kernel you will find a file called linux-image-3.0.0-goflex_1.1_armel.deb. Copy this to your GoFlex, for example to /root.
scp ~/Kernel/linux-image-3.0.0-goflex_1.1_armel.deb root@ip-of-the-goflex:/root
Now login to your GoFlex Net via ssh.
ssh root@ip-of-the-goflex
cd /root
Before you install your custom kernel, it's a good idea to install the official 3.0.0 kernel from the testing repo first. Why? Because when installing the "official" 3.x kernel for the first time, Debian apparently also updates linux-base and udev, which won't happend if you install your custom kernel only.

Do this to prevent Debian from installing packages from the testing repo unless you want it to
cat <<END > /etc/apt/preferences
Package: *
Pin: release a=stable
Pin-Priority: 900

Package: *
Pin: release o=Debian
Pin-Priority: -10
END
echo 'APT::Default-Release "stable";' >> /etc/apt/apt.conf
and add the testing repo to your sources.list
echo 'deb http://ftp.debian.org/debian/ testing main contrib' >> /etc/apt/sources.list
apt-get update
Install the official kernel
apt-get install -t testing linux-image-2.6-kirkwood 
and the custom kernel
dpkg -i linux-image-3.0.0-goflex_1.1_armel.deb
mkdir /lib/modules/3.0.0-goflex/kernel/arch
Don't remove that official kernel (packages linux-image-kirkwood etc.) even if you don't use it. Removing it may cause troubles so better keep it there.

The last step is to create uImage und uInitrd for uBoot/UBIT but also backup to the old ones
cd /boot
cp uImage uImage.old
cp uInitrd uInitrd.old
mkimage -A arm -O linux -T kernel  -C none -a 0x00008000 -e 0x00008000 -n Linux-3.0.0 -d /boot/vmlinuz-3.0.0-goflex /boot/uImage
mkimage -A arm -O linux -T ramdisk -C gzip -a 0 -e 0 -n Linux-3.0.0  -d /boot/initrd.img-3.0.0-goflex /boot/uInitrd

Done! Next time you reboot your GoFlex it should boot with the new kernel. If something goes wrong, just connect your USB/HDD with the rootfs to a Linux machine, mount the filesystem and do
cp /path-to-rootfs/boot/uImage.old /path-to-rootfs/boot/uImage
cp /path-to-rootfs/boot/uInitrd /path-to-rootfs/boot/uInitrd
This will give you the old kernel back

Finding the right boot partition

GoFlex Net has problems to boot from a USB flash drive when there are SATA hard drives attached. The solution you have to apply depends on whether you have Jeff's u-Boot bootloader or the UBIT bootloader.
  • If you initially installed Debian using Jeff's script then you have u-Boot.
  • If you initially installed Arch using instructions from the Arch Linux ARM site then you have UBIT
Independent of the solution you are going to use, it's mandatory to label your rootfs partition as "rootfs". To do this, connect your USB flash drive to a Linux box and issue
sudo tune2fs -L "rootfs" /dev/whatever
where /dev/whatever is the path to the partition containing the rootfs for GoFlex Net

Solution for uBOOT

On the GoFlex run
fw_setenv usb_init "run usb_scan; setenv usb_root LABEL=rootfs"
after that reboot and you're done. For more information on this solution check out this thread

Solution for UBIT aka hacked initrd

If you have UBIT you still may try the uBOOT solution but the chances are high that it simply won't work. In this case you should do the following. On the GoFlex Net run
cd /boot
mkdir initrd.img-new &&  cp initrd.img-3.0.0-goflex initrd.img-new/
cd initrd.img-new/ && gzip -dc initrd.img-3.0.0-goflex | cpio -id
rm initrd.img-3.0.0-goflex
nano init
Find the section which looks like
if [ -n "${noresume}" ]; then
export noresume
unset resume
else
resume=${RESUME:-}
fi
and replace it by
if [ -n "${noresume}" ]; then
export noresume
unset resume
else
resume=${RESUME:-}
fi
ROOT="/dev/disk/by-label/rootfs"
Save your changes (Ctrl+W) and exit (Ctrl+X) nano. Now run
find ./ | cpio -H newc -o > ../initrd.img-3.0.0-goflex_arc
gzip ../initrd.img-3.0.0-goflex_arc
mv ../initrd.img-3.0.0-goflex_arc.gz ..//initrd.img-3.0.0-goflex_mod
cd ..
rm -r initrd.img-new
mkimage -A arm -O linux -T ramdisk -C gzip -a 0 -e 0 -n Linux-3.0.0  -d /boot/initrd.img-3.0.0-goflex_mod /boot/uInitrd
The purpose of all this is to hardcode a rootfs partition. In this case we tell the kernel (via initramfs) that the rootfs partition is a partition with the label "rootfs". This is a very ugly hack but it works when everything else fails.


Installing the kernel headers
In ~/Kernel you will also find a package containing kernel headers (linux-headers-3.0.0-goflex_1.1_armel.deb) that might be necessary for compiling some modules/utilities on the GoFlex Net. For some reason this package contains a lot of X11 related dependencies which are definitely not needed for a headless server. I solved this by simply removing those by hand.
cd ~/Kernel
dpkg-deb -x linux-headers-3.0.0-goflex_1.1_armel.deb linux-headers-3.0.0-goflex_1.1_armel_hacked
dpkg-deb -e linux-headers-3.0.0-goflex_1.1_armel.deb linux-headers-3.0.0-goflex_1.1_armel_hacked/DEBIAN
nano linux-headers-3.0.0-goflex_1.1_armel_hacked/DEBIAN/control
Remove libaudio 2, libfontconfig1, libfreetype6, libice6, libqt3-mt, libsm6, libx11-6, libxcursor1, libxext6, libxft2, libxi6, libxinerama1, libxrandr2, libxrender1, libxt6 from the Depends line.
dpkg-deb -b linux-headers-3.0.0-goflex_1.1_armel_hacked
rm -r linux-headers-3.0.0-goflex_1.1_armel_hacked
copy linux-headers-3.0.0-goflex_1.1_armel_hacked.deb to your device and install it via
dpkg -i linux-headers-3.0.0-goflex_1.1_armel_hacked.deb

Sources:
http://www.debianadmin.com/step-by-step-tutorial-howto-compile-kernel-in-debian-5-0-lenny.html
http://horms.net/projects/debian_kernel/stuff/debian_kernel.pdf



Edited 6 time(s). Last edit at 10/15/2011 03:20PM by Vlad.
Attachments:
open | download - archlinuxarm.patch (10.8 KB)
open | download - config_armel_none_kirkwood (99.5 KB)
Hmm, I've just learned a very weird thing about my patched Debian kernel: It doesn't boot if there is no uInitrd present. I mean it gets to the "Starting kernel ..." but the kernel part of the netconsole stays empty. If there's a uInitrd present everything works just fine.

I'm a bit puzzled, because my custom vanilla kernels (both 2.6.38.8 and 3.0.1) don't have any problems booting without uInitrd. Is there something special about the way Debian team patches their kernel?

EDIT: I guess that's because of the
CONFIG_IP_PNP
CONFIG_IP_PNP_DHCP
CONFIG_IP_PNP_BOOTP
and not enabled in the Debian kernel by default.



Edited 1 time(s). Last edit at 10/14/2011 05:02PM by Vlad.
A small correction concerning my previous statement on custom vanilla kernels failing with unlocking LUKS-encrypted rootfs via SSH. After some more experiments, I finally managed to find the reason for the kernel panic and could reproduce those when using Debian kernel too. The culprit is mv_cesa. If you include the module to "/etc/initramfs-tools/modules" your initrd will be built with mv_cesa and mv_cesa will be loaded during the initramfs phase. However, when the kernel switches to /sbin/init after having unlocked and mounted the rootfs, a kernel panic occurs. If you remove mv_cesa from initrd, everything boots fine, but you don't get the aes hardware acceleration.



Edited 3 time(s). Last edit at 10/14/2011 05:00PM by Vlad.
The bug with mv_cesa seems to have been fixed in 3.0.13 upstream, so it should be fixed soon if it hasn't already in the Debian kernels
Re:
"If your system has more than one CPU, you can also do this to speed up the compilation process. The rule of thumb is number of CPUs + 1, which makes 3 for a Dual Core
export CONCURRENCY_LEVEL=3"

This a persistent misconception as export CONCURRENCY_LEVEL=1 would then spawn 0 compile threads ..... which obviously is not the case.
The reason why some developers prefer cpu count +1 is to counter for slow hard disk I/O.
But on machines with plenty of ram ( read the ones with +9GB ram that can hold the build tree in cache ) cpu count +1 will actually make a build slower > my build machines have a minimum of 12GB, my workstations 24GB.

In short the better "export CONCURRENCY_LEVEL" rule is
export CONCURRENCY_LEVEL=`getconf _NPROCESSORS_ONLN`
which will set the correct amount of threads

my 5 cents
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: