You are not logged in.

#1 2009-09-17 18:41:46

b52
Member
From: Germany
Registered: 2009-03-20
Posts: 49
Website

/var to tmpfs

Hey,

I'm running arch on a tiny homeserver with an USB pen drive as root.
Since the write cycles are limited I would like to reduce the load on the pen drive as much as possible.
Since /var is a commonly used part of the filesystem I would like to put it in to ram.

My thougts are, that I could add another init script which handles this:
On boot it creates a tmpfs e.g. to /var_tmp, copies all stuff from /var to /var_tmp, and moves the tmpfs mount point from /var_tmp to /var.
On shutdown it should do this steps in reverse order, so that no stuff gets lost.

What do you think? How could I realise that?

Thanks,
Oli


srsly?

Offline

#2 2009-09-17 19:32:12

genisis300
Member
From: Uk
Registered: 2008-01-15
Posts: 284

Re: /var to tmpfs

make your own dameon and call it from the rc.conf. it's wouldn't be that difficult to-do. might slow the boot down a little while it copy's the files across.

best way to learn would be to open up one of the existing scripts in /etc/rc.d/ see how they work then produce your script. that way it's called on start and exit only downside would be if you had a crash you might loose some stuff from /var


"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson

Offline

#3 2009-09-17 19:44:32

bender02
Member
From: UK
Registered: 2007-02-04
Posts: 1,328

Offline

#4 2009-09-17 19:47:31

b52
Member
From: Germany
Registered: 2009-03-20
Posts: 49
Website

Re: /var to tmpfs

i hope the system never crashes big_smile

how can i remount a tmpfs for e.g. /foo to /bar without losin its content?


srsly?

Offline

#5 2009-09-17 20:33:57

genisis300
Member
From: Uk
Registered: 2008-01-15
Posts: 284

Re: /var to tmpfs

do it the other way round.

copy the contents of /var to /var_tmp
mount tmpfs to /var
copy back the contents.



Or see the link above. big_smile

Last edited by genisis300 (2009-09-17 20:35:40)


"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson

Offline

#6 2009-09-17 20:55:03

b52
Member
From: Germany
Registered: 2009-03-20
Posts: 49
Website

Re: /var to tmpfs

genisis300 wrote:

do it the other way round.

copy the contents of /var to /var_tmp
mount tmpfs to /var
copy back the contents.



Or see the link above. big_smile

what is the benefit?

i actually do it this way:

#!/bin/bash                     

. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
        start)
                stat_busy "Creating /var tmpfs"

                rm -rf /tmp/var
                mkdir /tmp/var 

                mount -t tmpfs tmpfs /tmp/var -o size=500M,noatime
                cp -rp /var/* /tmp/var                            
                mount --move /tmp/var /var                        

                rm -rf /tmp/var

                add_daemon vartmpfs
                stat_done          
                ;;                 
        stop)                      
                stat_busy "Syncing /var back"

                rm -rf /tmp/var
                mkdir /tmp/var 

                mount --move /var /tmp/var
                rsync -a /tmp/var/* /var/
                umount /tmp/var

                rm -rf /tmp/var

                rm_daemon vartmpfs
                stat_done
                ;;
        restart)
                $0 stop
                $0 start
                ;;
        *)
                echo "usage: $0 {start|stop|restart}"
                ;;
esac

exit 0

what do you think?


srsly?

Offline

#7 2009-09-17 21:08:20

genisis300
Member
From: Uk
Registered: 2008-01-15
Posts: 284

Re: /var to tmpfs

nothing at all the above was just my suggestion on how i would have probably done it, However the mount --move is probably better.

all though both kind of work in the same way just done differently.


"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson

Offline

#8 2009-09-17 21:10:41

b52
Member
From: Germany
Registered: 2009-03-20
Posts: 49
Website

Re: /var to tmpfs

Ok,

seems to work for.
Unless someone has to add anything this thread can be marked as solved. smile


srsly?

Offline

#9 2009-09-17 21:43:40

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: /var to tmpfs

Have you considered using FUSE to do this?

You could mount your /var partition as something else and then make /var a FUSE directory that transparently reads from the actual /var partition. All write changes could be stored in tmpfs and synced on exit. This way you could avoid copying everything in /var at boot and at shutdown.

Depending on how you do it, it should also be possible to sync the /var partition without unmounting FUSE. For example, you could add a local server to the FUSE appllication so that you could pass it commands via a port on localhost.

I would also add a routine to sync the disk after a certain amount of time or data to make sure that you don't lose anything critical if the system crashes.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#10 2009-09-17 21:49:57

b52
Member
From: Germany
Registered: 2009-03-20
Posts: 49
Website

Re: /var to tmpfs

No I haven't.
And actually its too complex for me.


srsly?

Offline

Board footer

Powered by FluxBB