Score:0

Running cachefilesd cache on ramdisk (tmpfs) for PXE NFS boot

mx flag

I am running ubuntu 20.04 LTS (kernel 5.4.0-81-generic) from PXE and I wish to add a local cache. Because I don't want to have a partition on all my devices for caching, I wish to use a ramdisk for that purpose.

I have managed to enable the fsc option during boot with the help of this answer.

However when I run the cachefilesd service, it failes with -95: Operation not supported. This is probably because tmpfs doesn't support user_xattr, which is required.

I have read here that you can compile/patch the kernel to enable user_xattr, though this is a security risk. Besides being a maintenance nightmare, I do not wish to go that far and fiddle around with automating that with every kernel update.

I have read here (german) and this and it's response.

It indicates that you can make a tmpfs, then make a loopback device, format that to ext4 and then run your fs-cache on there.

However, since I'm using PXE and the NFS mount point is /, how do I do that during boot, preferably before cachedfilesd.service is started?

My bootloader (vesamenu.c32)

# [...]
label                   ubuntunfs
        menu label      ^Ubuntu NFS
        text help
Run ubuntu from Network File System.
        endtext
        kernel          ubuntu/boot/vmlinuz
        initrd          ubuntu/boot/initrd.img
        append          root=/dev/nfs nfsroot=192.168.1.5:/srv/tftp/ubuntu,rw,fsc,relatime ip=dhcp rw
# [...]

My fstab

/proc    /proc    proc    defaults   0 0
/sys     /sys     sysfs   defaults   0 0
/dev/nfs /        nfs     defaults,relatime,fsc   1 1

# ramdisk for fs-cache for nfs
tmpfs    /media/ramdisk    tmpfs    defaults,size=5%      0       0

none            /tmp            tmpfs   defaults        0       0
none            /var/run        tmpfs   defaults        0       0
none            /var/lock       tmpfs   defaults        0       0
none            /var/tmp        tmpfs   defaults        0       0

my /etc/cachefilesd.conf

dir /media/ramdisk
tag mycache
brun 90%
bcull 70%
bstop 30%
frun 90%
fcull 70%
fstop 30%

culltable 14
guiverc avatar
cn flag
Please provide product & release details.
FalcoGer avatar
mx flag
@guiverc I hope you mean the ubuntu and kernel version. I have added those.
guiverc avatar
cn flag
by product, ubuntu server, ubuntu desktop, ubuntu core etc. & release details such as 20.04, 20.04.3, 20, etc (if full product & release details are provided we know the kernel, eg. ubuntu 20.04 server uses GA or 5.4 kernel, 20.ubuntu 20.04 desktop kernel is HWE so varies on upgrade level, 20.04 is 5.4, 20.04.2 is 5.8, 20.04.3 is 5.11 etc, Ubuntu Core 20 is....) -- your 5.4 implies it's a 20.04 server to me thus the GA kernel
FalcoGer avatar
mx flag
@guiverc I installed with debootstrap. I assume it's server or minimal.
Score:0
mx flag

I did it with a systemd service.

[Unit]
Description=Cache creator
Before=cachefilesd.service

[Service]
ExecStart=/bin/bash -c "dd if=/dev/zero of=/media/ramdisk/cache.ext4 bs=1k count=`df /media/ramdisk | tail -n 1 | sed -e 's/ \+/ /g' | cut -d ' ' -f 2` && mke2fs /media/ramdisk/cache.ext4 && mount -o rw,noatime,nodiratime,user_xattr /media/ramdisk/cache.ext4 /media/cache/"
Restart=no
Type=oneshot

[Install]
WantedBy=multi-user.target

The script is taking the 1k block count (from df) of the ramdisk as the input for dd's input file (if=) argument, otherwise dd will return an error code because the disk is full and && will not work in that situation. Obviously this only works if ramdisk is empty.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.