Typo
[linux_from_scratch_hints.git] / OLD / stripped-down.txt
blobbff9954af1cc55f2079cb8e42d1764c9c1b3ec1e
1 TITLE:          Stripping down an LFS
2 LFS VERSION:    4.0
3 AUTHOR:         James Smaby <jsmaby@virgo.umeche.maine.edu>
5 SYNOPSIS:
6         A freshly built LFS is smaller than most distros, but still contains
7         much cruft that can be removed.  Knowing what to remove takes knowing
8         your system, but here are some pointers.
10 HINT:
11     This hint can be followed right after building LFS, or perhaps best, after
12 all additional software is installed as well.  Stripping a system mostly takes
13 going through all the directories and removing stuff you don't need/use.
14     If you are looking for a small system, you should consider compiling stuff
15 with -Os, which tells the compiler to optimize for size, usually a good thing.
16 It is normally okay to compile with -fomit-frame-pointer, but do not use it on
17 glibc or anything you plan on debugging.  If you don't use NLS, you can config
18 packages with --disable-nls to conserve some room.  Adding -s to your LDFLAGS,
19 or using "gcc -s" as your CC will save some work later, because most libraries
20 and binaries will be already stripped before installing them.  Stripping glibc
21 while the system is running, for instance, can be problematic.
22     Before getting started, maybe ask yourself if it might be best to build up
23 the system in an additive manner, copying over the files you need (like for a
24 floppy-based router) instead of removing stuff you don't need.  Perhaps using
25 busybox will meet your needs better than LFS in this case.
27     The first thing I like to do is remove things from /usr/share, like docs
28 and locales.  If you use info, you can compress the info pages.  Otherwise,
29 remove them.  Then do the same with /usr/share/man and /usr/share/doc.  You
30 could do what I do, and keep compressed man pages, and remove the docs dir
31 and the info pages.  Note that in order to compress the man pages, you may
32 have to fix some links between them.  Look for hard links by:
33   # ls -l /usr/share/man*/* | grep -v "1 root"
34 and symbolic links by:
35   # find /usr/share/man -type l
36 In the case of hard links, decide which one you want for the master copy
37 and remove the others.  You can then recreate the others by:
38   # echo ".so gzip.1" > /usr/share/man/man1/zcat.1
39 for instance.  Make sure you remove the link first otherwise the master
40 copy will be clobbered.
41     You can remove any locales, timezones, and keymaps that you don't
42 use.  If you don't use NLS, you can remove all the locale info (there
43 is data in /usr/share/locale and /usr/lib/locale), although you might
44 get warnings like
45   Gdk-WARNING **: locale not supported by Xlib, locale set to C
46 from gtk-using apps, which can be ignored (or hacked from of the glib
47 source code).
48     If you copy your timezone to /etc/localtime instead of making the
49 normal symbolic link, all of /usr/share/zoneinfo can be removed.  You
50 can remove /usr/share/kbd, and either create a keymap file somewhere:
51   # dumpkeys > /etc/dvorak.map
52 or compile your keymap into the kernel:
53   # dumpkeys | loadkeys -m - >/usr/src/linux/drivers/char/defkeymap.c
54 The keymap file will have to be loaded upon startup, while if it's put
55 in the kernel, the system will start with that keymap loaded.  One can
56 not simply copy the keymap file from /usr/share/kbd because those maps
57 include files, and tracking down all the dependencies is a pain.  Using
58 dumpkeys will insure that all the needed info is in one file.
59     You can remove terminfo files that you don't use.  For instance, you
60 could remove all the terminfo files except for linux and xterm, but this
61 takes knowing what terminal types you use; If you do not know, leave them
62 alone for now, and you'll see what files aren't used later.
64     If you don't use the auto tools in any of your projects, and you don't
65 download source from cvs which relies on autoconf to build (like if there's
66 a autogen.sh but no configure script), it's safe to remove /usr/share/auto*
67 and /usr/share/aclocal*.
68     Basically, most of the dirs in /usr/share can be removed even if you use
69 the programs that go with them.  Take a look inside the dirs, and if none of
70 the files look `important', remove it.  If you want to play it safe, move the
71 files to a temporary place, and see if anything misses their absence.  My own
72 system, with various extra programs installed, has a /usr/share that is like:
73   aspell dict        gnuplot.gih irssi   man  psutils  texmf
74   bison  ghostscript groff       libtool misc terminfo vim
75 Again, if you're not sure if you need the files or not, leave them be, and you
76 will see which files get used later.
78     Next up is the hard part; look at each binary installed in the PATH: /bin,
79 /sbin, /usr/bin, and /usr/sbin.  If you don't know what it does, then read the
80 man page, and decide if you need it or not.  If you know what it does, and you
81 know that you don't need it (like bzdiff, dir, bashbug, etc.), then remove it.
82 This is the point where you get to really learn your system.  There'll be some
83 binaries that don't have man pages, don't offer any help, and who's purpose is
84 not obvious.  Play it safe and leave it be in that case.  You'll get to see if
85 it is not used later.
86     Chances are, your /usr/sbin will be pretty small after stripping it down.
87 I like to just move whatever is left in there to /sbin, and have one less dir
88 in my PATH.
90     It's not so easy removing stuff from /usr/lib, as it is not obvious what
91 is needed.  Indeed, ldd doesn't even show all of the runtime dependencies as
92 a binary could load shared libraries after running.  It is safest to remove
93 only the debugging and profiling libraries, and leave it at that.  A couple
94 packages might install these (glibc and and ncurses), and they end in _g.a
95 or _p.a.  They can be removed if you do not plan on debugging or profiling
96 code that uses them.
97     The .la files installed by libtool are unneeded by anything that I've
98 found (except some for parts of kde), and can be removed (well, I always
99 remove them and haven't run into trouble yet).  They're pretty small but
100 they add clutter, and clutter is a bad thing.
101     The static libraries will not have been stripped by `-s' since they
102 are not linked so strip out the debugging symbols now:
103   # strip -g /usr/lib/*.a
105 Now is as good a time as any to look for any other binaries that need
106 stripping.  Run the following command to see which programs/libraries
107 still have debugging symbols in them:
108   # find / -exec file {} \; | grep "not stripped"
109 This will print out the names of some binaries that didn't honor your
110 CC or LDFLAGS, and a few other files, maybe in subdirs of /usr/lib or
111 hiding in odd places.  If it ends in .o or .a, use strip -g on it, so
112 that you don't clobber all the symbols.  Any other binary is probably
113 linked, so can be run with just plain strip.  Do not strip any binary
114 or library that's currently in use, as it's possible that the program
115 using it will crash.  If the strip program, bash, or glibc need to be
116 stripped, I recommend doing so from the host.
118     There's still a lot that can be removed, like subdirs of /usr/lib,
119 files in /etc, and binaries you are not sure are needed or not.  Maybe
120 the easiest way to find out what to keep is to do the following:
121   # touch /var/tmp/timestamp
122 Now use the system like normal.  Reboot a couple times.  Build a kernel.
123 Maybe build another LFS. Just use the system.  After a week or so of use
124 you will have accessed any files that will ever need to be accessed.  Run
125 the following command to see which files have not been accessed since you
126 touched the timestamp.
127   # find / -not -anewer /var/tmp/timestamp
128 Now go through this listing, and look for anything that looks important, or
129 that you know you might someday want (like documentation).  Everything else
130 can most likely be removed.  If you want to be safe, move all the files to a
131 temporary location out of the way.  Maybe put them on a cdrom backup.
132     Note that for this trick to work, nothing should be mounted read-only or
133 noatime during the usage time, otherwise the atime's of the files will not be
134 updated, and everything will appear to be unused.
136     After you have your system stripped down, look through every directory for
137 anything you don't want.  This may include some files that you accessed during
138 the usage time, but didn't mean to (like looking inside configuration files in
139 /etc to see what's in them).
140     Another good thing to do in the final pass-through is to use du -sh on the
141 different directories to see how much space they are taking up.  If you find a
142 particularly bloated one, concentrate efforts on slimming it down, like if you
143 see that /usr/include is taking up more room than you want it to, you could do
144 a very evil thing and strip out all the comments from the header files.
146 Good luck, have fun, and I hope you made a backup first ;-)