You are not logged in.

#1 2012-08-12 19:09:28

domac
Member
Registered: 2012-08-06
Posts: 102

[solved] How to work with tmpfs?

Hello.
I'm pretty new to ramfs and tmpfs things. So I wanted to ask if someone can give me tips on that? I just read the wiki about ramdisk and this article.

Now I wanted to create a tmpfs partition and wanted to store files for my dwm-statusbar there. Can someone explain what's the best way to do this?

The approach

lucke wrote:

Put this in /etc/fstab:

none    /tmp    tmpfs   nodev,nosuid,noexec,nodiratime,size=1024M    0   0

looked quite good, but I don't understand it fully. I only can guess what nodev,nosuid,noexec,nodiratime means but I don't know it for sure and I want to understand tmpfs for 100%.

Thanks in advance!
Cheers

PS: Also feel free to share your tmpfs and the way you've implemented them! smile

Last edited by domac (2012-08-13 09:42:25)


domac [ git ]

Offline

#2 2012-08-12 19:21:08

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [solved] How to work with tmpfs?

domac wrote:

I don't understand it fully. I only can guess what nodev,nosuid,noexec,nodiratime means but I don't know it for sure and I want to understand tmpfs for 100%.

Generic mount options. see 'man 8 mount' for explanations.

Offline

#3 2012-08-12 19:39:05

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

Thanks so far! I just started reading and can't wait to see more comments on this. smile

Edit: Also wanted to add the following wiki article about tmpfs, which I didn't found until yet. smile

Last edited by domac (2012-08-12 19:41:19)


domac [ git ]

Offline

#4 2012-08-12 20:08:00

Awebb
Member
Registered: 2010-05-06
Posts: 6,297

Re: [solved] How to work with tmpfs?

Congratulations, you have found the wiki article. That'll tell you everything.

Offline

#5 2012-08-12 20:22:53

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

So when I want to create a tmpfs for my dwm statusbar I just put the following in my /etc/fstab:

# tmpfs for ~/.dwmstatus
tmpfs    /home/domac/.dwmstatus  tmpfs   nodev,nosuid,size=8M    0 0

? This should work, right?
And when I then write whatever to files in ~/.dwmstatus/ it is written on ram instead?
Sorry but I'm uncertain, if I do it right. smile

Last edited by domac (2012-08-12 20:46:52)


domac [ git ]

Offline

#6 2012-08-12 20:27:53

hsngrms
Member
From: Turkey
Registered: 2012-03-06
Posts: 41
Website

Re: [solved] How to work with tmpfs?

tmpfs		/tmp	tmpfs	nodev,nosuid,size=512M	0	0

Default conf + size=512M

Last edited by hsngrms (2012-08-12 20:38:56)

Offline

#7 2012-08-12 20:55:42

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

Thanks for sharing hsngrms.
So I just put the line above in my /etc/fstab and every file I put in there is loaded into ram…? Can't believe it should be that easy… :s

Last edited by domac (2012-08-12 20:56:53)


domac [ git ]

Offline

#8 2012-08-13 01:47:50

hsngrms
Member
From: Turkey
Registered: 2012-03-06
Posts: 41
Website

Re: [solved] How to work with tmpfs?

Youre welcome : )

Yes it's easy. But be careful for these reasons:
1. Files on RAM disappear after reboot. So, you can't save your configuration files with tmpfs.
2. Don't add /run as tmpfs DIR. If u add, keyboard & mouse etc. don't work.

Last edited by hsngrms (2012-08-13 01:48:55)

Offline

#9 2012-08-13 09:42:10

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

Ok, thank you all! I'll mark this thread as solved sinve, I've got all thee informations I need. smile


domac [ git ]

Offline

#10 2012-08-13 19:42:24

graph
Member
Registered: 2010-12-21
Posts: 105

Re: [solved] How to work with tmpfs?

Ok, since you invited me to your thread, and I still haven't figured out how to send a pm, here goes.

First I have the following script: statusbar_input

my .xinitrc looks like this:

/home/graph/script/dwm/statusbar_input &
while true
do
	xsetroot -name "$(echo -e "$(cat /tmp/.dwm/ssid) $(cat /tmp/.dwm/wlan)\x03 | \x01B:$(cat /tmp/.dwm/battery)\x03 | \x01V:\x04$(cat /tmp/.dwm/volume)\x03 | \x04$(date +"%H:%M") ")"
	sleep 60s
done &

Finally, my volume-keys run the following script when pressed: volume_wrapper

My /tmp is mounted as a ramdisk, using the following entry in /etc/fstab:

tmpfs /tmp      tmpfs nodev,nosuid,size=1G                 0 0

Last edited by graph (2012-08-13 19:45:30)

Offline

#11 2012-08-13 23:11:45

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

graph wrote:

Ok, since you invited me to your thread, and I still haven't figured out how to send a pm, here goes.

First I have the following script: statusbar_input

my .xinitrc looks like this:

/home/graph/script/dwm/statusbar_input &
while true
do
	xsetroot -name "$(echo -e "$(cat /tmp/.dwm/ssid) $(cat /tmp/.dwm/wlan)\x03 | \x01B:$(cat /tmp/.dwm/battery)\x03 | \x01V:\x04$(cat /tmp/.dwm/volume)\x03 | \x04$(date +"%H:%M") ")"
	sleep 60s
done &

Finally, my volume-keys run the following script when pressed: volume_wrapper

My /tmp is mounted as a ramdisk, using the following entry in /etc/fstab:

tmpfs /tmp      tmpfs nodev,nosuid,size=1G                 0 0

Thanks for sharing! Totally love it. smile
Edit: But how does that make sense when your bar is updated every minute while there is stuff in the bar that get updated more frequently?

Last edited by domac (2012-08-14 13:31:35)


domac [ git ]

Offline

#12 2012-08-14 18:24:41

graph
Member
Registered: 2010-12-21
Posts: 105

Re: [solved] How to work with tmpfs?

domac wrote:

Edit: But how does that make sense when your bar is updated every minute while there is stuff in the bar that get updated more frequently?

I guess you are refering to the loop concerning the wlan-bar? I wanted it to update faster than the others so that I can see the update by simply pressing a volume-button.

Alrighty, but how come it's not a part of the volume_wrapper script then?
No idea, but it is now, so thanks for pointing it out;-)
New statusbar_input btw

Last edited by graph (2012-08-14 18:38:49)

Offline

#13 2012-08-14 18:51:21

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

Hey graph!
Let me show you, how I used your configs. smile
I display pacman packages, cpu temp, cpu use, mem use, wlan stats+ip, bat stat, volume, date

Here is a list of paste's:
dwm-statusbar
dwm-wrapper
startdwm

I have problems with that ram story… when I boot up I have to refresh my bar (didn't manage to store them on shutdown on my hdd → see dwm-wrapper)… made an shortcut for it with cool animation/icon (watch Show off your DWM conf! Thread wink )
dwm-tmpfiles
config.h

Enjoy! Can't wait to present some screenshots. smile
Edit: Screen + files will be soon on git.
Edit2: I think I'll fix my stuff soon in the same direction you did.

Last edited by domac (2012-08-14 18:53:28)


domac [ git ]

Offline

#14 2012-08-15 08:54:04

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

Would you tell me how do you (graph) recover the statusbar after reboot,etc.?
I copied a systemd service for this and wrote a script triggered by this service before and after shutdown to recover the last state of my statusbar.
How do you manage this? smile
Do you keep it empty and refresh then with your volume keys?


domac [ git ]

Offline

#15 2012-08-15 17:39:13

graph
Member
Registered: 2010-12-21
Posts: 105

Re: [solved] How to work with tmpfs?

Haha, I like you. You've stumbled upon the only thing that I don't have a working fix for.
I simply press a volume-key whenever I start my computer. I've thought about doing something about it, but I've sort of gotten used to pressing a button.

EDIT
I have a fix now. (Edit again: and so do you, it seems)
First you need to delete the touch-part from dwm-statusbar. (It was a leftover from when I played with FIFO-pipes, and isn't needed).

Then you could add something like the following at the bottom of dwm-statusbar.

# Write volume to file
amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print " M" } else { print $2 }}' > /tmp/.dwm/volume

while true 
do
	# Count number of files in dir, and draw bar if sufficient number is present.
	if [ $(ls /tmp/.dwm | wc -l) = "5" ]; then
		#EXAMPLE: "SSID [|||||] | B:34 | V:45 | 12:56"
		xsetroot -name "$(echo -e "$(cat /tmp/.dwm/ssid) $(cat /tmp/.dwm/wlan)\x03 | \x01B:$(cat /tmp/.dwm/battery)\x03 | \x01V:\x04$(cat /tmp/.dwm/volume)\x03 | \x04$(date +"%H:%M") ")"
		exit 0
	fi
	sleep 0.05s
done &

This will leave check if all files in /tmp/.dwm is created, and then draw the bar. You will need to adjust the number in the if-condition to the number of files in /tmp/.dwm you are expecting.

Last edited by graph (2012-08-15 18:38:39)

Offline

#16 2012-08-15 18:24:24

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

graph wrote:

Haha, I like you. You've stumbled upon the only thing that I don't have a working fix for.
I simply press a volume-key whenever I start my computer. I've thought about doing something about it, but I've sort of gotten used to pressing a button.

I have a working fix for you. I'm using it too but with systemd service I wrote for a script that re/store your information/status from bar.
If you use initscript, just add "path/to/script store" to rc.shutdown and "path/to/script restore" to rc.local or .xinitrc. If you're using systemd like me, feel free to use my service script. smile

Scripts:
dwm-tmpfile
dwm-tmpfile.service

To make the scripts copy&paste friendly, remove the ?bash from url. I'd love to get credits for the dwm-tmpfile script. big_smile tongue
Just remove the function print_volume() from the script, I guess you don't need it. And you can also remove line 39, it's a personal thing that I want my computer to start up silent, if you know what I mean. wink
Cheers!


domac [ git ]

Offline

#17 2012-08-15 18:50:59

graph
Member
Registered: 2010-12-21
Posts: 105

Re: [solved] How to work with tmpfs?

But your solution will print the wrong info, wouldn't it? Eg: I shutdown my computer on AC and boot the next day from battery. Using your solution would leave me with "AC" in the bar, right? (I could be wrong here)
Other than that, that's a pretty sweet and simple solution. My solution (post above yours) will litteraly just keep on checking for the number of files in /tmp/.dwm, which isn't that clean.

I'm still stuck on init-scripts - Waiting for a rainy day to do the full switch to systemd.

EDIT:
I think you might be able to use "mv" to merge the "cp -r" and "rm" to make your solution even simpler.

mv /home/domac/.tmpdwm/* /tmp/.dwm
chown -R domac /tmp/.dwm
chgrp -R users /tmp/.dwm
/usr/bin/amixer -q -c 0 sset 'Master',0 0% mute
print_volume > /tmp/.dwm/volume

Last edited by graph (2012-08-15 18:57:40)

Offline

#18 2012-08-15 18:56:06

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

graph wrote:

But your solution will print the wrong info, wouldn't it? Eg: I shutdown my computer on AC and boot the next day from battery. Using your solution would leave me with "AC" in the bar, right?
Other than that, that's a pretty sweet and simple solution. My solution (post above yours) will litteraly just keep on checking for the number of files in /tmp/.dwm, which isn't that clean.

I'm still stuck on init-scripts - Waiting for a rainy day to do the full switch to systemd.

I like your solution! smile Maybe I'll try to mix them up tomorrow and see if I can find a good consensus.
Edit: I think my solution, will be kinda replaced by yours… your solution is so obvious but I really couldn't think of it at times. big_smile
Edit2: Thanks for that tip!
Edit3: I guess I'll do it like that: When my pc wakes up I check all the stuff for validity and only write updates. Well then maybe there's stuff I could skip to write because it will always be invalid… hmmn. Or I just run your script on restore. wink What do you think?

Last edited by domac (2012-08-15 19:07:56)


domac [ git ]

Offline

#19 2012-08-15 19:09:47

graph
Member
Registered: 2010-12-21
Posts: 105

Re: [solved] How to work with tmpfs?

I'm sort of embarrassed. While-loop-fixes like this is something I use way more than I'm proud of.

Since this thread have moved far of already - Are you using the systray-patch to get your systray in the statusbar?

And also, I've noticed another "bug" in my solution:
If netcfg for any reason fails to connect to my default AP, it will break the wlan-while-loop when it's first run, set the SSID to "off/any" and don't retry until next reboot.

Other than that, I've really been enjoying where this has been going. I've thought about lots of stuff that I wouldn't have otherwise.

Last edited by graph (2012-08-15 19:30:43)

Offline

#20 2012-08-15 20:35:21

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] How to work with tmpfs?

Well I've got that awesome scriptbase of yours and the wifi strength function. smile
I also like the direction this is going. I'm interested how far this can go! smile
I'll think about some new solutions and post them here. Maybe we should open up a thread especially for dwm statusbar optimization?

Yes, I'm using the systray patch, which you can also find in my git… somewhere in my dwm folder ^^
Postin my changes tomorrow, if I have some. tongue

Edit: Earlier as expected, but I kinda got bored since the soccer game sucked for my team… so here it is:
startdwm
dwm-func
dwm-statbar
dwm-statbar-poll
dwm-key-wrapper
dwm-tmpfs
Maybe I have to merge them again at some spots, since there are some things not loaded in my statusbar. This problem appeared with the "split-up" of scripts.
Dunno if I will change more… if you have ideas, please feel free to modify! smile

Edit2: Merged dwm-tmpfs-setup into dwm-tmpfs. That was causing the error I guess. tongue

Last edited by domac (2012-08-16 09:30:08)


domac [ git ]

Offline

Board footer

Powered by FluxBB