Debian: unnecessary essential packages in a chroot environment

chrootdebian

I have set up debian 8 (jessie) in a chroot environment (on an android phone, but that is not important to this question), and noticed that it is quite large.
I have then removed all packages that are not essential and not used by me (ssh and rsync currently), and the size is still about 200MB (I used deborphan excessively in the process).

The question is: can I remove some essential packages so that the system will keep functioning (e.g. I do not need console login and a lots of device management capabilities)?

Or is there a way to replace some essential packages with smaller alternatives?

Currently, my largest packages are:

# dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -nr | head -n20

13509   coreutils
9047    libc6
7004    dpkg
5198    bash
5043    gnupg
4811    perl-base
3842    openssh-client
3078    apt
2946    libc-bin
2893    e2fsprogs
2732    login
2692    util-linux
2555    tar
2478    libapt-pkg4.12
2268    libssl1.0.0
2218    passwd
1579    libdb5.3
1563    findutils
1447    libpam-runtime
1434    libslang2

Best Answer

Essential packages are necessary on a normal system, but a chroot isn't really a normal system. You don't need the packages that provide system services that Android is effectively providing (if in a way that won't let you do all you can do on a normal Linux system), such as init and login.

You can tell dpkg to remove packages marked essential with the --force-remove-essential command line option.

Of the packages marked essential in Debian jessie, for your use case, you don't need init, ncurses-base, ncurses-bin, diffutils, login, e2fsprogs and possibly not perl-base, base-passwd and base-files. Beyond that, there are many packages that debootstrap installs by default that you don't need, such as locales. You can also get rid of all documentation (/usr/share/doc, /usr/share/man, /usr/share/info) but there's no way to avoid the files there being rewritten on each package upgrade.

Another big one you don't actually need is coreutils, and possibly also not debianutils, bsdutils, gzip, mount and util-linux, if you replace them by busybox. If you don't care about having a comfortable command line shell, you don't need bash.

If you want to save space, and you only need SSH access and rsync, you can get something smaller than Debian. All you need is Dropbear, rsync and the libraries they need. Dropbear doesn't provide an SFTP server, so if you want that, you'll need to install the one from OpenSSH. There are a number of distributions designed for embedded systems with a base installation that doesn't include bash or perl, where all documentation comes in separate package, and where the standard library is not Glibc but a smaller alternative such as uClibc. Look for distributions with the opkg or ipkg package manager, such as OpenWRT and Optware, or others mentioned on the BusyBox product list.

Related Question