Purpose: In this series we will learn how to reduce the size of a Linux installation particularly Debian. We will try to get rid of unnecessary and “not so” important stuff from your system – Believe it or not there is lot of stuff that you can simply remove without harming your system.

Why do we need this
Ok, good and a perfectly valid question. If you believe a “lean” system is better than a “bloated” system then you know the reason why. Also most of the times in embedded systems you need stuff only that is absolutely necessary and essential and you want to get rid off everything that you are not going to use – the same reason why people compile custom kernel rather than using the stock kernel. The basic idea is that “Less is More”. Also this goes with the bottom-up approach rather than a top down approach – You install minimal things first and then one by one keeping stuff that you absolutely necessarily require.

Assumptions
I am going to start from a “Standard System” install of Debian Lenny (5.0) and then one-by-one we will start reducing the size of the system. By “Standard” system I mean no graphics stuff like X, GNOME, KDE, etc. – just pure console based system. Basically you can select this option from the

So let’s get started.

Default Standard Installation Size
Let’s say you install with “Standard System” option and after you finish installing you boot from your hard drive and give the following command:
# du -h
Note: We will be using this command a lot throughout the entire series to check the system size.
Output:
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1             3.7G  573M 2.9G  18% /
tmpfs                 247M     0  247M   0% /lib/init/rw
udev                   10M   80K   10M   1% /dev
tmpfs                 247M     0  247M   0% /dev/shm

As you can see your total system size is around 573 MB with a Standard base install.

Step 1: Un-select the “Standard System” option

With a very easy trick you save a lot of space by un-selecting the “Standard System” option during the installation phase as shown here:

Debian Installer Install Type Selection

Debian Installer Install Type Selection

After completing your installation when you boot into your system check the size of your system:

debian:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1             3.7G  459M 3.1G  13% /

Savings: 573-459=114 MB

Current System size: 459 MB

Step 2: Remove all the .deb installation files

By default Debian stores all the installable package files (*.deb) into your local repository that you either download from Internet or from CD-ROMs:

# ls /var/cache/apt/archives/
..........
vim-common_1%3a7.1.314-3+lenny2_i386.deb
vim-tiny_1%3a7.1.314-3+lenny2_i386.deb
wget_1.11.4-2_i386.deb
whiptail_0.52.2-11.3_i386.deb
x11-common_1%3a7.3+18_all.deb
xauth_1%3a1.0.3-2_i386.deb
zlib1g_1%3a1.2.3.3.dfsg-12_i386.deb

We really don’t need these installable files since we have already installed the packages. You we will remove them by giving following command:
# apt-get clean
and we check the space again:

debian:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1             3.7G  365M 3.2G  11% /

Savings: 459-365=94 MB

Current System size: 365 MB

Step 3: Install some cleaner tools

Let’s download some tools that will help us to further clean or reduce size of our system.

# apt-get install localepurge deborphan debfoster
# apt-get clean

Note: These tools will increase the size of your system but by a very small portion. Also note how we cleaned the .deb files for the above packages also by giving apt-get clean command after downloading them.

debian:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1             3.7G  368M 3.2G  11%

As you can see we only increased our system size by 3 MBs.

Savings: 365-368=-3 MB

Current System size: 368 MB

Step 4: Clear unwanted locales

This is going to give you a huge savings. Type the command:

# localepurge

Output:
localepurge: Disk space freed in /usr/share/locale: 37824K
localepurge: Disk space freed in /usr/share/man: 2476K
Total disk space freed by localepurge: 40300K

Basically this commands clears out all the locales (languages of different countries for translation) that are stored on your system. By default “en_US.UTF-8″ is only kept on your system.

debian:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1             3.7G  329M 3.2G  10% /

Savings: 368-329=39 MB

Current System size: 329 MB

Step 5: Clear orphan packages

Here we will remove packages which are orphaned i.e. they were installed as a dependency of other packages but since there parent packages are not there anymore they have not use.

# deborphan | xargs apt-get -y remove --purge

debian:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1             3.7G  327M 3.2G  10% /

Savings: 329-327=2 MB

Current System size: 327 MB

We saved 2MB of free space – yes I know that’s little but Hey in embedded system every MB counts.

Step 6: Remove Documentation and Manuals

Finally we don’t need documentation on an embedded system so we will remove all of them:
# rm -rf /usr/share/doc/
# rm -rf /usr/share/doc-base/
# dpkg --purge man-db manpages
# rm -rf /usr/share/man/

debian:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1             3.7G  309M 3.2G   9% /

Savings: 327-309=2 MB

Current System size: 309 MB

As you can see just by giving few commands and with some tricks we were able to reduce the size of our default Debian Lenny installation system from 537 MB to 309 MB i.e. we saved around 228 MB of space.

In our next part we will see some more techniques to further reduce the size of our Linux installation. Stay tuned!

Be Sociable, Share!