January 23, 2010 at 11:21 pm #42158
The purpose of this post is to describe the overall steps necessary to compile a newer kernel for Compact Flash version of Zeroshell (18.104.22.168 as of the time I wrote this post).
Although I’m a very a experienced linux user/admin I’m very new to Zeroshell (My first installation was less than 1 week ago), so, forgive me if there is an easier way of doing this that I don’t know of…
All begun when I had some problems with the out-of-the-shelf Zeroshell image supporting a Davicom USB/ETHERNET adapter with the original 22.214.171.124 kernel included on Beta12.
Of course the culprit wasn’t Zeroshell itself (which is actually an excellent, not to say AMAZING, distribution), but the kernel version, which leaded me to execute the procedure I describe below).
The upgrade process wasn’t simple and, actually, I didn’t take note of every step in detail, and much of it was result of a do-test-change-try-again process; Just too much to describe here in detail, so I’ll describe the overall idea, including the way I used to generate a proper initrd file.
1 – compiled the kernel in a different box (same architecture);
1.1 – I got the original Zeroshell kernel “.config” file by running “zcat /proc/config.gz >.config” using the Zeroshell’s shell.
1.2 – Before recompiling, I applied the l7 netfilter ( http://l7-filter.sourceforge.net/ ) kernel patches to the vanilla image (not at the first trial, but then I realized I lost the L7 net-filtering capabilities… so I had to recompile everything 🙂 ).
1.3 – Used “make oldconfig” to make sure all the new options from the newer kernel version get properly configured and recompiled the kernel (not described here).
2 – repartitioned the compact flash (a 2GIG one with the 1GIG out-of-the-shelf image from the Zeroshell site) and reformatted partition 2 to be ext3 instead of iso9660 (not before backing up all files from every partition, then, after reformatting, copying back the all the files to the CF);
NOTE1: This is an essential step as iso9660 cannot be mounted read-write;
NOTE2: I also enlarged a bit the partitions 1 and 2 so that parititon 1 (/boot) can hold multiple versions of kernel images and paritition 2 (/cdrom) can accommodate the ext3 overhead (iso9660 is a way lighter filesystem).
3 – Instead of using mkinitrd, I edited the original initrd from zeroshell replacing the modules within it with the new compiled ones. This can be done using the ps_initrd.sh script ( http://www.nigilist.ru/nit/ps_initrd.sh/ ). I also did this in a different box;
3.1 – Since I changed the partition 2 type from iso9660 to ext3, I also had to edit the linuxrc file within the original initrd and replace all the iso9660 occurrences with ext3. This change is very transparent: everything will look very like the same, meaning that this partition will still be mounted under /cdrom, just the file-system format will be ext3 (thus possible to be mounted read-write);
3.2 – For the same reasons we changed the linuxrc file we also have to change the /etc/fstab that exists within /cdrom/isolinux/rootfs (which is the image of the rootfs copied to / at startup) and change the fstype there from iso9660 to ext3 too. In order to do this, we have to copy it to a different box, gunzip it (although it doesn’t have the .gz extension), loop mount it somewhere (like /mnt), change the /etc/fstab within it, umount it, gzip it again (remember to remove the .gz extension right after) and copy it back to the newly formatted ext3 /cdrom image. All this should be done in a separate box.
4 – Installed the new kernel on the Compact Flash:
4.1 – Booted the Zeroshell using original kernel but with a slightly modified initrd (not the one with the new modules, but one with just the linuxrc file changes needed to support the iso9660 to ext3 change).
NOTE: I used a different box to copy this slightly modified initrd on the compact flash;
4.1 – Using Zeroshell’s shell, remounted /cdrom and /boot as read-write (” mount -o remount,rw…”). Copied the new files in the appropriate locations (mainly vmlinuz-X.X.X and the new fully modified initrd-X.X.X to /boot and all the new kernel modules to /cdrom/modules);
4.2 – edited /boot/grub/grub.conf and added the new entry for the new kernel;
IMPORTANT: The next two steps are very important before booting the new kernel. As we compiled the kernel in a different box, we needed to correct the module dependences and kernel image boot device:
5 – Run “depmod -av X.X.X” locally to update the modules.dep file under /cdrom/modules/X.X.X (X.X.X is the new kernel version);
NOTE: This has to be done directly in the Zeroshell box, running the original kernel, but with /cdrom (already converted to ext3) mounted read-write and with the new kernel modules already copied to it under /cdrom/modules/X.X.X
6 – Run rdev vmlinuz-X.X.X /dev/ram2 (where vmlinuz-X.X.X is the image of the new kernel)
NOTE: As I said here I’m just describing the main idea as I didn’t take note of every step, so, just in case, keep the original kernel lines on grub.conf and original files where they are so that you sill can boot in case of problems. Believe me this is a complex process and chances are that a step may get forgotten.
DISCLAIMER: If you are not familiarized with recompiling a linux kernel, repartitioning a hard disk and this sort of thigs, then, the safest thing here is NOT TO FOLLOW the procedure described here as this is just a overall idea guide for more experienced users.
IMPORTANT: TRY THIS AT YOUR OWN RISK, and please: BACKUP THE ENTIRE COMPACT FLASH IMAGE BEFORE BEGINNING!January 24, 2010 at 5:53 pm #49437
This can definitively come in handy one day. Thanks a lot for posting it.October 20, 2010 at 2:26 am #49438
Thank you so much for posting this topic….i really enjoy reading it…
God bless!!!February 14, 2011 at 6:25 am #49439
DELETEDMarch 27, 2011 at 11:41 pm #49440
Thank you for the positive feedback!
indeed I’ve to post this: This was actually very useful for me too. About 1 year after posting this, I had to look at it in order to do part of this again as I’m upgrading to beta14. Would certainly forget a step if I didn’t write this…
You must be logged in to reply to this topic.