James, I realize I'm top posting, but I have nothing to add or comment on what you've written and want people to see this first... What you've given us is a gem, and doesn't even need much polishing... Have you considered submitting it as a mini-howto? I'm definitely going to keep this one around. Jim Cunning Today at 4:22pm, James Oakley wrote:
On Tuesday 05 April 2005 12:53 pm, Robert Rozman wrote:
I got advice to go on another route. To take minimal install (Why SuSE installs default system with KDE, although one can comment that out in installation process?) and then delete all unneeded packages. But here comes dependency hell. Each package requires or depends on another and sooner or later you want to erase one part of yast and then whole yast in second dependency level... Any better way to do this? Should I ignore dependencies ?
I've done this before (I've also created small distros from scratch).
Here's my preferred method:
Make a directory to work in and make the following subdirectories under it:
RPMS/ root/ custom/ config/ scripts/
Make a config file under config containing some variables:
BASEDIR="/path/to/your/work/directory" ROOTDIR="$BASEDIR/root" RPMDIR="$BASEDIR/RPMS" ... and so on...
Put all of the SUSE packages in RPMS
Make a list of packages you want and put it in the file config/packages, one per line, just the names (no versions)
Make a script under scripts to install the RPMS in $ROOTDIR:
#!/bin/bash # Source your config variables (assuming you're running this script from the # main work directory) . config/config
# Clear out directory so we start fresh if [ -z $ROOTDIR ] ; then echo "ROOTDIR not defined" exit 1 fi rm -rf $ROOTDIR mkdir $ROOTDIR
# Get filenames for requested packages RPMFILES="" for pkgname in `cat config/packages` ; do for rpmfile in $RPMDIR/$pkgname-* ; do if [ `rpm -qp --queryformat '%{NAME}' $rpmfile` = $pkgname ] ; then RPMFILES="$RPMFILES $rpmfile" break fi done done
# Create some initial directories for d in etc var/lib/rpm tmp dev ; do mkdir -p $ROOTDIR/$d done
# Initialise rpm db rpm --root=$ROOTDIR --initdb
# Install packages under $ROOTDIR rpm --root=$ROOTDIR --excludedocs -Uvh $RPMFILES
######### end
This attempts to install the requested rpms leaving out any files marked %doc. It will definitely fail the first time, so keep adding needed packages to config/packages as necessary until everything installs ok. This will take a while, but you will be sure you have the necessary dependencies and you gain a better understanding of what goes in a Linux system.
Now create a file, config/removelist, containing a list of directories and files left over that you want to remove (including rpm, which you no longer need at this point):
/usr/share/man /usr/share/doc /bin/rpm /var/lib/rpm /usr/lib/rpm ... and so on...
I use mc to browse the resulting filesystem to look for binaries and other filesI don't need.
Remove them like this:
for f in `cat config/removelist` ; do rm -rf $ROOTDIR/$f done
Now put any files you want to add or overwrite (config files, scripts, etc) in their target directories under the custom directory. To add them to the root system do
cp -a $CUSTOMDIR/* $ROOTDIR
Now you can make a script to format your CF device and copy the resulting system to it.
While that all looks like a lot of work, it's worth it. You will be able to reproduce your image at any time and you will never get into the situation where you tweaked something and forgot about it 3 months later. Also, upgrading rpms is easy. Just replace with newer packages and rebuild.
At this point your system will be roughly equivalent to SUSE's rescue system, but if it's not small enough, you can go further.
One thing you can do is replace a lot of stuff with Busybox. Busybox is a program that contains the functionality of a *lot* of standard commands in one small binary. To use it, simply replace your binaries with symlinks to busybox. Say busybox is installed in /bin/busybox. Your /bin might look like this:
lrwxrwxrwx 1 root root 7 Dec 31 1969 ash -> busybox -rwxr-xr-x 1 root root 204252 Dec 31 1969 busybox lrwxrwxrwx 1 root root 7 Dec 31 1969 cat -> busybox lrwxrwxrwx 1 root root 7 Dec 31 1969 cp -> busybox ... and so on...
As you can imagine, you will save a lot of space this way.
Another thing you can do is get rid of libraries you don't need, such as openldap. To do this you need to rebuild packages that depend on it. To find out which packages to rebuild, do this:
rpm -q --whatrequires libldap.so.2
Grab the source packages, edit the spec files, and modify the ./configure lines. If you see a '--with-ldap' or similar, remove it and rebuild. If you don't see a '--with' option, you may have add '--without-ldap' or similar. Use ./configure --help to see what you can do here.
Finally, you can save even more space by using a cramfs image for parts of the filesystem that will not change. This can get a bit complicated because you can't write to a cramfs. You'd have to split the system into writeable and non-writeable areas and make a custom initrd that mounts the cramfs filesystem, then the writeable areas.
I once made a minimal system where I copied /etc and /root to /var, created symlinks for them, tarred all of /var to a file on the cramfs, then removed everything under /var. The initrd mounted the cramfs, mounted a ramfs on /var, and untarred the file to the ramfs.
Of course, since you're using Asterisk, you'd probably want your writable directories persistent, so you could use a separate partition instead of the ramfs+tarball approach I used.
Hope that helps,