How to mount /tmp as tmpfs in Alpine Linux?

In AlpineLinux/edge/amd64 (unpriv) from images.linuxcontainers.org the /tmp folder is a regular folder (not tmpfs). It probably is a bug.

In LXC i can handle it by overmounting it with a host mount (lxc.mount.entry = tmpfs tmp tmpfs defaults,create=dir 0 0) but i have no clue how to do it with LXD. I’ve noted down a command some time time ago but it doesn’t work (anymore?):
lxc config device add alpine tmpfs disk source=tmpfs path=/tmp
On lxc start alpine it throws this error:
Error: Common start logic: Missing source 'tmpfs' for disk 'tmpfs'

/etc/fstab entries are not accepted either even though a manual mount does work:
tmpfs /tmp tmpfs nodev,nosuid,size=8G 0 0

(1) How can i mount a tmpfs folder with LXD from host side?

(2) How can i show/edit all the other host mounts (configs) done by the image/template? On LXC there are several templates/configs that show /run mounts, cap drops and alike done from host side, On LXD lxc config show alpine just gives me the user config. All the template stuff is missing. How can i show/edit it?

Archlinux 5.1.11
LXD 3.13

/tmp doesn’t have to be and often isn’t a tmpfs on most distros.
If you want it to be one, you should be able to just put a line in /etc/fstab inside the container to have it mounted as a tmpfs on boot.

Try this in /etc/fstab:

/tmp /tmp tmpfs defaults,size=8G 0 0

Doesn’t work either…

$ mount |grep tmp
none on /dev type tmpfs (rw,relatime,size=492k,mode=755,uid=200000,gid=200000)
dev on /dev/full type devtmpfs (rw,nosuid,relatime,size=8184520k,nr_inodes=2046130,mode=755)
dev on /dev/null type devtmpfs (rw,nosuid,relatime,size=8184520k,nr_inodes=2046130,mode=755)
dev on /dev/random type devtmpfs (rw,nosuid,relatime,size=8184520k,nr_inodes=2046130,mode=755)
dev on /dev/tty type devtmpfs (rw,nosuid,relatime,size=8184520k,nr_inodes=2046130,mode=755)
dev on /dev/urandom type devtmpfs (rw,nosuid,relatime,size=8184520k,nr_inodes=2046130,mode=755)
dev on /dev/zero type devtmpfs (rw,nosuid,relatime,size=8184520k,nr_inodes=2046130,mode=755)
dev on /dev/fuse type devtmpfs (rw,nosuid,relatime,size=8184520k,nr_inodes=2046130,mode=755)
dev on /dev/net/tun type devtmpfs (rw,nosuid,relatime,size=8184520k,nr_inodes=2046130,mode=755)
tmpfs on /dev/lxd type tmpfs (rw,relatime,size=100k,mode=755)
tmpfs on /dev/.lxd-mounts type tmpfs (rw,relatime,size=100k,mode=711)
tmpfs on /run type tmpfs (rw,nodev,relatime,size=1638828k,mode=755,uid=200000,gid=200000)

I’ve also disabled all ‘boot’ entries in openrc. Doesn’t change anything. It probably does weird stuff in initrd (maybe ignoring fstab completely or is buggy). The /run mount above shows uid=200000,gid=200000 that obviously is a host mount (its in alpine.common.conf on LXC). It might be intended to be done this way.

Is there nothing like ‘alpine.common.conf’ in LXD? On LXC i just copied the line for /tmp and i was set.

You can use a raw.lxc entry but for things like this, having the container handle it like a normal Linux system is certainly preferred.

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

It is already 3 years and this bug still persists. How one should fix it to avoid editing that file?

Is there a bug upstream for this at Alpine?

If not could you open an issue here Issues · lxc/distrobuilder · GitHub please.

This has been fixed.

1 Like