[SOLVED] How can I shrink a working root file system for embedded Linux
Linux - Embedded & Single-board computerThis forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I shrink a working root file system for embedded Linux
Hello,
I have a JFFS2 root file system that takes about 20MB on the NAND flash of my ARM9 processor, and it is working fine with Linux 3.2 (Ångström distro).
I want to convert the JFFS2 into a RAM file system, but before that, I must minimize its size so that it won't make the overall kernel too large. The problem is, I don't know how to do that.
This forum thread explains the necessary components of a root file system pretty well. It suggests, for instance, that the /lib directory is needed only if the executables are linked dynamically.
I build my executable with
Code:
gcc -static ...
so I expect it to be statically linked only. When I issue the
Code:
ldd <program>.out
command, I get: "not a dynamic executable". However, if I type:
Code:
file <program>.out
I get:
Code:
ELF 32-bit LSB executable, ARM, EABI5, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.16, not stripped
So does my program need any shared object in the /lib directory (like pthread, for example)?
I tried removing all shared objects in the /lib directory, which resulted in all programs (including shell commands) malfunctioning, stating that needed shared libraries are missing.
Long story short, how can I know which files in my 20-MB root file system (not just library files, but files of any kind) are expendable?
Thanks in advance,
OkCalis
Last edited by OkCalis; 01-11-2019 at 01:43 AM.
Reason: Clarification
ELF 32-bit LSB executable, ARM, EABI5, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.16, not stripped
So does my program need any shared object in the /lib directory (like pthread, for example)?
No, but as the file command shows, the shared library loader (/lib/ld-linux.so.3) is needed for your program, even though it has nothing to do.
Quote:
I tried removing all shared objects in the /lib directory, which resulted in all programs (including shell commands) malfunctioning, stating that needed shared libraries are missing.
Long story short, how can I know which files in my 20-MB root file system (not just library files, but files of any kind) are expendable?
Mostly by trial and error. Most of the supplied system binaries in /*bin will be shared executables so most of the basic /lib (and probably /usr/lib) libraries will be needed for them. But most savings can be made in the /usr tree (and luckily that mostly is the largest one). But then again, 20MB is already quite small, my /lib is about 250 MB
BTW: not using shared libraries will increase the size of your own executables by quite a bit, so maybe you should experiment with NOT compiling them as static executables.
One of the reasons for shared executables is that one time all functions takes up less space then all of the executables having separate copies of some of those functions.
Of course, this does depend on how many executables you build, but as most shared libraries are there anyway, why not use them?
Last edited by ehartman; 01-14-2019 at 07:29 AM.
Reason: explanation about shared objects
Thanks, Ehartman, your explanation was very useful.
I'm going to remove the /bin and /sbin executables step by step until I see something goes wrong.
Also, I'll remove the "-static" option from my makefile, since it does not seem to offer any advantages.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.