This repository has been archived on 2025-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
Files
home-assistant-yellow/overlay/usr/libexec/init-storage
Dustin C. Hatch 9d507c74ae Create /var/log with systemd-tmpfiles
*systemd-tmpfiles* can create btrfs subvolumes with the `v` entry type.
Using this mechanism instead of the `init-storage` script will allow for
greater flexibility when adding other subvolumes later.

Unfortunately, the default configuration for *systemd-tmpfiles* already
includes an entry for `/var/log` with the `d` (directory) type.  Since
individual entries cannot be overridden, we need to modify this entry.
2023-03-12 12:53:16 -05:00

56 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
cleanup() {
if [ -n "${tmpdir}" ] && [ "${tmpdir}" != / ]; then
if mountpoint -q "${tmpdir}"; then
umount "${tmpdir}"
fi
rm -rf "${tmpdir}"
unset tmpdir
fi
}
copy_var() {
dev="$1"
echo 'Copying /var contents to data volume'
mount -o subvol=var "${dev}" "${tmpdir}" || exit
cp -auv /var/. "${tmpdir}" || exit
umount "${tmpdir}"
}
format_dev() {
dev="$1"
printf 'Creating BTRFS filesystem on %s\n' "${dev}"
mkfs.btrfs "${dev}" || exit
mount "${dev}" "${tmpdir}" || exit
btrfs subvolume create "${tmpdir}"/var || exit
umount "${dev}" || exit
}
has_fs() {
dev="$1"
fstype=$(blkid -o value -s TYPE "${dev}")
[ -n "${fstype}" ]
}
datapart=$(findfs PARTLABEL=dch-data)
if [ -b "${datapart}" ]; then
printf 'Found data partition: %s\n' "${datapart}"
else
echo 'Could not identify data partition' >&2
exit 1
fi
trap cleanup INT TERM QUIT EXIT
tmpdir=/run/storinit
mkdir -p "${tmpdir}"
if ! has_fs "${datapart}"; then
format_dev "${datapart}"
fi
copy_var "${datapart}"