Hello everyone!
This is my first post after registering, so please be gentle with a noob who's willing to learn.
I have a Raspberry Pi 2 which I intend to put on a friend's network with dnsmasq and pihole running.
Its kind of a fire-and-forget mission, so I need to make sure it works for a long time without maintenance.
My concern is the SD card. I want to reduce wear on it as much as possible.
My idea was to have systemd mount a tmpfs to a temporary directory at boot, copy the contents of /var to this mount, move the mountpoint to /var and on shutdown do the opposite, that is, moving the mountpoint back to the temporary directory, copying its contents to /var and unmounting it.
I created four files for that purpose:
/etc/systemd/system/sdguard-start.service
$this->bbcode_second_pass_code('', '[Unit]
Description=SD Card Guard start
[Service]
Type=oneshot
ExecStart=/usr/bin/tmpfs-var-start.sh
[Install]
WantedBy=multi-user.target')
/etc/systemd/system/sdguard-stop.service
$this->bbcode_second_pass_code('', '[Unit]
Description=SD Card Guard stop
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/usr/bin/tmpfs-var-stop.sh
[Install]
WantedBy=multi-user.target')
/usr/bin/tmpfs-var-start.sh
$this->bbcode_second_pass_code('', '#!/bin/bash
mkdir /var-tmpfs
mount -t tmpfs -o size=256m none /var-tmpfs
cp -r /var/* /var-tmpfs/.
mount --move /var-tmpfs /var
rmdir /var-tmpfs')
/usr/bin/tmpfs-var-stop.sh
$this->bbcode_second_pass_code('', '#!/bin/bash
mkdir /var-tmpfs
mount --move /var /var-tmpfs
cp -r /var-tmpfs/* /var/.
umount /var-tmpfs
rmdir /var-tmpfs')
I committed a daemon-reload, the two services are enabled and the scripts are executable.
After booting this setup, df -h shows that my tmpfs is mounted on /var-tmpfs instead of /var .
My first check was trying to manually move the mountpoint which revealed that this is the step that isn't working.
I get the message $this->bbcode_second_pass_code('', 'mount: /var: bad option; moving a mount residing under a shared mount is unsupported.')
The manual of mount states that this is normal.
How can I mount the tmpfs as non-shared or not residing under a shared mount ?