LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   Runtime size Optimization (https://www.linuxquestions.org/questions/linux-from-scratch-13/runtime-size-optimization-4175482424/)

AN28 10-28-2013 12:06 AM

Runtime size Optimization
 
Hi,

I am interested in reducing the size of my LFS build and have been reading up on possible options and hints.

In most articles they recommend UPX!

So i thought i to try it as well. However I have a small issue on which version to download.

My machine type is i686-32 bit and I would like to know which of the options available should I go ahead with.

Thanks in advance!

AN28 10-28-2013 12:52 AM

Quoting this article,
Quote:

Stripping binaries and libraries can free a lot of space. Use the instructions
provided in the LFS book to do this. To find out whether there are still
unstripped libraries or binaries, run the following command:
# find / -exec file {} \; | grep "not stripped"
These can be stripped as well.

Can someone please tell me how I can strip these binaries/libraries. When I run the command suggested as above I get a long list with majority ending in
Quote:

dynamically linked, for GNU/Linux 2.6.25, not stripped

Lennie 10-28-2013 03:09 AM

It's in the book...

pan64 10-28-2013 03:10 AM

there is a command, named strip to do that.

AN28 10-28-2013 05:07 AM

So is it ok to use the commands as given in LFS even after completing BLFS?
Also do you guys know about UPX?

pan64 10-28-2013 05:13 AM

you can use strip any time, it will not affect the running system (you may have problems during troubleshooting).
you will need i386 version of upx.

AN28 10-28-2013 05:48 AM

Thank You pan64 :)

AN28 10-28-2013 10:33 PM

Hi again,

I used
Quote:

find / -exec file {} \; | grep "not stripped"
from a blog post article to find the unstripped executables but do not have a proper understanding on the sed notations.

Can I use
Quote:

strip --strip-unneeded -exec file {} \; | grep "not stripped"
to strip all the unneeded exec ??

pan64 10-29-2013 01:20 AM

no, that won't work at all.
the command find / -exec file {} \; will print out all the files together with their types you have and grep will filter the result (will select only the lines containing "not stripped").
the command find has this special syntax (where you can specify what are you looking for), but you cannot use the same syntax with strip. Instead, you need to combine the two commands to achieve what you need.
that will look like:
Code:

# this will be a small shell script, named strip.sh
#!/bin/bash

F="$1"
file "$F" | grep -q 'not stripped' && strip --strip-unneeded "$F"
}
# end of script

# and now you can execute the find command:
find / -exec strip.sh {} \;


AN28 10-29-2013 03:35 AM

Thank You for the explanation but I have a few doubts though....

Quote:

file "$F" | grep -q 'not stripped' && strip --strip-unneeded "$F"
}
should there be a paranthesis on the new line? If so why?


should the find command be within the strip.sh file or is that just the command to run in the terminal.
Because when I run it from the terminal i get the error:
Quote:

find: `strip.sh': No such file or directory
despite the fact that I set permissions for the sh file.

pan64 10-29-2013 03:44 AM

you may need to write ./strip.sh or <full path to>/strip.sh

} is a mistake, just a copy&paste error or something like that, please ignore that.

AN28 10-29-2013 04:02 AM

I replaced the find command with
Quote:

find / -exec ./strip.sh {} \;
and I get the recursive output
Quote:

./strip.sh: pipe error: Too many open files

pan64 10-29-2013 04:36 AM

I do not know what have you actually done, how your strip.sh script looks like, therefore hard to say anything.

AN28 10-29-2013 04:59 AM

It is pretty much the same as what you suggested only corrected the mistakes of } and the path to strip.sh

Quote:

# this will be a small shell script, named strip.sh
#!/bin/bash

F="$1"
file "$F" | grep -q 'not stripped' && strip --strip-unneeded "$F"

# end of script

# and now you can execute the find command:
find / -exec ./strip.sh {} \;


---------- Post added 10-29-13 at 04:59 AM ----------

It is pretty much the same as what you suggested only corrected the mistakes of } and the path to strip.sh

Quote:

# this will be a small shell script, named strip.sh
#!/bin/bash

F="$1"
file "$F" | grep -q 'not stripped' && strip --strip-unneeded "$F"

# end of script

# and now you can execute the find command:
find / -exec ./strip.sh {} \;

pan64 10-29-2013 05:43 AM

you should not include the find (in the script), that should be executed in a shell - see there is an end of script line!


All times are GMT -5. The time now is 05:29 AM.