3

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
  • What do you need? And what software did you pick while installing? – muru Sep 29 '15 at 16:21
  • This depends which features you want in the chroot. From your list, I would only consider to remove e2fsprogs (you normally do not need to create/check filesystem in a chroot). The rest is more or less needed for package installation via dpkg or apt-get. – jofel Sep 29 '15 at 16:24
  • 1
    Busybox could replace coreutils, bash, and maybe a couple others, but not easily in Debian: unix.stackexchange.com/questions/35165/… – drewbenn Sep 29 '15 at 16:45
  • "gnupg" is not essential, it's "important". Why is "openssh-client" still installed? Methinks you could remove more packages without touching the "essential" ones. – wurtel Sep 30 '15 at 8:57
  • @wurtel apt depends on gnupg, and apt is essential :( – P.Péter Sep 30 '15 at 12:31
2

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.

  • I am not sure I won't need any debian utilities, I installed debian because that provides flexibility if I need any package. Meanwhile, I also found out that /var/lib/apt/ takes up a lot of space (55M), so 30M can be gained if I gzip the files there. I could even delete them and then do an apt-get update if I need to install something. – P.Péter Sep 30 '15 at 6:52
1

You might try rebuilding the coreutils package with ./configure --enable-single-binary so it shares a binary between all utilities like busybox does

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.