Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 22 Oct 2014, 06:18
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
Remove unneeded modules and firmware
Moderators: Flash, Ian, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Sun 17 Jan 2010, 23:33    Post_subject:  Remove unneeded modules and firmware
Sub_title: only what you need for your system
 

New versions available for testing here:
http://www.murga-linux.com/puppy/viewtopic.php?t=51552

TODO
Generate firmware module dependencies dynamically from either /etc/modules/firmware.dep or /etc/modules/firmware.dep.$(uname -r)
Build a list of modules that may not be loaded and still wanted (+gui)
Make it easier to integrate into remaster script.

_________________
Web Programming - Pet Packaging 100 & 101

Edited_times_total
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Mon 18 Jan 2010, 20:23    Post_subject:  

Progress update:

lsmod > tmp #puts raw ouput in file mods
sed -i "1,1 d" tmp #removes the header line
sed -i "s/ /\*\) /g" tmp #can be .ko or .ko.gz & maybe others
cut -d " " -f 1 tmp > mods #removes all but the first column
sed -i "s/_/?/g" mods #replaces the _ with ? so that - and . will not give false evaluation
echo *) rm $FILE;; >>mods

while {recurse directories in /lib/modules/ --***NEED to CODE still***---}
case $FILE in
. $PATHTO/mods
esac

cp -a /lib/modules $DESTDIR/lib/modules
dir2sfs $DESTDIR
Now you have a case condition for each module that does nothing - can add stuff to steps 3 & 4 if we later find we need to do something on the fly (perhaps cp $FILE $DEST/lib/modules....), but for now will just use the final *) to delete the modules that do not match

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
amigo

Joined: 02 Apr 2007
Posts: 2258

PostPosted: Tue 19 Jan 2010, 16:07    Post_subject:  

Code:
#!/bin/bash

CWD=$(pwd)

# set this to the name of a temp dir:
TMP=/tmp/mymodules

# create the module directory in the TMP dir:
mkdir -p $TMP

# get the version of your kernel
KVERS=$(uname -r)

lsmod |tail +2 |cut -f1 -d' ' > $CWD/mods

cd /
for module in $(cat $CWD/mods) ; do
   # uncomment the first and comment the second one to just see the list
   # find lib/modules/$KVERS -type f -name "$module*\.o"
   find lib/modules/$KVERS -type f -name "$module*\.o" -exec cp --parents {} $TMP/ \;
done

depmod -b $TMP/lib/modules/$KVERS -e -F /path/to/kernel/System.map


You'll need to run depmod on the created directory so that the module symbol tables are created.
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Tue 19 Jan 2010, 21:53    Post_subject:  

Yeah! it builds now - thanks for the assist amigo - now time to remaster and reboot
Code:
#!/bin/sh
. /etc/DISTRO_SPECS #gets $DISTRO* variables
KERNELVER=$(uname -r) # get the version of your kernel
PREFIX1CHAR="`echo -n "$DISTRO_FILE_PREFIX" | cut -c 1`"
KERNEL3CHARS="`echo -n "$KERNELVER" | tr -d '.' | tr -d '\-' | tr -d '[a-z]' | rev | cut -c 1,2,3 | rev`"
ZDIR="z${PREFIX1CHAR}${DISTRO_VERSION}${KERNEL3CHARS}"
# set this to the name of a temp dir:
TMPDIR=/mnt/shm/$ZDIR
# create the module directory in the TMP dir:
mkdir -p $TMPDIR
lsmod |tail +2 |cut -f1 -d' ' > $TMPDIR/mods #just a list of modules
sed -i "s/_/?/g" $TMPDIR/mods #replaces the _ with ? so that - and . will not give false evaluation
cd /
for module in $(cat $TMPDIR/mods) ; do
   # uncomment the first and comment the second one to just see the list
   # find lib/modules/$KVERS -type f -name "$module*\.o"
   find lib/modules/$KVERS -type f -name "$module*" -exec cp --parents {} $TMPDIR/ \;
done
mv /lib/modules /lib/modules~ # can't force a link over a directory
ln -s -f $TMPDIR/lib/modules /lib #use link so busybox depmod works
depmod #-b $TMPDIR/lib/modules/$KERNELVER -e -F /path/to/kernel/System.map
rm $TMPDIR/mods #cleanup
dir2sfs $TMPDIR
mv $TMPDIR"_"$DISTRO_VERSION.sfs ~/$ZDIR.sfs #move to $HOME
mv $TMPDIR"_"$DISTRO_VERSION.sfs-md5.txt ~/$ZDIR.sfs-md5.txt #move to $HOME
rm -rf $TMPDIR
rm -rf /lib/modules
mv /lib/modules~ /lib/modules

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Wed 20 Jan 2010, 21:11    Post_subject:  

cool, the firmware deps are in /etc/modules/firmware.dep and /etc/modules/firmware$(uname -r).dep - that should help with code to reduce some of the firmware dependencies

I hard-coded it for now for testing, but it seems that it would be possible to build the "case ... esac" for the firmware directly from firmware.dep using sed and cut

NOTES for adding dynamic creation:
sed to
replace ".ko," with |
replace ".ko" with )
cut
using : to separate firmware from modules and -s to remove comments
cut -d ":" -f 1 for firmware
cut -d ":" -f 2 for modules
then go line by line using echo to build the commands
echo $moduledeps" echo "$firmware" >>$TMPDIR/fw;;"
zdrv_cutter-0.2.pet
Description 
pet

 Download 
Filename  zdrv_cutter-0.2.pet 
Filesize  2.02 KB 
Downloaded  303 Time(s) 

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0581s ][ Queries: 12 (0.0048s) ][ GZIP on ]