Hello to everyone who is interested,
How to replace the kernel on a Fedora livecd
By Sean Godsell
The reason I wrote this was I wanted to have a live cd with more stuff on it. I wanted
more wifi, skype, and Adobe flash as well as shockwave, wine (for the games). So the
first task on the list was a kernel that supported all the webcam drivers, ntfs,
ndiswrapper, madwifi, and 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 . I could have
chosen the kernel source from fedora and built it the rpm way, but I started back in the
days with slackware. So I am use to building the kernel the original way. Also this way
of building works with other distros as well. And I get to control the patches that I
want to apply. (I know you can edit the kernel.spec file, but I will leave that up to
someone else ;-) ). I could also go into every detail of how to manipulate a kickstart
file, and how to use livecd-creator, but I didn't, so stop reading then ;-). Once you
have obtained the kernel source code, extracted, modified and built and tested it to your
needs. Then its time to roll your own fedora livecd.
To start with I obtained the original Fedora-9-i686-Live.iso file and saved it to
/home/images (For the duration of this document I will be using a folder /home/images).
Before we do anything else I am going to create a few mount points, using type in the
following commands:
mkdir /mnt/iso; mkdir /mnt/squashfs; mkdir /mnt/ext3fs; mkdir /mnt/next3fs
Now we need to mount the Fedora-9-i686-Live.iso file. Type in the following command:
mount -o loop /home/images/Fedora-9-i686-Live.iso /mnt/iso
The next step I created a directory to put all the file into:
mkdir /home/images/isoimage
Next we have to copy all the files to the /home/images/isoimage directory with:
cp -dpR /mnt/iso/* /home/images/isoimage
So now we have extracted the fedora iso image to a directory. Next I created a directory
called initrd
mkdir /home/images/initrd
Then I extracted the initrd0.img file using the following commands:
cd /home/images/initrd
cat /home/images/isoimage/isolinux/initrd0.img | gunzip - | cpio -i
You should have an extracted initrd image now inside the /home/imgaes/initrd folder. Okay
now comes the fun stuff. Copy the following lines to a file called copymodules in the
/home/images folder. Start copying everything in between the equals symbols (======)
==================
#!/bin/bash
# Copy files from a modules.dep to a directory , by Sean Godsell
# $1 - the modules.dep file to use
# $2 - the directory of where to get the kernel modules to copy from
# $3 - the directory to copy the modules into
mods=`cat $1`
for i in $mods; do
name=`echo $i|awk '{print $1}'|awk -F / '{print $(NF)}'|awk -F :
'{print $1}'`
find $2 -iname $name -exec cp -dpf {} $3 \;
done
===================
Okay once the copymodules file is created. Next we have to create a directory for our new
with the exact same name of the kernel you are going to copy from. In my case I am using
2.6.25.9. So I will create a directory in /home/images/initrd/lib/modules using the
following command:
mkdir /home/images/initrd/lib/modules/2.6.25.9
Next I want to use fedora livecds module files so I copied from the original
/home/images/initrd/lib/modules/2.6.25-14.fc9.i686/ using the following command:
cp /home/images/initrd/lib/modules/2.6.25-14.fc9.i686/module*
/home/images/initrd/lib/modules/2.6.25.9/
Next I modified modules.dep and added the squashfs + lzma modules. To do this I looked at
my installed 2.6.25.9 kernel from /lib/modules/2.6.25.9/modules.dep and replaced the one
line with squashfs.ko: in /home/images/initrd/lib/modules/2.6.25.9/modules.dep with the
following 3 lines:
/lib/modules/2.6.25.9/extras/sqlzma.ko: /lib/modules/2.6.25.9/extras/unlzma.ko
/lib/modules/2.6.25.9/extras/unlzma.ko:
/lib/modules/2.6.25.9/extras/squashfs.ko: /lib/modules/2.6.25.9/extras/sqlzma.ko
/lib/modules/2.6.25.9/extras/unlzma.ko
I also edited out ALL of the /extras so you will end up with
/lib/modules/2.6.25.9/unlzma.ko: . Next I did a global replace for 2.6.25-14.fc9.i686 to
2.6.25.9 .
Now save the changes back to /home/images/initrd/lib/modules/2.6.25.9/modules.dep. We
still don't have any modules in the folder, but that is about to change. Type in the
following command:
source /home/images/copymodules /home/images/initrd/lib/modules/2.6.25.9/modules.dep
/lib/modules/2.6.25.9/ /home/images/initrd/lib/modules/2.6.25.9/
This should populate the /home/images/initrd/lib/modules/2.6.25.9 with all the necessary
modules, including the squashfs and the lzma modules. Next we need to delete the old
2.6.25-14.fc9.i686 folder with the following command:
rm -fr /home/images/initrd/lib/modules/2.6.25-14.fc9.i686
Once that is complete it is time to replace the original initrd0.img file. Type in the
following commands:
cd /home/images/initrd
find . | cpio -H newc -o | gzip -9> /home/images/isoimage/isolinux/initrd0.img
We now have replace the original initrd0.img. Next we need to replace the original kernel
image with the following commnad:
cp /boot/bzImage-2.6.25.9 /home/images/isoimage/isolinux/vmlinuz0
So now if we were to burn an iso image at this point it would boot up with the kernel
2.6.25.9 and mount a normal squashfs or a squashfs with lzma. But the rest of the livecd
would not work. We need to replace the existing /lib/modules/2.6.25-14.fc9.i686 directory
with the /lib/modules/2.6.25.9. These files reside inside the
/home/images/isoimage/LiveOS/squashfs.img file. Enter in the following commands:
mkdir /home/images/squashfs_image/
modprobe squashfs
mount -o loop -t squashfs /home/images/isoimage/LiveOS/squashfs.img /mnt/squashfs
cp -dpR /mnt/squashfs/* /home/images/squashfs_image/
umount /mnt/squashfs
mount -o loop /home/images/squashfs_image/LiveOS/ext3fs.img /mnt/ext3fs
rm -fr /mnt/ext3fs/lib/modules/2.6.25-14.fc9.i686
cp -dpR /lib/modules/2.6.25.9 /mnt/ext3fs/lib/modules/
Now you can put what ever you want on the ext3fs image. I put skype, wine packages and my
wine enviroment with a windows version of firefox. Now some of you are probably thinking
there is a firefox already on the fedora live cd. That is true. I already know this, but
the only way that I know of getting shockwave to work is through wine or a VM with
windows. The last option is just a little too big to get on a livecd image. So I opted
to installing wine and my .wine environment. I also updated the firefox beta that was on
the live image to the released version (Not to mention I updated a few more things). At
this point you are ready to do 1 of 2 things. 1) you can re squash the ext3fs.img. 2)
create a clean ext3fs.img and copy everything from /mnt/ext3fs/ to the clean ext3fs.img.
You are probably wondering why would you copy everything from one ext3fs.img to another
ext3fs.img, well the answer is quite simple. If you delete a bunch of things off the
ext3fs.img, and then decide to squash it. You might get roughly the same size image after
wards, even if you remove a lot of files. With ext3 file system it doesn't zero out
all the files. It only removes entries, so the data is still there. So when squashing
the ext3 image, if the data is still there, then it has to compress it. In other words
if you transfer everything over from one image to a brand new clean image then when it
comes time to compress the ext3 image, the end result can be a smaller image. If you
don't care and want to just squash the ext3fs.img, then skip to the squashfs section.
Okay to copy everything type in the following commands:
dd if=/dev/zero of=/home/images/ext3fs.img bs=1MB count=4096
mkfs.ext3 /home/images/ext3fs.img
mount -o loop /home/images/ext3fs.img /mnt/next3fs
cp -dpR /mnt/ext3fs/* /mnt/next3fs/
Now to use the squashfs file system. First we most umount the ext3 file system. So type
in:
umount /mnt/next3fs
umount /mnt/ext3fs
Next replace the new image in squashfs_image/LiveOS
cp -f /home/images/ext3fs.img /home/images/squashfs_image/LiveOS/
Then to compress type in (If you replaced the original command, then just remove the
.lzma):
mksquashfs.lzma squashfs_image/ /home/images/isoimage/LiveOS/squashfs.img
This takes some time. So have a drink, hey why not have a couple of drinks ;-)
Okay once that is done the final step is create an iso image with the following command:
mkisofs -J -r -hide-rr-moved -hide-joliet-trans-tbl -V Fedora-9-Live-i686 -o Seans.iso -b
isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-info-table -boot-load-size
4 isoimage
With the exact same fedora image. I was able to save almost 110 megabytes. Wow, what a
savings.
Not to mention saving on download time. I don't know why fedora didn't take the
time to use squashfs+lzma, but it is worth it. I hope they put it in the next release.
_________________________________________________________________
Express yourself with free Messenger emoticons. Get them today!
http://www.freemessengeremoticons.ca/?icid=EMENCA122