You are not logged in.

#1 2022-06-01 03:23:58

dawnofman
Member
Registered: 2019-07-26
Posts: 140

best way to place default content on a RAM drive upon startup ?

I have the following on my /etc/fstab:

tmpfs /tmp-workspace tmpfs defaults,size=8G,nodev,nosuid,uid=root,gid=root,mode=1777,rw 0 0

I would like to place some default content immediately upon startup (including /home/*/.cache directories, browser's cache directories, and the like). I can think of at least two possible ways of automating what I am manually doing right now:

- properly coding a stand-alone systemd service unit that triggers on /tmp-workspace successful mount
- add systemd extensions to the mount line in fstab with ExecStart and the like (leaving the magic to the systemd generator)

Either way, I suppose if [Install] WantedBy=multi-user.target is present will guarantee that mounting /home will grant me everything on my RAM drive will be right in place (multi-user.target) ... am I right ?

Pros/Cons/Advice please ?

Offline

#2 2022-06-01 07:31:14

dogknowsnx
Guest

Re: best way to place default content on a RAM drive upon startup ?

Care to share what you're "manually doing right now"?

#3 2022-06-01 11:34:35

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: best way to place default content on a RAM drive upon startup ?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#4 2022-06-01 19:43:08

dawnofman
Member
Registered: 2019-07-26
Posts: 140

Re: best way to place default content on a RAM drive upon startup ?

dogknowsnx wrote:

Care to share what you're "manually doing right now"?

Sure. But I think it is totally irrelevant: I am manually executing the following BASH script under root upon startup before login-in with any other user:

typeset strUserName='root';

if /usr/bin/test "${USER}" = "${strUserName}"; then ### a self-imposed restriction

   readonly strPATHROOT='/';
   readonly strPATHNAME='tmp-workspace';

   if /usr/bin/test '['$(/usr/bin/findmnt --noheadings --output='TARGET' --mountpoint="${strPATHROOT}${strPATHNAME}")']' = "[${strPATHROOT}${strPATHNAME}]"; then

      readonly strPATH="${strPATHROOT}${strPATHNAME}/";

      readonly -a strFSOdirectories=( \
         "root   root 755 ${strPATH}cache" \
         "root   root 700 ${strPATH}cache/users" \
         "root   root 700 ${strPATH}cache/users/root" \
         "user1 stuff 700 ${strPATH}cache/users/user1" \
         "user2 stuff 700 ${strPATH}cache/users/user2" \
         "user3 stuff 700 ${strPATH}cache/users/user3" \
         "user4 stuff 700 ${strPATH}cache/users/user4" \
         "user1 stuff 750 ${strPATH}setup" \
         "user1 stuff 750 ${strPATH}setup/build" \
         "user1 stuff 750 ${strPATH}setup/build-logs" \
         "user1 stuff 750 ${strPATH}setup/build-packages" \
         ); ### space delimited: owner group mode path

      typeset strFSO='';

      for strFSO in "${strFSOdirectories[@]}"; do

         typeset strFSOUID=$(echo "${strFSO}" | /usr/bin/awk -F ' ' '{ print $1 }');
         typeset strFSOGID=$(echo "${strFSO}" | /usr/bin/awk -F ' ' '{ print $2 }');
         typeset strFSOMOD=$(echo "${strFSO}" | /usr/bin/awk -F ' ' '{ print $3 }');
         typeset strFSODIR=$(echo "${strFSO}" | /usr/bin/awk -F ' ' '{ print $4 }');

         if /usr/bin/test ! -d "${strFSODIR}"; then

            /usr/bin/printf "creating directory [${strFSODIR}]\n";

            /usr/bin/mkdir --mode="${strFSOMOD}" "${strFSODIR}";

         fi;

         if /usr/bin/test -d "${strFSODIR}"; then

            /usr/bin/chown "${strFSOUID}:${strFSOGID}" "${strFSODIR}";

         fi;

         unset -v strFSODIR;
         unset -v strFSOMOD;
         unset -v strFSOGID;
         unset -v strFSOUID;

      done;

      unset -v strFSO;

   else

      /usr/bin/printf "ooops … ${colorOOOPS}missing mount${colorDEFAULT}: [${colorVALUE}${strPATH}${colorDEFAULT}]\n";

   fi;

else

   /usr/bin/printf "ooops … ${colorOOOPS}executing with wrong user${colorDEFAULT}: [${colorVALUE}${USER}${colorDEFAULT}]≠[${colorVALUE}${strUserName}${colorDEFAULT}] … a self-imposed restriction\n";

fi;

unset -v strUserName;

Offline

#5 2022-06-13 03:37:06

dawnofman
Member
Registered: 2019-07-26
Posts: 140

Re: best way to place default content on a RAM drive upon startup ?

Will check it, thanks for the link, I have it in mind but got unexpectedly busy the past week.

Offline

Board footer

Powered by FluxBB