LDP/LDP/howto/docbook/SquashFS-HOWTO/chapter2.xml

318 lines
9.5 KiB
XML

<?xml version='1.0' encoding='ISO-8859-1'?>
<sect1 id="gettingready">
<title>Getting ready for SquashFS</title>
<sect2 id="acquiring">
<title>Acquiring SquashFS</title>
<para>
The SquashFS home site is located at
<ulink url="http://squashfs.sourceforge.net/">http://squashfs.sourceforge.net/</ulink>
- it contains news for the latest release and it's changelog, as well as general information
about SquashFS. You can grab the latest version at the SquashFS
<ulink url="http://sourceforge.net/project/showfiles.php?group_id=63835">project page</ulink>
at SourceForge.
</para>
<para>
Squashfs is also avaliable with LZMA compression at
<ulink url="http://www.squashfs-lzma.org/">http://www.squashfs-lzma.org/</ulink>
</para>
</sect2>
<sect2 id="preparing">
<title>Preparing a SquashFS-capable kernel</title>
<para>
In order to read SquashFS, you need it supported in your kernel - just as if it was a
<filename>reiserfs</filename> or <filename>ext3</filename> file system. You have to make sure
there is an appropriate patch for your kernel version. It should be located in
<filename>kernel-patches/linux-2.x.y</filename> subdirectory of the SquashFS source tree. Also, remember
that in most cases you will need a <emphasis>clean</emphasis> (original) Linux kernel
source from <ulink url="http://kernel.org/">kernel.org</ulink>. If your kernel source is
from a distro vendor, it may be already pre-patched with custom vendor patches, and patching
with a SquashFS patch will almost surely not work, as SquashFS patches are made against
<emphasis>original</emphasis> Linux kernels.
However some distributions make avaliable SquashFS-kernel-modules and SquashFS-tools packages from the repositories.
If you consider to use these packages from your distro, you don't need to patch your kernel or
to build SquashFS tools from source. In such case, make sure to get the proper module for your kernel from the distro
repositories. Please note that doing so you will have an easy installation step, but no control on
kernel configuration parameters if you mind to use SquashFS for particular purposes (eg. for embedded systems).
</para>
<sect3 id="patching">
<title>Patching the kernel source</title>
<para>
With a kernel source and a proper SquashFS patch present, all you have to do is
(we'll assume that you have your Linux kernel source in <filename>/usr/src/linux</filename> and
that you have the SquashFS source in <filename>/usr/src/squashfs</filename>):
</para>
<para>
Change to the SquashFS source directory and
copy the kernel patch (we'll assume it's named <filename>squashfs-patch</filename>) to
<filename>/usr/src/linux</filename>.
</para>
<programlisting>
bash# cd /usr/src/squashfs
bash# cp linux-2.x.y/squashfs-patch /usr/src/linux
</programlisting>
<para>
Go to the linux kernel source directory <filename>/usr/src/linux</filename>:
</para>
<programlisting>
bash# cd /usr/src/linux
</programlisting>
<para><emphasis>Note:</emphasis> please remember that we will not be leaving this
directory during all further kernel-related procedures, and all paths
will be given relative to <filename>/usr/src/linux</filename>.</para>
<para>Now patch the source with the SquashFS patch:</para>
<programlisting>
bash# patch -p1 &lt; squashfs-patch
</programlisting>
</sect3>
<sect3 id="compiling1">
<title>Compiling a 2.6.x kernel</title>
<para>Cleanup and prepare the kernel source:</para>
<programlisting>
bash# make distclean
bash# make mrproper
</programlisting>
<para>Configure the kernel using your favourite method
(config/menuconfig/xconfig/gconfig):</para>
<programlisting>
bash# make menuconfig
</programlisting>
<orderedlist>
<listitem><para>
In the <quote><emphasis>File systems</emphasis></quote> section,
<quote><emphasis>Miscellaneous file systems</emphasis></quote> subsection, enable
the <quote><emphasis>Squashed filesystem</emphasis></quote> option, whether as
module or bundled with the kernel. It is only obligatory to compile SquashFS inside
the kernel if you plan using squashed initial RAM disks (<command>initrd</command>).
</para></listitem>
<listitem><para>
In the same subsection, <command>"do NOT"</command> enable the <quote><emphasis>Additional option for memory-constrained system</emphasis></quote>, unless
you are configuring your kernel for an embedded system.
</para></listitem>
<listitem><para>
If you would like to use a squashed initial RAM disk, enable the
<quote><emphasis>Initial RAM disk support</emphasis></quote> in the
<quote><emphasis>Device drivers</emphasis></quote> section,
<quote><emphasis>Block devices</emphasis></quote> subsection.
</para></listitem>
<listitem><para>
If you want to be able to mount the squashed file system via a <emphasis>loopback device</emphasis> in future, you should enable
<quote><emphasis>Loopback device support</emphasis></quote> in the
<quote><emphasis>Device drivers</emphasis></quote> section,
<quote><emphasis>Block devices</emphasis></quote> subsection.
</para></listitem>
</orderedlist>
<para>Now you may compile the kernel and modules:</para>
<programlisting>
bash# make
</programlisting>
</sect3>
<sect3 id="compiling2">
<title>Compiling a 2.4.x kernel</title>
<para>Configure the kernel:</para>
<programlisting>
bash# make menuconfig
</programlisting>
<orderedlist>
<listitem><para>
In the <quote><emphasis>File systems</emphasis></quote> section, enable
the <quote><emphasis>Squashed filesystem</emphasis></quote> option, whether as
module or bundled with the kernel. It is only obligatory to compile SquashFS inside
the kernel if you plan using squashed initial RAM disks (<command>initrd</command>).
</para></listitem>
<listitem><para>
If you would like to use a squashed initial RAM disk, enable the
<quote><emphasis>Initial RAM disk support</emphasis></quote> in the <quote><emphasis>Block
devices</emphasis></quote> section.
</para></listitem>
<listitem><para>
If you want to be able to mount the squashed file system via a <emphasis>loopback
device</emphasis> in future, you should enable <quote><emphasis> Loopback device
support </emphasis></quote> in the <quote><emphasis>Block devices </emphasis></quote> section.
</para></listitem>
</orderedlist>
<para>Now you may compile the kernel and modules:</para>
<programlisting>
bash# make dep
bash# make bzImage
bash# make modules
</programlisting>
</sect3>
<sect3 id="installkernel">
<title>Installing and testing the kernel</title>
<para>It's time to install your new SquashFS-enabled kernel.
The instructions below are for installing and booting the kernel
on the host machine. You may want to install and test it on the
target system.
</para>
<para>We assume that the kernel was compiled for a x86
architecture, and the compressed kernel image is located in the
<filename>arch/i386/boot/</filename> subdirectory of the kernel tree.
Now copy the kernel to the <filename>/boot</filename> directory (and name it
<filename>bzImage-sqsh</filename> for convenience, if you like):</para>
<programlisting>
bash# cp arch/i386/boot/bzImage /boot/bzImage-sqsh
</programlisting>
<para>
Don't forget to install the kernel modules
if you have any:
</para>
<programlisting>
bash# make modules_install
</programlisting>
<para>
Modify your boot loader's configuration file to include your new kernel and install
(update) the boot loader. Now you may reboot with your new kernel. When it boots, check that
everything went fine:
</para>
<programlisting>
bash# cat /proc/filesystems
</programlisting>
<para>
Or, if you built SquashFS support as a kernel module:
</para>
<programlisting>
bash# insmod squashfs
bash# cat /proc/filesystems
</programlisting>
<para>
If you see the <computeroutput>squashfs</computeroutput> line among other file systems,
this means you have successfully enabled SquashFS in your kernel.
</para>
</sect3>
</sect2>
<sect2 id="tools">
<title>Compiling the SquashFS tools</title>
<para>
Now you need to compile <command>mksquashfs</command> - the tool for creating squashed file systems and the
<command>unsquashfs</command> which extracts files from an existing squashed file system.
</para>
<programlisting>
bash# cd /usr/src/squashfs/squashfs-tools
</programlisting>
<para>
Compile and install the tools:
</para>
<programlisting>
bash# make
bash# cp mksquashfs /usr/sbin
bash# cp unsquashfs /usr/sbin
</programlisting>
<para>
If everything went fine, typing <command>mksquashfs</command> or <command>unsquashfs</command> at the shell prompt should print the <quote>usage</quote> message.
</para>
</sect2>
<sect2 id="debian">
<title>Installing SquashFS on Debian</title>
<para>If you use Debian (or onother Linux distribution) you may want to get SquashFS module and tools from the distro repositories. With Debian you have to install the proper kernel module and the tools with the following commands:
</para>
<para>
(Assuming your architecture is x86)
</para>
<programlisting>
bash# apt-get install squashfs-modules-2.6-486 squashfs-tools
</programlisting>
<para> Now load the squashfs module for the Linux kernel and if it was correctly loaded you should find it in the relative list
</para>
<programlisting>
bash# modprobe squashfs
bash# lsmod|grep squash
squashfs 39620 0
</programlisting>
<para>
Then you have to add the squashfs module to /etc/modules if you need it loaded at boot time.
</para>
<programlisting>
bash# echo squashfs >> /etc/modules
</programlisting>
<para>
Note that at the time of writing, the Debian packages (Etch. 4.0 r2) relates to squashfs 3.1 release. Some latest options and features of 3.2 release may be not supported. Look at the next section for details.
</para>
</sect2>
</sect1>