You are not logged in.

#1 2013-02-26 10:45:07

DaveCode
Member
Registered: 2008-08-15
Posts: 103

systemd kiosk volatile $HOME

How may systemd populate a volatile user $HOME from persistent storage, before users can login, or before Arch logs in automatically?

The needed rsync call is trivial. I've attempted several unit/service files. I must not know something basic. The Arch OS is a charm and pure systemd. It just needs an automated rsync.

The kiosk must avoid periodic sync (a la various AUR daemons). Users can bork it. $HOME in tmpfs leaves us in control of what lands on SSD. We can tell people to reboot a borked system. We also want to minimize slow writes and maximize SSD life.

All we need is for systemd to rsync at the right stage in the boot sequence.

Thanks Arch

fstab,

tmpfs /kioskuserhome tmpfs auto,uid=4000,gid=users,rw,nosuid,exec,noatime,size=300M,nr_inodes=30K  0  0

boot setup,

rsync  --archive     /home/kioskuserhome/     /

Offline

#2 2013-02-28 11:10:09

DaveCode
Member
Registered: 2008-08-15
Posts: 103

Re: systemd kiosk volatile $HOME

Subject to correction, here's a solution. I hope it doesn't depend on timings. It works on our kiosk. Rsync is touchy about trailing slashes but works fine. We renamed kioskuserhome to ramhome. Another annoying fact is that systemd requires absolute pathnames in execution lines.

So this rigging boots a kiosk with $HOME in tmpfs and automatically logs into tty1. From there, auto-starting X is trivia.

$HOME in tmpfs is a nice speedup since apps are always reading and writing dotfiles.

# /etc/fstab
tmpfs /ramhome     tmpfs  auto,uid=2000,gid=users,rw,nosuid,exec,noatime,size=300M,nr_inodes=30k  0  0
# /etc/systemd/system/ramhome-setup.service (UPDATE: see corrected unit below)

[Unit]
Description=Populate RAM user files from persistent store
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/usr/bin/rsync --archive /home/ramhome/ /ramhome 
RemainAfterExit=no

[Install]
RequiredBy=getty.target

And following automatic login advice but tweaking After and Install, we have

# /etc/systemd/system/autologin@.service

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Autologin Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=https://wiki.archlinux.org/index.php/Automatic_login_to_virtual_console
After=systemd-user-sessions.service plymouth-quit-wait.service ramhome-setup.service

# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes

# On systems without virtual consoles, don't start any getty. (Note
# that serial gettys are covered by serial-getty@.service, not this
# unit
ConditionPathExists=/dev/tty0

[Service]
# the VT is cleared by TTYVTDisallocate
ExecStart=-/sbin/agetty --noclear -a anyone %I 38400 linux
Type=idle
Restart=always
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no

# Unset locale for the console getty since the console has problems
# displaying some internationalized messages.
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=

# Some login implementations ignore SIGTERM, so we send SIGHUP
# instead, to ensure that login terminates cleanly.
KillSignal=SIGHUP

[Install]
WantedBy=getty.target

Then of course the obligatory commands

# systemctl daemon-reload
# systemctl enable ramhome-setup.service
# systemctl disable getty@tty1
# systemctl enable autologin@tty1

and reboot.

UPDATE. And we have been duly corrected. The revised service per systemd creator Lennart Poettering (1,2,3) follows.

# /etc/systemd/system/ramhome-setup.service

[Unit]
Description=Populate RAM user files from persistent store
Before=systemd-user-sessions.service

[Service]
Type=oneshot
ExecStart=/usr/bin/rsync --archive /home/ramhome/ /ramhome 

[Install]
WantedBy=multi-user.target

Last edited by DaveCode (2013-03-05 18:11:17)

Offline

#3 2013-03-02 22:17:43

dgbaley27
Member
Registered: 2011-07-22
Posts: 47

Re: systemd kiosk volatile $HOME

Instead of rsyncing the home directory template into ram, why don't you use aufs to union a writeable tmpfs over a read-only filesystem.

Offline

#4 2013-03-02 23:22:00

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: systemd kiosk volatile $HOME

^^^This is a good idea. There is unionfs in the repository, but if you want good performance, you would probably have to use a patched kernel with aufs3 (available in that aur) .


Edit: BTW, the reason why unionfs lacks a bit in performance is because it is a FUSE implementation. So it works well, but is not super optimal.

Last edited by WonderWoofy (2013-03-02 23:23:35)

Offline

#5 2013-03-03 11:30:20

DaveCode
Member
Registered: 2008-08-15
Posts: 103

Re: systemd kiosk volatile $HOME

Thank you dgbaley27! That's an excellent idea. I'd love to see fstab and/or systemd mount units.

The answer to your question why is that I don't know aufs. An AUR bolt-on and patched kernel pushes me back to keep-it-simple-stupid. Still it is an excellent idea. I wish Arch repos would supply more kernel flavors and more of these nice AUR packages - via compile farm maybe? I was just looking for a fallback kernel (earlier version of mainline) to help with some USB bug that cropped up in the last one.

I suppose I should give code for saving to permanent store.

#!/usr/bin/env zsh
set -e
# invoke a trimmer script for Firefox profile and other app $HOME bloat first if desired, then
rsync --links --delete -tgovrW   /ramhome/    /home/ramhome

Last edited by DaveCode (2013-03-03 11:31:21)

Offline

Board footer

Powered by FluxBB