HOWTO Freeze Linux

  • home directory is on a btrfs partition (/dev/sda6 in this example)
  • /mnt is available on boot for temporaryly mounting a fs
  • read-only version of home is a read-only snapshot named home-ro in btrfs root
  • the name home-rw is not used on the btrfs fs
  • wipe is installed in /usr/local/bin
  • systemd is used and wipe.service is installed in etc/systemd/system
  • run systemd enable wipe.service to enable wiping
  • if anything fails on boot, home is mounted from fstab (99% of cases; except when exit code is 4)
  • user login is delayed until wiping is done
wipe
#!/bin/bash
if mount /dev/sda6 /mnt; then
	btrfs subvolume delete /mnt/home-rw
	if btrfs subvolume snapshot /mnt/home-ro /mnt/home-rw; then
		if umount /home; then
			if mount -o subvol=home-rw /dev/sda6 /home; then
				ret=0
			else
				ret=4
			fi
		else
			ret=3
		fi
	else
		ret=2
	fi
else
	ret=1
fi
umount /mnt
if [ $? -ne 0 ]; then
	ret=1"$ret"
fi
 
exit $ret
wipe.service
[Unit]
Description=Wipe home directory modifications
Requires=local-fs.target
After=local-fs.target
Before=systemd-user-sessions.service
 
[Install]
WantedBy=systemd-user-sessions.service
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/wipe
si/lab/2020/hidden/freeze.txt ยท Last modified: 2021/08/10 18:32 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0