Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Tip/Trick: using tmpfs for /tmp
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
mr.ed
Tux's lil' helper
Tux's lil' helper


Joined: 30 Nov 2004
Posts: 75

PostPosted: Sun Apr 24, 2005 9:03 pm    Post subject: Reply with quote

Quote:
This makes /dev/shm and /tmp share one tmpfs.

/etc/conf.d/local.start:
Code:
cp -Rp /tmp /dev/shm
mount --bind /dev/shm/tmp /tmp
:!: cp instead of mkdir, this avoids X11 crash.


This is a bit weird... Mine implements /tmp BEFORE /tmp and /var/tmp get used (at mountpoint), but yours AFTER? No wonder u had X crashes m8... Look at the dirs in tmp, lol, u should have figured that one out yourself! 8O If u create and mount the tmpfs before the rest and at the same time create the tmp-dir, al progs after allready can use the tmpfs...:idea:

As for the symlinks: they r easier cause with this u can put virtually EVERYTHING in tmpfs with a simple symlink... Instead of having everything to mount, which takes longer at startup...:roll:

Third benefit: this way i know for sure my whole tmp is gone on reboot, cause if u don't do the mkdir /dev/shm/tmp, it will complain bout not finding mountpoint tmp!:wink:

Finally: mount --bind /dev/shm/tmp /tmp? Why put it in local? Wouldn't it be easier to add this line to fstab: /tmp /dev/shm/tmp tmpfs bind 0 0? Or better yet: tmpfs /dev/shm/tmp tmpfs defaults,mode=1777,size=512M???
_________________
(Ex-Pornstar)
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 508
Location: North~Sea~Coa~s~~t~~~

PostPosted: Sun Apr 24, 2005 9:51 pm    Post subject: Reply with quote

mr.ed wrote:
This is a bit weird... Mine implements /tmp BEFORE /tmp and /var/tmp get used (at mountpoint), but yours AFTER? No wonder u had X crashes m8... Look at the dirs in tmp, lol, u should have figured that one out yourself! 8O If u create and mount the tmpfs before the rest and at the same time create the tmp-dir, al progs after allready can use the tmpfs...:idea:
It works fine. :D I didn't want to mess up the init scripts, and local.start is for your own commands. The only things copied over are 2 empty dirs .X11-unix and .ICE-unix in /tmp, made by bootmisc. No big deal.

mr.ed wrote:
Finally: mount --bind /dev/shm/tmp /tmp? Why put it in local? Wouldn't it be easier to add this line to fstab: /tmp /dev/shm/tmp tmpfs bind 0 0? Or better yet: tmpfs /dev/shm/tmp tmpfs defaults,mode=1777,size=512M???
/tmp must be copied to /dev/shm first, so fstab wil be to early to bind mount. But changing localmount would be more right.

/etc/init.d/localmount:
Code:
...
start() {
# Mount local filesystems in /etc/fstab.
ebegin "Mounting local filesystems"
mount -at nocoda,nonfs,noproc,noncpfs,nosmbfs,noshm >/dev/null
### bind mount
mkdir -m 1777 /dev/shm/tmp
mount --bind /dev/shm/tmp /tmp >/dev/null
###
eend $? "Some local filesystem failed to mount"
...


Last edited by lost+found on Mon Apr 25, 2005 6:15 am; edited 2 times in total
Back to top
View user's profile Send private message
DrWoland
l33t
l33t


Joined: 13 Nov 2004
Posts: 603

PostPosted: Mon Apr 25, 2005 6:11 am    Post subject: Reply with quote

Can tmpfs be set to noexec?

Edit: Sure can!!
_________________
I'm not a Guru, I just ask a lot of questions.
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 508
Location: North~Sea~Coa~s~~t~~~

PostPosted: Mon Apr 25, 2005 9:14 am    Post subject: Reply with quote

DrWoland wrote:
Can tmpfs be set to noexec?

Edit: Sure can!!
http://www.gentoo.org/doc/en/gentoo-security.xml#doc_chap5
Any problem script detected so far?
Back to top
View user's profile Send private message
mr.ed
Tux's lil' helper
Tux's lil' helper


Joined: 30 Nov 2004
Posts: 75

PostPosted: Mon Apr 25, 2005 12:52 pm    Post subject: Reply with quote

lost+found wrote:
Quote:
DrWoland wrote:
Can tmpfs be set to noexec?

Edit: Sure can!!
http://www.gentoo.org/doc/en/gentoo-security.xml#doc_chap5
Any problem script detected so far?


There should be no problems, unless u put the portage tmp dir in /tmp: emerge needs be able to execute scripts!! (u will get an error similar to this: /usr/portage/eclass/kde.eclass: ./configure: /bin/sh: bad interpreter)

lost+found wrote:
Quote:
/tmp must be copied to /dev/shm first, so fstab wil be to early to bind mount. But changing localmount would be more right.


Uh and now u r hacking scripts to make your 'trick' work? lol man, u said before u didn't like to do that ( I didn't want to mess up the init scripts, and local.start is for your own commands) ... Tmp doesn't need to be copied first, cause if u do it right it all gets deleted on reboot and thus the only thing u 'need' to do is make a new tmp-folder on startup!!! It's a bit more logical then your approach: u delete the whole tmp at shutdown and create a new one at startup (instead of copying the existing tmp over, evil script kiddies would love that one)... An excerpt of how i do it:

Quote:
# Make tmp directories for mounting /etc/fstab.
ebegin "Creating and mounting tmpfs filesystems (tmpfs)"
mount /dev/shm
mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
eend $? "Some tmpfs filesystem failed to mount (tmpfs)"


And yeah, mkdir -m 1777 is the same, but if something goes wrong or doesn't work, it's easier this way to check where it went wrong...

I really don't get why u think lost+found, that i don't know anything m8... U trying to convince me to do otherwise (afk your approach), try to flame my posts, but in the end your own posts get flamed with better arguments to which u have no reply... And u contradict yourself!!! That's no problem at all btw, allways like a good discussion bout something, but be carefull when u quote something....
_________________
(Ex-Pornstar)
Back to top
View user's profile Send private message
adsmith
Veteran
Veteran


Joined: 26 Sep 2004
Posts: 1386
Location: NC, USA

PostPosted: Mon Apr 25, 2005 1:10 pm    Post subject: Reply with quote

Actually, I don't see why either of you are bothering to make /tmp a subdir of /dev/shm. There is no harm in having multiple tmpfs's.
Back to top
View user's profile Send private message
NotQuiteSane
Guru
Guru


Joined: 30 Jan 2005
Posts: 484
Location: Klamath Falls, Jefferson, USA, North America, Midgarth

PostPosted: Thu May 26, 2005 1:31 am    Post subject: encrypted tmpfs? Reply with quote

hey peoples,

I have both /tmp and /var/tmp on tmpfs (also encrypted swap)

I'm playing around trying to create an encrypted /tmp. I try:

Code:
cryptsetup -c serpent -d /dev/urandom create temp /dev/shm/

&

cryptsetup -c serpent -d /dev/urandom create temp none

&

cryptsetup -c serpent -d /dev/urandom create temp tmpfs


All 3 return the same error message:

Code:
Command failed: Block device required


so, question one, what is the proper block device for tmpfs, and two, considering /tmp is mounted in "memory" vs "disk" and I already have encrypted swap, do I need to encrypt it? perhaps a hourly cron job to shred/delete anything older than X minutes would work just as well?

NQS
_________________
These opinions are mine, mine I say! Piss off and get your own.

As I see it -- An irregular blog, Improved with new location

To delete French language packs from system use 'sudo rm -fr /'
Back to top
View user's profile Send private message
Garr
n00b
n00b


Joined: 06 Mar 2003
Posts: 10

PostPosted: Fri May 27, 2005 5:54 am    Post subject: debian servers use tmpfs Reply with quote

and recently at work - I found out why :)

if anyone has looked after mysql on a server before, they may know about some of the little "issues" mysql has, such as filling up the partition (usually /var), and thus crashing the whole damn server.

Most MySQL queries are collated in memory. If there is an output over a certain size (configured in the my.cnf) it will dump the answer out to the disk, /tmp by default.

If your webdevs make stupid mistakes (I have found the orderby command can often be the culprit), and the server spirals out into oblivion - if you use tmpfs - it will simply crash the thread, and give a nice error (something like error blah /tmp/XyZcTpB). But the server keeps on keeping on.

I am not sure if only the one thead crashes, is because we use a J2EE server to talk to the mysqldb, but eh - whatever - I love it :) Much better than a 4am call from the data center coz somebody left in a stupid line of code on a query that only gets used once a week - at 4 am ;)
Back to top
View user's profile Send private message
Drysh
Apprentice
Apprentice


Joined: 06 Apr 2005
Posts: 203
Location: São Paulo, Brazil

PostPosted: Fri May 27, 2005 9:05 am    Post subject: Reply with quote

I'm using tmpfs for a month now, and it seems to be working..

My fstab is:
Code:
/dev/sda1      /boot            ext2          noatime                                 1 2
/dev/sda2      /                reiserfs      noatime                                 0 0
/dev/sda3      /files           xfs           osyncisdsync                            1 1
/dev/sda4      none             swap          sw                                      0 0
proc           /proc            proc          defaults                                0 0
tmpfs          /dev/shm         tmpfs         defaults,nosuid,size=3072M,mode=1777    0 0
/dev/shm       /tmp             none          rw,bind                                 0 0
/dev/shm       /var/tmp         none          rw,bind                                 0 0

And my swap is:
Code:
Filename        Size        Used       Priority
/dev/sda4      4140856      226232     -1

I have 1GB RAM, so I'm using this huge swap to avoid:
- errors when emerging large packages;
- the system not responding because there is no memory.

I'm using a single tmpfs to reduce the chance of having one filled up and another empty (without reserving cache for each one); and to make it easier to manage that (I don't have to think about how much each directory uses). I never saw any problem with /dev/shm, /tmp and /var/tmp being the same directory. Portage is using /dev/shm as temporary file.
I tested compilling oppenoffice, while running gnome and having gimp with large image files opened.. Everything seems fine. What I noticed is that the system is much faster when I'm doing the same thing for some time.. I mean, the applications seems to speed up after 1 or 2 minutes running. I still need to perform more methodical mesures of performance (time everything), because I was more concerned with making it work than making it fast.

Does anyone see anything wrong with what I'm using? Is it too much swap? (Apparently I'm using less then 1GB most of the time, but during the test I saw more than 2 GB of swap.) Is there any problem binding the way I did (everything in the same directory)?
And while we are at it, about that xfs.. I heard osyncisdsync is now default, is it true? BTW, I'm using xfs for /files, a directory I created to store all my common use files, like: mp3, images (photos), videos, docs that I read a lot but do not edit, etc. Since xfs is very fast reading and not so fast writting, it worked like a charm. But I'm still taking suggestions for this one.
Back to top
View user's profile Send private message
Drysh
Apprentice
Apprentice


Joined: 06 Apr 2005
Posts: 203
Location: São Paulo, Brazil

PostPosted: Fri May 27, 2005 9:20 am    Post subject: Reply with quote

NotQuiteSane:

Take a look at this:
The 'Advanced filesystem implementor's guide', on IBM forums wrote:
Not a block device
Here's another interesting property of the tmpfs filesystem. Unlike most "normal" filesystems, like ext3, ext2, XFS, JFS, ReiserFS and friends, tmpfs does not exist on top of an underlying block device. Because tmpfs sits on top of VM directly, you can create a tmpfs filesystem with a simple mount command:
Code:

# mount tmpfs /mnt/tmpfs -t tmpfs


After executing this command, you'll have a new tmpfs filesystem mounted at /mnt/tmpfs, ready for use. Note that there's no need to run mkfs.tmpfs; in fact, it's impossible, as no such command exists. Immediately after the mount command, the filesystem is mounted and available for use, and is of type tmpfs. This is very different from how Linux ramdisks are used; standard Linux ramdisks are block devices, so they must be formatted with a filesystem of your choice before you can use them. In contrast, tmpfs is a filesystem. So, you can just mount it and go.

I think there isn't a block device after all. Isn't there an option for cryptography with tmpfs in the kernel config? I remember something about it, but I'm not sure.

I hope it helps. Please, post the results if you find how to use them together.
Back to top
View user's profile Send private message
Drysh
Apprentice
Apprentice


Joined: 06 Apr 2005
Posts: 203
Location: São Paulo, Brazil

PostPosted: Fri Jun 24, 2005 8:21 pm    Post subject: Reply with quote

I'm having a small problem with /tmp... Some packages create special directories under /tmp and they expect them to be there after reboot. One example is gimp. It creates /tmp/gimp-2.2 to use as a swap file, and it complains that it doesn't exist (since it disapears after a reboot). The way I'm using to fix this is a rc script to create these directories.

Some questions:

1. Is it a problem to set the swap directory of gimp to /tmp? I'm afraid it might confuse some file with other applications.

2. Does anyone knows how tmpfs manages memory? Will it be problematic to create a lot of tmpfs (one for each directory)? Or is it better to make like I did (see post above), binding them in a single tmpfs?

3. Any ideas how to handle multiple directories with tmpfs: with data that may be lost, but with a structure (sub-dirs) that needs to survive a reboot?
Back to top
View user's profile Send private message
adsmith
Veteran
Veteran


Joined: 26 Sep 2004
Posts: 1386
Location: NC, USA

PostPosted: Sun Jun 26, 2005 4:54 pm    Post subject: Reply with quote

Drysh wrote:
I'm having a small problem with /tmp... Some packages create special directories under /tmp and they expect them to be there after reboot.



this should not happen. no program should assume /tmp is permanent. If gimp does this, it should be considered a bug. If directoried are supposed to be persistent, they should reside in your home directory or in some permanent system directory.

Quote:

2. Does anyone knows how tmpfs manages memory? Will it be problematic to create a lot of tmpfs (one for each directory)? Or is it better to make like I did (see post above), binding them in a single tmpfs?


it doesn't matter. If nothing is in a tmpfs, it takes up no space. there is no problem having multiple tmpfs's.

Quote:

3. Any ideas how to handle multiple directories with tmpfs: with data that may be lost, but with a structure (sub-dirs) that needs to survive a reboot?


of you really want to do this, add
mv /my/tmpfs /somewhere/permanent/
to /etc/conf.d/local.stop
and add
mv /somewhere/permanent/tmpfs /my
to /etc/conf.d/local.start
Back to top
View user's profile Send private message
Drysh
Apprentice
Apprentice


Joined: 06 Apr 2005
Posts: 203
Location: São Paulo, Brazil

PostPosted: Mon Jun 27, 2005 1:41 am    Post subject: Reply with quote

Thanks!

I'm using...
mkdir /tmp/gimp
...in local.start and it works now. Gimp doesn't create the directory.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum