]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Changing snippets/tpl.075.tmp-tmpfs.sh to a systemd mount unit file
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 31 Oct 2023 14:04:15 +0000 (15:04 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 31 Oct 2023 14:04:15 +0000 (15:04 +0100)
snippets/tpl.075.tmp-tmpfs.sh

index f0d54e20a4c40133acfce1a8a16a90d77fe946c6..ba397041c051ac488d87c256bf5d1500c5dbfa1d 100644 (file)
@@ -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