Minimized Raspbian image (no X server) with SD card backup

Most of the time I am using Raspbian only in command line so I’ve decided to create a minimal image, with removed X server and other unnecessary stuff that is not needed for a server.

You might want to ask why to remove all the stuff when SD cards are cheap today? One reason is that with less packages there is lesser probability to have bugs in the system and other reason is that updates will take less time, as I don’t need to update packages that I don’t need.

Remove everything related to: X server, LXDE, Openbox, GTK, Alsa and TTF fonts. It will also remove the packages omxplayer, nano (vim rulez :), tsconf (for touch screens) and scratch (a programming environment aimed for kids).

sudo apt-get purge xserver* x11-common x11-utils x11-xkb-utils x11-xserver-utils xarchiver xauth xkb-data console-setup xinit lightdm libx{composite,cb,cursor,damage,dmcp,ext,font,ft,i,inerama,kbfile,klavier,mu,pm,randr,render,res,t,xf86}* lxde* lx{input,menu-data,panel,polkit,randr,session,session-edit,shortcut,task,terminal} obconf openbox gtk* libgtk* alsa* nano scratch tsconf desktop-file-utils omxplayer
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get clean

Not entirely sure why, but apt-get autoclean will remove Python libraries for GPIO and camera, so I had to install them back

sudo apt-get install python-picamera python3-picamera python3-rpi.gpio python-rpi.gpio

Finally remove some files that left and I don’t think they are necessary

rm -rf /usr/share/icons/ /usr/games/ /usr/share/themes/ /usr/share/images/ /home/pi/python_games/

Before cleanup:

Filesystem                    Size  Used Avail Use% Mounted on
rootfs                        2.9G  2.5G  245M  92% /
/dev/root                     2.9G  2.5G  245M  92% /
devtmpfs                       88M     0   88M   0% /dev
tmpfs                          19M  228K   19M   2% /run
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                          37M     0   37M   0% /run/shm
/dev/mmcblk0p1                 56M  9.8M   47M  18% /boot

After clean up:

Filesystem                    Size  Used Avail Use% Mounted on
rootfs                        2.9G  922M  1.9G  34% /
/dev/root                     2.9G  922M  1.9G  34% /
devtmpfs                       88M     0   88M   0% /dev
tmpfs                          19M  224K   19M   2% /run
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                          37M     0   37M   0% /run/shm
/dev/mmcblk0p1                 56M  9.8M   47M  18% /boot

Image size went down from 2.5GB to 922MB which is significant improvement and after reboot everything seems working…

It is always a good idea to backup, so let create an backup of the SD card with dd command. You have to know which device is your SD card, how to do so I have explained here. Insert SD card to your Mac or Linux and run dd command (replace /dev/diskX with your path).

dd if=/dev/diskX of=/path/to/image bs=1M

In my case it would be

dd if=/dev/sdc1 of=~/raspbian-wheezy-minimized.img bs=1M

On some systems (like Mac) 1M has to be lower case 1m. This command takes quite a while. So grab a coffee and read another article.