Os ramdisks iniciais usam o Busybox para economizar espaço. Essencialmente, utilitários como mv
e cp
compartilham muita lógica comum - abra um descritor de arquivo, leia buffers na memória, etc. O Busybox basicamente coloca toda a lógica comum em um binário que muda a maneira como ele se comporta, dependendo do nome com o qual foi chamado. Vamos dar uma olhada nesse disco.
alex@alexs-arch-imac:/tmp/initramfs/bin$ ls -l
total 1308
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 [ -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 [[ -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ash -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 awk -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 basename -> busybox
-rwxr-xr-x 1 alex alex 68840 Mar 24 17:06 blkid
-rwxr-xr-x 1 alex alex 287096 Mar 24 17:06 busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 cat -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 chgrp -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 chmod -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 chown -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 chroot -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 clear -> busybox
-rwxr-xr-x 1 alex alex 130272 Mar 24 17:06 cp
-rwxr-xr-x 1 alex alex 59264 Mar 24 17:06 cryptsetup
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 cttyhack -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 cut -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 dd -> busybox
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 depmod -> kmod
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 df -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 dirname -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 dmesg -> busybox
-r-xr-xr-x 1 alex alex 92227 Mar 24 17:06 dmsetup
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 du -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 echo -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 egrep -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 env -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 expr -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 false -> busybox
-rwxr-xr-x 1 alex alex 53696 Mar 24 17:06 findmnt
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 free -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 getopt -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 grep -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 halt -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 head -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 hexdump -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ifconfig -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 init -> busybox
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 insmod -> kmod
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 install -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ip -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ipaddr -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 iplink -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 iproute -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 iprule -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 iptunnel -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 kbd_mode -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 kill -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 killall -> busybox
-rwxr-xr-x 1 alex alex 142424 Mar 24 17:06 kmod
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 less -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ln -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 loadfont -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 loadkmap -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 losetup -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ls -> busybox
-rwxr-xr-x 1 alex alex 70192 Mar 24 17:06 lsblk
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 lsmod -> kmod
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 md5sum -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 mkdir -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 mkfifo -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 mknod -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 mktemp -> busybox
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 modinfo -> kmod
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 modprobe -> kmod
-rwsr-xr-x 1 alex alex 40168 Mar 24 17:06 mount
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 mountpoint -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 mv -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 nc -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 netstat -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 nslookup -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 openvt -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 pgrep -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 pidof -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ping -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ping6 -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 poweroff -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 printf -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 ps -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 pwd -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 readlink -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 reboot -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 rm -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 rmdir -> busybox
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 rmmod -> kmod
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 route -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 sed -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 seq -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 setfont -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 sh -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 sha1sum -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 sha256sum -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 sha512sum -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 sleep -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 sort -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 stat -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 strings -> busybox
-rwxr-xr-x 1 alex alex 14816 Mar 24 17:06 switch_root
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 sync -> busybox
-rwxr-xr-x 1 alex alex 63992 Mar 24 17:06 systemd-tmpfiles
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 tac -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 tail -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 telnet -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 test -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 tftp -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 touch -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 true -> busybox
-rwxr-xr-x 1 alex alex 264696 Mar 24 17:06 udevadm
-rwsr-xr-x 1 alex alex 27616 Mar 24 17:06 umount
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 uname -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 uniq -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 uptime -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 vi -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 wc -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 wget -> busybox
lrwxrwxrwx 1 alex alex 7 Mar 24 17:06 yes -> busybox
alex@alexs-arch-imac:/tmp/initramfs/bin$
Como você pode ver, quase todos os binários dessa imagem estão vinculados ao Busybox.
alex@alexs-arch-imac:/tmp/initramfs/bin$ ls -l | grep --invert-match busybox -
total 1308
-rwxr-xr-x 1 alex alex 68840 Mar 24 17:06 blkid
-rwxr-xr-x 1 alex alex 130272 Mar 24 17:06 cp
-rwxr-xr-x 1 alex alex 59264 Mar 24 17:06 cryptsetup
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 depmod -> kmod
-r-xr-xr-x 1 alex alex 92227 Mar 24 17:06 dmsetup
-rwxr-xr-x 1 alex alex 53696 Mar 24 17:06 findmnt
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 insmod -> kmod
-rwxr-xr-x 1 alex alex 142424 Mar 24 17:06 kmod
-rwxr-xr-x 1 alex alex 70192 Mar 24 17:06 lsblk
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 lsmod -> kmod
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 modinfo -> kmod
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 modprobe -> kmod
-rwsr-xr-x 1 alex alex 40168 Mar 24 17:06 mount
lrwxrwxrwx 1 alex alex 4 Mar 24 17:06 rmmod -> kmod
-rwxr-xr-x 1 alex alex 14816 Mar 24 17:06 switch_root
-rwxr-xr-x 1 alex alex 63992 Mar 24 17:06 systemd-tmpfiles
-rwxr-xr-x 1 alex alex 264696 Mar 24 17:06 udevadm
-rwsr-xr-x 1 alex alex 27616 Mar 24 17:06 umount
alex@alexs-arch-imac:/tmp/initramfs/bin$ ls | wc -l # total number of files
116
alex@alexs-arch-imac:/tmp/initramfs/bin$ ls -l | grep --invert-match busybox - | grep --invert-match kmod | wc -l # number of real binaries minus two (busybox and kmod)
12
Existem 116 arquivos na imagem, mas apenas 14 deles são realmente binários. O resto são links simbólicos para kmod
ou busybox
.
Então: a razão pela qual existem tantos utilitários aleatórios é porque você também pode colocá-los lá. Os links simbólicos não ocupam espaço, e mesmo se você os removesse, a funcionalidade permaneceria no binário do Busybox, ocupando espaço. Como não há nenhum motivo real para remover todos os links, os empacotadores não o fazem.
Aqui está outra questão a considerar: por que não simplesmente remover a funcionalidade de rede do binário do Busybox? Como o @Gilles menciona, são casos legítimos (se não comuns) onde você precisaria de rede em um initcpio. Portanto, os empacotadores têm duas opções: uma, fazer o que eles fazem agora e incluir tudo isso, por padrão, ou duas funcionalidades de rede divididas em seu próprio mkinitcpio
hook. O primeiro é fácil (basicamente você não faz nada) e custa uma quantia muito pequena, enquanto o segundo é muito complexo (mais uma vez, graças ao @Gilles por apontar isso) e os ganhos realmente não são significativos o suficiente para serem importantes. Portanto, os empacotadores saem de maneira inteligente e não fazem nada com a rede.