Rm /etc/services /etc/protocols

I have an old router and I would like to keep few kibibytes and I need to know which auxiliary files can I delete from image. I already removed /etc/banner and now I want to remove /etc/services and
/etc/protocols. They both have 5.6 kb and even after lzma compression still have quite a lot.

Is it safe to remove the /etc/protocols and the /etc/services?
What can be affected?

programs can do a getportbyname() sockets call in their code in order to understand what port they should use. For example, a POP3 email daemon would do a getportbyname (POP3) in order to retrieve the number 110 that POP3 runs on.

the uhttpd and dropbear uses port from config and they don't use the protocols mapping file but what about others?

As far I see the only program that uses them is iptables where I can use these alisases

nfs-server uses /etc/services via rpcbind or portmap.

1 Like

Current compression is xz on images, so the space occupied in the squashfs image is quite small.

  • package/base-files/files/etc/services -- 3073 bytes uncompressed ~ 1140 compressed
  • package/base-files/files/etc/protocols -- 2541 bytes uncompressed ~ 1420 compressed

If you're fighting for 5 kB, I think you've got bigger problems.

For a system to be functional, you really need ~200 kB or more free in the overlay file system.

Have you already built from source (build system) or assembled from packages (image builder) your own image?

(Removing files/packages from pre-built ROMs doesn't recover any space, and actually uses a few bytes to "delete" them.)

2 Likes

thank you,
yes I know that this is only about two kibibytes but even them will may be useful for me. I'll store a lot of data in /tmp folder and the more RAM will be available then better to me.
Anyway I even more interested why do we need this files at all.
BTW, squashfs uses lzma compression but is any chance to have the lzma compressor and decompressor as a regular command line tool? Or at least some liblzma so I can use it in my programm?
Also I wondered that OpenWrt contains bz2 decompressor but doesn't have bz2 compressor.
For me it's not clear who needs bz2 and why wasn't added bz2 compressor because I guess it will share almost the same code as decompressor and not a big overhead for space

https://openwrt.org/docs/guide-user/additional-software/saving_space may be valuable for you. I think there are some similar pages, but couldn't immediately find the links.

You can't really modify the ROM squashfs image on the running device in any sane manner that I know of. It really has to be built on a build machine.

The compression and decompression command-line utilities are available as packages, which can be build into your ROM.

Either gzip or lzma compression here is basically the same; 1104 and 1356 bytes (gzip), 1094 and 1376 bytes (lzma)

xz compression is available, from include/image.mk

SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
SQUASHFSCOMP := gzip
LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
ifeq ($(CONFIG_SQUASHFS_XZ),y)
  ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
    BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
  endif
  SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
endif
1 Like

This page should cover all space saving measures. Other pages might exists, but don't contain more than this page.

1 Like

The folder /tmp uses RAM; and is not persistent after reboot and power cycles.

1 Like

Answering myself: the /etc/services file isn't really needed and can be (almost safely) removed.
It's used by getservbyname() but in fact the function is called only by inetd, nc, tcpudp, and telnet client when they using protocol names instead of ports.

Changing the file is also useless idea. For example in Termux which is a Linux emulator/wrapping layer for Android they do really need to change telnet port to 8023 for telnetd because 23 needs for a root permissions.
But they have to patch all software instead of changing the /etc/services. Why?
Because telnet client also reads it and if you change telnet port to 8023 then it won't be able to connect to others servers.

So you can add new entries into the /etc/services but you must not change any existing lines.

But the /etc/protocols may be not so safe to remove because it may be used by firewall

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.