venerdì 17 settembre 2010

[HOWTO] - Slax powered by zen-kernel v. 2.6.32

Ecco spiegato passo passo come installare il nuovo kernel 2.6.32 nella nostra Slax: 

Fonte:http://www.slax.org/forum -  Thanks to : fanthom

Before you start: make a backup on your existing Slax installation!

WARNING: after upgrading, all kernel dependent Slax modules like: Virtualbox or proprietary GPU drivers will need to be updated to the new kernel version too.
WARNING: If you are changing something in kernel config and recompiling kernel once again, you may need to replace all kernel modules (M) in initrd and 001-core.lzm accordingly.

Hardware requirements:
at least 2GB of memory when Slax runs with copy2ram cheatcode
1,5GB of free space on usb stick or hard drive when building up maximum compatibility kernel (all options enabled)

Let's start!

Section I Kernel

First of all make sure that Slax devel package is activated:

activate /mnt/sdb1/slax/optional/006-devel.lzm


download recent kernel version and unpack it somewhere:

wget http://distfiles.gentoo.org/distfiles/linux-2.6.32.tar.bz2
 

tar -xvjf linux-2.6.32.tar.bz2 -C /root/

enter kernel directory and download zen-kernel patches (sq4lzma, reiser4, tuxonice, and other features included, more info: http://zen-kernel.org/included-code)

cd /root/linux-2.6.32

 
wget http://downloads.zen-kernel.org/2.6.32/2.6.32-zen4.patch.lzma

 
decompress zen file and patch the kernel:

lzma -d 2.6.32-zen4.patch.lzma
patch -p1 < 2.6.32-zen4.patch

 
once you have kernel patched you need to configure it. Best way is to use old slax kernel config file.

cp /usr/src/linux/.config .
make oldconfig


script will give you around 100 questions - all changes between kernel 2.6.27.27 and 2.6.32.
If you are not sure which option choose, better keep enter pressed (default options are usually safe).
Check if your configuration is correct:

make menuconfig


Navigate to "File systems" menu and mark ext4 as built in (*) and FUSE as (M). Then go to -> "Miscellaneous filesystems", Aufs and Squashfs can go as a kernel module (M), lzma compression must be (*)
Mark other drivers and features as you like :D
EDIT: Read cheater1034 post before you finish with configuration: http://www.slax.org/forum.php?action=view&parentID=53971
Now it's time to build a kernel so:

make && make modules_install && make firmware_install


It's gonna take long time so grab a beer.
If no errors are reported you can copy your shiny new zen kernel to Slax /boot directory

cp arch/x86/boot/bzImage /mnt/sdb1/boot/vmlinuz


Comments:
1. Good idea it to store compiled sources somewhere (maximum 1,5GB when uncompressed), in case when you'll be adding/changing something, you wont have to go through whole process once again
and compilation will be much faster.
2. If you use Slax on different machines try to compile as many drivers as it's possible as a (M), kernel wont be bloated that much (my gentoo kernel stripped to maximum takes 1.7MB only)
3. Other/Newer zen patches can be found here: http://downloads.zen-kernel.org/
4. Best place for compilation is RAM (fastest). Boot slax with copy2ram cheatcode or use tmpfs instead: http://en.wikipedia.org/wiki/Tmpfs

Section II Initrd

To tweak initial ramdisk, do as follows:

cp /mnt/sdb1/boot/initrd.gz /root
gunzip /root/initrd.gz
mount -o loop /root/initrd /mnt/cdrom


I never do PXE boot so I have removed drivers.lzm from initrd. Also, we don't need old kernel drivers (2.6.27.27) so we can remove them from /mnt/cdrom/lib/modules. Last step is to add proper catalog structure for 2.6.32-zen4. We just need 3 drivers to boot up our new kernel: fuse, aufs and squashfs

rm -r /mnt/cdrom/lib/modules/2.6.27.27/
mkdir -p /mnt/cdrom/lib/modules/2.6.32-zen4/kernel/fs/fuse/
mkdir -p /mnt/cdrom/lib/modules/2.6.32-zen4/kernel/fs/squashfs/
mkdir -p /mnt/cdrom/lib/modules/2.6.32-zen4/kernel/fs/aufs/
cp /lib/modules/2.6.32-zen4/kernel/fs/fuse/fuse.ko /mnt/cdrom/lib/modules/2.6.32-zen4/kernel/fs/fuse/
cp /lib/modules/2.6.32-zen4/kernel/fs/squashfs/squashfs.ko mnt/cdrom/lib/modules/2.6.32-zen4/kernel/fs/squashfs/squashfs.ko
cp /lib/modules/2.6.32-zen4/kernel/fs/aufs/aufs.ko /mnt/cdrom/lib/modules/2.6.32-zen4/kernel/fs/aufs/
depmod -b /mnt/cdrom


Now we have to convert usr.lzm from initrd to squashfs4 format (new kernel wont be able read old lzm modules). First, copy it to root folder and extract the content.

mkdir /root/usr
lzm2dir /mnt/cdrom/usr.lzm /root/usr/


Download my module and activate it: (you can also build sq4fs tools from sources using cvs - to add lzma compression just edit Makefile, Phillip left some hints there)

wget http://www.slax.org/modules/3155/dl/squashfs4-tools.lzm

It will create squashfs4-tools folder under /root directory. You'll find there a mksquashfs and unsquashfs binaries patched for lzma compression.

/root/squashfs4-tools/mksquashfs /root/usr /root/usr.lzm
mv /root/usr.lzm /mnt/cdrom/


All done for now so repack initrdand move it to boot folder:

umount /mnt/cdrom
gzip /root/initrd
mv /root/initrd.gz /mnt/sdb1/boot/


Comments:
1. If you want PXE boot or other drivers in initrd then add them to drivers.lzm. Remember to create lzm module using new squashfs4-tools.

Section III Converting slax modules to the new format

Same usage as with usr.lzm file

/root/squashfs4-tools/mksquashfs /mnt/live/memory/images/002-xorg.lzm/ /mnt/sdb1/slax/base/002-xorg.lzm
/root/squashfs4-tools/mksquashfs /mnt/live/memory/images/003-desktop.lzm /mnt/sdb1/slax/base/003-desktop.lzm


Now we need to get rid of old drivers from 001-core.lzm so:

cp -r /mnt/live/memory/images/001-core.lzm/ /root/001-core/
rm -r /root/001-core/lib/modules/*
rm -r /root/001-core/lib/firmware/*
cp -r /lib/firmware/* /root/001-core/lib/firmware/
mkdir /root/001-core/lib/modules/2.6.32-zen4/
cp -r /lib/modules/2.6.32-zen4/* /root/001-core/lib/modules/2.6.32-zen4/
/root/squashfs4-tools/mksquashfs /root/001-core/ /mnt/sdb1/slax/base/001-core.lzm


Comments:
1. Any volunteer to write a script for automatic conversion?

Thats it!
Reboot and enjoy :D

Section IV Debugging

When something goes wrong and you finish with:
"looking for Slax data Directory"
you will have an access to the debug shell so take those actions:
1) run lsmod and make sure you have fuse, aufs and squashfs loaded
2) mount your usb key manually:

mkdir /mnt/usb

mount /dev/sdb1 /mnt/usb


If you get message like "/dev/sdb is not a valid block device" or similar it means that you are short of some required drivers or filesystem support. Add them to config, recompile kernel and replace all drivers in initrd and 001-core.lzm. If you are able to mount the stick then everything should go fine.


Final Comments:
1. I didn't replace original squashfs tools in 001-core.lzm cause I need them for repacking modules.
2. New sq4lzma modules are little bit bigger in size. I used defaults options so experiments with block size etc are very welcome.
3. Zen sources are rich of experimental/untested features, be aware of that. Familiarize yourself with Issue Tracker: http://zen-kernel.org/issues

Good luck!