24

I've been building a Linux distro, and I've stripped the binaries, etc. The system won't use GCC or development tools, as it will be a Chrome kiosk, so it would greatly help if I could strip down the system...

I was wondering, is there a way that I can delete all of the unused system files (like binaries, etc.) by watching what files/libraries are used during runtime? Maybe another method is preferred, but is there a way to accomplish something like this?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Blender
  • 1,853
  • 2
  • 18
  • 25
  • 3
    Indeed you are in THE correct place this time :) – phunehehe Dec 10 '10 at 03:56
  • 2
    Now, might I ask, why is there a separate Ubuntu-based Stack Exchange site? I think they should merge with this site, because AFAICT, Ubuntu *should* be considered Linux/Unix, but I'm not too sure ;) If not, get ready for GentooOverflow and FedoraOverflow! – Blender Dec 10 '10 at 16:43
  • 3
    @Blender: This merge was considered and rejected. Look in the two sites' Meta for the history. – Gilles 'SO- stop being evil' Dec 10 '10 at 18:35
  • 3
    I've found the ubuntu site is a lot more about gnome programs and user interface stuff. Here your answer will almost certainly be a terminal command. – Falmarri Dec 10 '10 at 23:59
  • take a look at busybox for one thing – Robert S Ciaccio Dec 11 '10 at 03:20
  • I was looking a `busybox`, but I first have to get my tiny X server running, as that takes up the most space. Thanks! – Blender Dec 11 '10 at 16:55
  • 2
    My understanding is that AskUbuntu is to Unix and Linux as Unix and Linux is to SuperUser: if it's an ubuntu-specific question, it goes to AU; if it's otherwise *n*x-ish, it goes here; otherwise it goes to SU or to ServerFault. – intuited Jan 06 '11 at 05:04

5 Answers5

11

There are programs like Bootchart that can be used to show what programs you ran during startup - you can probably keep it going after boot to see what's been invoked during a session.

A better solution may be to use remastering tools.

There are remastering tools for Fedora, Ubuntu, and others; you can use these to customize a distribution.

You might want to look at Tiny Core Linux. There is a guy working on a remaster script for that as well.

Shawn J. Goff
  • 45,338
  • 25
  • 134
  • 145
  • When I get home, I will definitely try Bootchart. I lied, though, as the system just finished compiling last night, so I'll have to *really* get it running in the next few days. I found TinyX (which is what I was looking for, as I can't figure out what XOrg modules I really need), but the website was down... Oh well, but thank you very much! – Blender Dec 10 '10 at 15:22
  • Bootchart it is! I compiled it, ran it, and it gave me extremely verbose and useful results. I'm not going to strip the system *just* yet, as I'm going to implement a source-based package manager (Gentoo?), but I will definitely use this. Thanks! – Blender Dec 13 '10 at 15:29
6

Amongst other things, you want to remove everything you don't need. Make sure the filesystem has atime fully enabled; you can set this in /etc/fstab. The current default is relatime but you want to use just atime. Every time a file is accessed, the timestamp will get updated. Then do some usage for a few days to see which files have never had their atime updated. I would do all of this in a VM, and very carefully, because I imagine there are a few files that are read when the system is in read-only mode. Note: set it to noatime once you're ready for production, otherwise you'll do a write every time you read; this is inefficient.

Though to be honest, I'd look at Damn Small Linux; do you really need to be smaller than that? Build yours based on their distro and simply remove the window manager and a few extra programs. Leave all the command-line tools, that way if you ever need to repair or reload you have the shell.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
xenoterracide
  • 57,918
  • 74
  • 184
  • 250
  • Thanks! I'm trying to do it myself, as I've never really gotten a fully usable LFS system running, but I've played with DLS before. I'm actually trying to build a ChromeOS clone that is not made with SuSEStudio (the one from chromium.org is), and is a bit smaller than 600MB ;) My goal is > 50MB, as DSL includes a ton of other software, but I'm only installing OpenBox, Chrome, and a custom-built Thunar (and some other goodies, of course). Thanks! – Blender Dec 10 '10 at 15:23
5

assuming you are using Debian or it's derivatives

After some days of (heavy) usage, run popularity-contest. It will display the oldest unused packages at the bottom. Uninstall those, but with a watchful eye on whether or not there's stuff depending on them installed.

Here's a snippet of the output:

1294222606 1292570417 vlc /usr/lib/vlc/plugins/gui/libqt4_plugin.so
1294222606 1292570109 xulrunner-1.9.2 /usr/share/xulrunner-1.9.2/chrome/classic.jar
1294222606 1292507839 ttf-dejavu-extra /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Oblique.ttf
1294222606 1292507459 x11-utils /usr/bin/xprop

The colums mean atime, ctime, package-name, and file accessed.

tshepang
  • 64,472
  • 86
  • 223
  • 290
1

Actively use your system for a while with file access times enabled. See what files never have their access time modified. These are candidates for deletion (but make sure there isn't a reason to keep them, e.g. because they're hardware drivers for hardware you don't have, or they're needed early in the boot process when the root partition is still mounted read-only).

Since you'll have few big applications, check what libraries are used by a single executable. Consider linking them statically.

ldd /bin/* /usr/bin/* |sed -n 's/^.* => \(.*\) (.*)$/\1/p' |sort |uniq -c
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
0

Where exactly are you starting from? Are you stripping an existing distro? Is there a reason you have to start with any distro?

You might want to consider building an embedded system from scratch and load only what you know you need.

Falmarri
  • 12,897
  • 17
  • 58
  • 71