Support for compressed kernel modules
Yann E. MORIN
yann.morin.1998 at anciens.enib.fr
Tue Nov 28 14:41:39 PST 2006
Rory, Luciano,
All,
On Monday 27 November 2006 234, Luciano Miguel Ferreira Rocha wrote:
> On Mon, Nov 27, 2006 at 02:19:41PM +0100, Rory Vieira wrote:
> > I'm running out of rootfs space, and can save roughly 1Mb if I
> > compress the kernel modules.
> > Does this version of busybox come with modprobe with gzip support?
> > And if so, how do I enable this?
If you're that short on space, then, as already suggested by Rob and Florian,
you'd be better off using a compressed file system:
- cramfs has been standard in linux kernel for a while now, but read-only;
- squashfs only needs a patch, is really stable and proven, and is fairly
powerfull wrt compression ratio, but is also read-only;
- jffs2 is not as good as the two file systems above and needs to lie on an
MTD device (such as a real MTD or a pseudo, RAM- or block-based, MTD, such
as mtdram), but is read/write.
A compressed file system offers the following advantages:
- seamless access to your files, as compression/decompression is done in the
file system: you access your files as though they were not compressed;
- all files are compressed, giving you even more space back;
- depending on your need, it might also offer write protection, if you don't
need write access (cramfs and squashfs).
But read on...
> If you apply the attached patch to busybox, and use the attached insmod
> script instead of busybox's, you can use compressed modules:
[--SNIP--]
That's a rather good idea, but I'd go a bit further:
- apply the suggested path, but please note that by doing so you bypasses
(is that correct phrasing?) an optimisation;
- remove busybox's installed "insmod" link;
- have the following script (fixed, tweaked, and commented from the suggested
one) called "insmod" and lying in the PATH (/sbin should be the place):
---8<---
#!/bin/sh
INSMOD="busybox insmod"
MODULE="$1"
[ -e $MODULE ] && exec $INSMOD $MODULE
umask 077
# Please note that calling mktemp is not safe, as it introduces
# a race. But you should be quite safe if untrusted users don't
# have shell access to the machine (embedded stuff), or you trust
# your users enough (which you should not ;-]) with shell access:
T=`mktemp -d /tmp/mod.XXXXXX`
[ $? -eq 0 -a -n "$T" ] || exit 1
# Exit gracefully by removing the temporary directory:
trap "rm -fr $T" EXIT
# Exit at the first error (still calling the above action):
set -e
cd $T
# I'm not quite sure these would work with anything else
# but bash and ash (lash and hush might have problems):
FILE="${MODULE##*/}"
KVER=${MODULE#/lib/modules/}
KMOD=${KVER#*/}
KVER=${KVER%%/*}
KDIR=/lib/modules/$KVER
if [ -e "$MODULE.gz" ]; then
zcat < $MODULE.gz > $FILE
$INSMOD $FILE
elif [ -e $KDIR/modules.tgz ]; then
tar xzf $KDIR/modules.tgz ./$KMOD
$INSMOD ./$KMOD
elif [ -e $KDIR/modules.cgz ]; then
zcat < $KDIR/modules.cgz | cpio -id $KMOD > /dev/null
# Hmmm. Should that be $KMOD or ./$KMOD ? I don't know cpio,
# so you'll have to check:
$INSMOD $KMOD
else
# Needed to mean the module was not found after all
# (in case depmod was not run after a module update):
exit 1
fi
---8<---
Disclaimer: script untested, you might need some adjustements...
But again, a compressed file system would be even better, for all it gives you.
Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +0/33 662376056 | Software Designer | \ / CAMPAIGN | ^ |
| --==< °_° >==-- °------------.-------: X AGAINST | /e\ There is no |
| http://ymorin.is-a-geek.org/ | (*_*) | / \ HTML MAIL | """ conspiracy. |
°------------------------------°-------°------------------°--------------------°
More information about the busybox
mailing list