From cb17a9f370cac17d5c604e3fa852224a512fae93 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 31 Oct 2023 15:04:15 +0100 Subject: [PATCH] Changing snippets/tpl.075.tmp-tmpfs.sh to a systemd mount unit file --- snippets/tpl.075.tmp-tmpfs.sh | 38 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/snippets/tpl.075.tmp-tmpfs.sh b/snippets/tpl.075.tmp-tmpfs.sh index f0d54e2..ba39704 100644 --- a/snippets/tpl.075.tmp-tmpfs.sh +++ b/snippets/tpl.075.tmp-tmpfs.sh @@ -4,19 +4,37 @@ #----------------------------------------------------------- setup_tmp_tmpfs() { - local fstab="/etc/fstab" - if [[ -f "${fstab}" ]] ; then + echo -e "\e[0Ksection_start:$( date +%s ):ks_setup_tmp_tmpfs[collapsed=true]\r\e[0KSetting up /tmp as a tmpfs ..." - echo -e "\e[0Ksection_start:$( date +%s ):ks_setup_tmp_tmpfs[collapsed=true]\r\e[0KSetting up /tmp as a tmpfs ..." - echo - echo "${HASH_LINE}" - echo - log "Setting up /tmp as a tmpfs in '${fstab}' ..." + local unit_file="/etc/systemd/system/tmp.mount" + echo + echo "Creating a systemd unit file '${unit_file}' providing a temp filesystem below /tmp" - echo 'tmpfs /tmp tmpfs nosuid,size=10% 0 0' >>"${fstab}" + cat > "${unit_file}" <<-EOF + # Unit file for creating a temp filesystem below /tmp - echo -e "\e[0Ksection_end:$( date +%s ):ks_setup_tmp_tmpfs\r\e[0K" - fi + [Unit] + Description=Creating a temporary filesystem below /tmp + Before=local-fs.target + + [Install] + WantedBy=local-fs.target + + [Mount] + What=tmpfs + Where=/tmp + Type=tmpfs + Options=nosuid,size=10%% + + EOF + + echo + echo "Content of '${unit_file}':" + echo "---------- snip ----------" + cat "${unit_file}" + echo "---------- snip ----------" + + echo -e "\e[0Ksection_end:$( date +%s ):ks_setup_tmp_tmpfs\r\e[0K" } setup_tmp_tmpfs -- 2.39.5