How to mount /tmp as tmpfs in Alpine Linux?

Here’s what’s happening:

/etc/fstab:
tmpfs /tmp tmpfs defaults,size=8G 0 0

Alpine uses OpenRC init system. The default startup services are:

$ rc-update
             bootmisc | boot                                   
                crond |      default                           
           networking |      default                           
               syslog | boot

The bootmisc service depends on localmount. The localmount service manages /etc/fstab but obviously doesn’t get invoked. Starting it manually does work though (fstab fires up properly and with it the /tmp mount).

Looking into /etc/init.d/localmount:

depend()
{
	need fsck root
	use lvm modules
	after clock lvm modules
	keyword -docker -jail -lxc -prefix -systemd-nspawn -vserver
}

keyword allows platform-specific overrides, e.g. keyword -lxc makes this service script a noop in lxc containers. The keywords get compared against rc_sys defined in /etc/rc.conf.

/etc/rc.conf:
rc_sys="lxc"

So, the solution is to remove “-lxc” in /etc/init.d/localmount and fstab gets honored in LXC/LXD containers as well.

1 Like