Quantcast
Channel: Squeezebox : Community : Forums - Logitech Media Server
Viewing all articles
Browse latest Browse all 5300

Snippet: Swapfile + ZFS + Overlayroot

$
0
0
Hi

Thought I'd share this.

I run LMS on a Pcengines APU with 4G RAM.
OverlayRoot is active.
OS is on a standard SSD,
Music is on a separate (writeable) ZFS volume.

Problem
I constantly run out of memory since the newer releases.
So I had to add SWAP. And I wanted it on the ZFS storage, but keep the overlayroot.

This is how I did.
This is Ubuntu 18 LTS.

Feel free to improve.

Regards
M

Code:

# SWAP ON ZFS, but INSIDE OVERLAYROOT
# Do this with overlayroot off, because easier:
# ZFS no worky in overlayroot-chroot, and
# Ersatz-rc-local.service needs to be saved permanently

# or just patch yourself through... half/half

# Reason for this mess
# - ZFS needs a special swapfile treatment
# - fstab entry wont work (in my case), we daisychain a /sbin/swapon via systemd from inside the overlay.


# zfs tank variable
TANK=bulker

# creating a non-COW dataset for swap
# https://askubuntu.com/questions/1198903/can-not-use-swap-file-on-zfs-files-with-holes
zfs create -V 8G -b $(getconf PAGESIZE) -o logbias=throughput -o sync=always -o primarycache=metadata -o com.sun:auto-snapshot=false $TANK/swap

mkswap -f /dev/zvol/$TANK/swap

# just for test, should reveal SWAP in 'free -m'
/sbin/swapon /dev/zvol/$TANK/swap

# Dont begin with fstab
# instead we do rc.local necromancy
# https://wiki.ubuntuusers.de/rc.local/

cat > /etc/systemd/system/Ersatz-rc-local.service<<GUSTAF
[Unit]
After = network-online.target
Wants = network-online.target

[Service]
Type = oneshot
RemainAfterExit = yes
ExecStart = /sbin/swapon /dev/zvol/$TANK/swap

[Install]
WantedBy = multi-user.target
GUSTAF


systemctl enable Ersatz-rc-local.service

exit
# and enable your overlayroot again
# my /etc/overlayroot.conf says:
overlayroot_cfgdisk="disabled"
overlayroot=""
overlayroot="tmpfs:swap=0,recurse=0"


Viewing all articles
Browse latest Browse all 5300

Trending Articles