[Fedora-livecd-list] Creating Squashfs + lzma kernel modules

Sean Godsell sgodsell at hotmail.com
Thu Jul 3 20:09:15 UTC 2008


Hello to anyone who is interested,

			Building a kernel with squashfs with lzma support (July 2008)
						By Sean Godsell

The first task on the list was a kernel that supported squashfs with lzma support.  So I decided to go with the latest stable kernel at this time.  Which is kernel 2.6.25.9 from kernel.org .  Now each linux distribution has its way of building kernels.  So I opted to building the kernel the generic way. This will also work for most distributions.  And I get to control the patches that I want to apply.  Once you have obtained the kernel source code, and extracted to a directory of your choice (I use /usr/src path).  To extact I used the following command
	tar -jxf linux-2.6.25.9.tar.bz2

	Next I downloaded a bunch of files from http://www.squashfs-lzma.org/ .  Download all the files in the section 'Download (all needed)', except the last one which states linux kernel 2.6.24 or higher.  For that one I already downloaded the kernel 2.6.25.9 from http://www.kernel.org .  Also download http://sourceforge.net/tracker/download.php?group_id=63835&atid=505341&file_id=274755&aid=1912192 to fix squashfs for 2.6.25 kernels. Okay now for the fun stuff making the kernel.  I always like to comple the stock kernel and get it running first, so I just take current kernel config file from the one I am running and use that as my starting point.  On some systems you can find the config in the /boot directory.  Some kernels might have enabled the config to be in /proc/config.gz.  I am going to use the /boot/config-xxxxxx files.  On my fedora system here I am going to copy one of the config files from /boot.  In my case specifically /boot/config-2.6.25.6-55.fc9.i686 and copy it to the kernel source directory and rename it to .config .
	cp /boot/config-2.6.25.6-55.fc9.i686 /usr/src/linux-2.6.25.9/.config

At this point I added some other patches to the kernel that are not related to squashfs (like ndiswrapper which requests an 8k stack size instead).  I also added a few other drivers like r5u870, gspca, linux-uvc, and madwifi.   None of which effect squashfs.

Then I do a make menuconfig to add or remove items from the kernel.  Once you made the changes in make menuconfig .  The next step is to build the kernel, type in 
	make -j 2 bzImage

Notice the -j 2 is used for running 2 jobs at the same time.  It helps speed up the build if you have a dual core system.   If you have a quad system then change the 2 to 4.   After type in:
	make -j 2 modules
then
	make -j 2 modules_install

If you don't want to wait for each step then type in the following:
	make bzImage modules modules_install

Well some of you might want a leaner kernel with using the option -g0.  This will definitely take some time to build the kernel and the modules.  Next I built the other drivers (r5u870, gspca, uvc, ...)
	If you get errors then you must have changed or did something wrong.  But if everything goes right then you should end up with a directory like '/lib/modules/2.6.25.9' with all the modules.  Next for my architecture I copy the linux-2.6.25.9/arch/x86/boot/bzImage to /boot directory.
	cp /usr/src/linux-2.6.25.9/arch/x86/boot/bzImage  /boot/bzImage-2.6.25.9


The next step is to create an initrd to go with our new kernel.   I use the following command to create my initrd.
	mkinitrd --with=ehci_hcd --with=ohci_hcd --with=uhci_hcd --with=mbcache --with=jbd --with=ext3 --with=dm_mod --with=dm_mirror --with=dm_zero --with=dm_snapshot --with=crypto_blkcipher --with=dm_crypt --with=aes_generic --with=aes_i586 --with=cbc --with=sha256_generic --with=scsi_mod --with=sd_mod --with=libata --with=ahci --with=sg /boot/initrd-2.6.25.9.img 2.6.25.9

	This will create a file called initrd-2.6.25.9.img in the /boot folder.  If you don't know what modules to put into the initrd.  Then what I do is look at the current system and see what it has currently loaded.  Use the command lsmod.  The last entries in the list are the first one's that get loaded at boot time. So I just include those ones (if you don't have and encrypted filesystem then you won't need crypto_blkcipher, as well as a few others).
	Now the last step before we test our kernel is to update the boot loader.  In this case I update my /boot/grub/grub file with the following lines:

	title MyBuild (2.6.25.9) 
		root (hd0,1) 
		kernel /bzImage-2.6.25.9 ro root=/dev/VolGroup01/LogVol00 rhgb
		initrd /initrd-2.6.25.9.img 

If you don't want to see a lot of information being displayed on bootup, then add the word quiet to the end of the kernel line.   Next reboot.
	reboot

	If it boots up, you are in luck ;-)   Now to move on with adding the squashfs + lzma support in the kernel.



				Adding Squashfs + lzma support

	Okay the first step is to take the squashfs files that were download and put them in a directory.  I put mine in /usr/src/squashfs , (I am going to assume that you are going to be in the directory /usr/src/squashfs) so I have 5 files in this directory:
	squashfs3.3.tar.gz
	lzma457.tar.bz2
	sqlzma3.3-457-2.tar.bz2
	squashfs-3.3-cvsfix.tar.gz
	squashfs-patch-2.6.25

The first one I expaned was squashfs3.3.tar.gz  using the following command:
	tar -zxf squashfs3.3.tar.gz

which will create a directory called squashfs3.3 inside the /usr/src/squashfs folder.  Next I created a directory called lzma457 inside /usr/src/squashfs.  Then I extracted the files from lzma457.tar.bz2 into the newly created folder called lzma457 using the following command:
	tar -C lzma457 -jxf lzma457.tar.bz2

Next I created a directory called patches inside the /usr/src/squashfs folder.  Then I extracted the file squashfs-3.3-cvsfix.tar.gz into the patches directory using the following command:
	tar -C patches -zxf squashfs-3.3-cvsfix.tar.gz

The last file to extract, I just extracted to /usr/src/squashfs, using the following command:
	tar -jxf sqlzma3.3-457-2.tar.bz2

Next I went inside the linux kernel (2.6.25.9).
	cd /usr/src/linux-2.6.25.9
	(for fedora do)
	cd /usr/src/kernels/2.6.25.9-76.fc9.i686

and added the squashfs patch using the following command:
	patch -p1 < /usr/src/squashfs/squashfs3.3/kernel-patches/linux-2.6.24/squashfs3.3-patch
then
	patch -p1 < /usr/src/squashfs/patches/typo_mkflags_k.patch
then
	patch -p1 < /usr/src/squashfs/sqlzma2k-3.3.patch
then
	patch -p1 < /usr/src/squashfs/squashfs-patch-2.6.25

The last patch you will get 2 fails but don't worry about them.  If you are really concerned with them then you can look at the reject file 'fs/squashfs/inode.c.rej'.  You will see that it is only two trivial things a printk and a module description.

After do a make menuconfig or edit the .config yourself and make sure CONFIG_SQUASHFS=m .  The option to set under menuconfig is under file systems->Miscellaneous filesystems->SquashFS 3.3 and set to M (for module)

Next go to the /usr/src/squashfs/lzma457 directory and type in the following:
	patch -p1 < ../sqlzma1-449.patch


Now go back one directory to /usr/src/squashfs and edit the Makefile and change the line LzmaVer = near the top of the file to read
	LzmaVer = lzma457

Then edit the line Kver = to
	Kver = linux-2.6.25.9
(fedora change to)
	Kver = 2.6.25.9-76.fc9.i686

Now save this file, and at the command prompt type in
	ln -s /usr/src/linux-2.6.25.9  squashfs3.3/kernel-patches/
	(for fedora do)
	ln -s /usr/src/kernels/`uname -r`  squashfs3.3/kernel-patches/
then
	patch -p0 < patches/typo_mkflags_u.patch
then
	patch -p0 < sqlzma2u-3.3.patch
then
	patch -p0 < patches/mksquashfs_bug_fixes.patch
then
	patch -p0 < patches/code_cleanup.patch

Don't worry about the mksquashfs_bug_fixes.patch reject.  It is only a printf.   And now to build the new mksquashfs command as well as the 3 new kernel modules.  Type in the following:
	make

If everything went well, then you should be able to copy the following files:

(none fedora)
	mkdir /lib/modules/`uname -r`/extra
	cp /usr/src/linux-2.6.25.9/fs/squashfs/*.ko  /lib/modules/`uname -r`/extra/
	cp /usr/src/squashfs/lzma457/C/Compress/Lzma/kmod/*.ko  /lib/modules/`uname -r`/extra/
	cp /usr/src/squashfs/squashfs3.3/squashfs-tools/mksquashfs  /sbin/mksquashfs.lzma

(fedora)
	cp /usr/src/kernels/`uname -r`/fs/squashfs/*.ko  /lib/modules/`uname -r`/extra/
	cp /usr/src/squashfs/lzma457/C/Compress/Lzma/kmod/*.ko  /lib/modules/`uname -r`/extra/
	cp /usr/src/squashfs/squashfs3.3/squashfs-tools/mksquashfs  /sbin/mksquashfs.lzma

if you want to replace the existing command mksquashfs then 
        cp /usr/src/squashfs/squashfs3.3/squashfs-tools/mksquashfs /sbin/ 

Next we have to fix up the kernel dependencies with the following command 
        depmod -ae

You should get no messages if everything went well.  Now we can load the 
modules 
        modprobe squashfs 

and finally if you do a 
        lsmod | head 

then you should see unlzma, sqlzma, and squashfs modules.  If you want to 
verify if the filesystem is supported then type in 
        cat /proc/filesystems |grep squ 

You should see squashfs 

Remember always Good Luck, and have fun  ;-) 

Sean 

_________________________________________________________________
Are you ready for Windows Live Messenger Beta 8.5 ? Get the latest for free today!
http://entertainment.sympatico.msn.ca/WindowsLiveMessenger




More information about the Fedora-livecd-list mailing list