Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Ramdisk init script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sat Aug 17, 2002 11:29 pm    Post subject: Ramdisk init script Reply with quote

On a whim (mostly), I wrote an init script for handling ramdrives. Basically, you tell it where you want it to make a ramdrive, and it will do all kinds of nifty things such as automatically save its contents and restore it as necessary. Anyway, here's the code:

/etc/init.d/ramdisk:
Code:
#!/sbin/runscript
# Written by delta407 (delta407@lerfjhax.com)
# Distributed under the terms of the GNU General Public License, v2 or later

depend() {
        need localmount
}

start() {
        mkdir -p ${RDPATH}
        for MP in ${RAMDISKS}; do
                MPN=`echo ${MP} | sed -e 's/\//-/g' -e 's/^-//g' -e 's/-$//g'`

                ebegin "Starting ramdisk on ${MP}"

                TARCMD="tar xpf${RDTAROPTS} ${RDPATH}/${MPN}${RDTARSUFFIX}"
                [[ -e ${RDPATH}/${MPN}${RDTARSUFFIX} ]] || TARCMD="true"

                touch ${RDPATH}/${MPN}${RDTARSUFFIX}
                mount ${MPN} ${MP} -t tmpfs && \
                        cd ${MP}/.. && \
                        `${TARCMD}`
                eend $?
        done
}

stop() {
        mkdir -p ${RDPATH}
        for MP in ${RAMDISKS}; do
                MPN=`echo ${MP} | sed -e 's/\//-/g' -e 's/^-//g' -e 's/-$//g'`
                ebegin "Stopping ramdisk on ${MP}"
                cd ${MP}/.. && \
                        tar cpf${RDTAROPTS} ${RDPATH}/${MPN}${RDTARSUFFIX} `basename ${MP}` && \
                        umount ${MP}
                eend $?
        done
}


/etc/conf.d/ramdisk:
Code:
# Config file for /etc/init.d/ramdisk

# Space-separated mountpoints that should be ramdisks
RAMDISKS="/mnt/rd"

# Path to store ramdisk tarballs in
# This will be created as necessary
RDPATH="/var/ramdisk"

# Extra flags to pass to tar
# Change this to "z" to gzip, "j" to bzip2, or empty for no compression
# Note that changing this will require modifying the file in RDPATH accordingly
#   (i.e. going from z to j you would gunzip then bzip2 the tar file, etc.)
RDTAROPTS="z"

# Tar file suffix
# If you enabled compression, you might want to make this .tar.gz or .tbz2 or something
RDTARSUFFIX=".tar.gz"


Think about this if you're running a rsync mirror, since rsync mtime()s the whole tree whenever someone connects. You can get some serious performance boosts out of it.

Potential problems, though, include loss of data since the last /etc/init.d/ramdisk restart if power is lost. (That's what happens, it's in RAM.)

Anyway, hope you find this useful.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
SAckerman
n00b
n00b


Joined: 18 Aug 2002
Posts: 7
Location: California

PostPosted: Sun Aug 18, 2002 4:38 am    Post subject: Ramdisk init script Reply with quote

Actually I am interested in your script...

I am trying to setup a system using a 512mb mem card with an IDE interface. The cards are not reccommended for continuous r/w so I thought I could boot from it then copy /, /bin, /sbin and /lib to a ramdisk and run /var, /usr and /opt from a hard disk. This is for a firewall/proxy machine. I think your script could probably be easily modified to do this... but I am not a very good scripter.
Back to top
View user's profile Send private message
TuxFriend
Apprentice
Apprentice


Joined: 14 Aug 2002
Posts: 151

PostPosted: Sun Aug 18, 2002 6:05 am    Post subject: Reply with quote

Thanks for this script. I do have a few questions:
- I have tmpfs enabled in my fstab (doesn't seem to do anything though) is it that required or prohibited?
- Is ramdisk "user-friendly" when doing memory allocation, I mean does it give itself the lowest priority so other programs keep running or is it too "greedy" when allocating memory? Is the allocation static or dynamic?
- Do you want to submit this to bugzilla so it will be available in Gentoo? I think a lot of people would appreciate it.

TuxFriend
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sun Aug 18, 2002 6:26 am    Post subject: Reply with quote

I have a few answers: ;)
- Just "rc-update add ramdisk boot" and there will be no need for an fstab entry. (It calls mount explicitly, so it will override your fstab either way.)
- The ramdisk acts just like any other tmpfs drive. I think it obeys the same swapping rules as user-mode programs -- i.e. it will act intelligently if you run out of RAM.
- I don't know where I would submit it to Bugzilla, and as such, I won't (at least not yet). I thought others would appreciate it; that's why I posted it here.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
TuxFriend
Apprentice
Apprentice


Joined: 14 Aug 2002
Posts: 151

PostPosted: Sun Aug 18, 2002 6:41 am    Post subject: Reply with quote

Thanks for your quick reply.
Since you are in the mood for providing information, (hopefully) last question:

I saw in another post your tip "# mount portagetemp /var/tmp/portage/ -t tmpfs". Is this still required or is the "rc-update add ramdisk boot" sufficient?

TuxFriend

BTW. don't you sleep? It looks like you post 24/7
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sun Aug 18, 2002 5:18 pm    Post subject: Reply with quote

I do sleep, but my hours vary. ;)

Anyway, if you wanted /var/tmp/portage to be a ramdrive (tmpfs), just change or add '/var/tmp/portage' to the RAMDISKS variable.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Sun Aug 18, 2002 8:40 pm    Post subject: Re: Ramdisk init script Reply with quote

SAckerman wrote:
I am trying to setup a system using a 512mb mem card with an IDE interface. The cards are not reccommended for continuous r/w so I thought I could boot from it then copy /, /bin, /sbin and /lib to a ramdisk and run /var, /usr and /opt from a hard disk.


I thought about this a while, and I think you would be better off using an initrd. (Ask Google.)
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Mon Sep 09, 2002 2:44 pm    Post subject: Reply with quote

There is documentation for initrd in the kernel documentation.
/usr/src/linux/Documentation/initrd.txt

Also documentation on ramdisk usage in there... same path, ramdisk.txt.

Great supplement to that script :)
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Mon Sep 09, 2002 3:18 pm    Post subject: Reply with quote

I just copied over the init.d and conf.d scripts, made a directory in /var called ramdisk, chmod'ed 755 /etc/init.d/ramdisk /etc/conf.d/ramdisk, and then tried executing /etc/init.d/ramdisk, but it gives me the error:
bash-2.05a# /etc/init.d/ramdisk start
* ERROR: "/etc/init.d/ramdisk" has syntax errors in it; not executing...

(I copied/pasted to Kate, so the format was kept)

I looked at it, but from my eyes I can't see anything wrong....
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20488

PostPosted: Mon Sep 09, 2002 3:39 pm    Post subject: Re: Ramdisk init script Reply with quote

Code:
tar cpf${RDTAROPTS} ${RDPATH}/${MPN}${RDTARSUFFIX} `basename ${MP}` && \
Is that all on one line? In the code block from delta407's post, it looks like the && \ is on a seperate line. I'm guessing browser width wrapped it. Any other similar lines get wrapped for you?
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Tue Sep 10, 2002 2:43 am    Post subject: Reply with quote

arkane wrote:
bash-2.05a# /etc/init.d/ramdisk start
* ERROR: "/etc/init.d/ramdisk" has syntax errors in it; not executing...

See, that's one thing I detest about /sbin/runscript.sh. It blows up but doesn't tell you what's wrong. ;)

Does `bash /etc/init.d/ramdisk` and get a more descriptive message?
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Sun Sep 15, 2002 1:15 am    Post subject: Reply with quote

Nevermind...
It probably was the formatting. I removed everything and copied/pasted through VI, now everything is working....

strange.
Back to top
View user's profile Send private message
dreamer3
Guru
Guru


Joined: 24 Sep 2002
Posts: 553

PostPosted: Sat Nov 16, 2002 7:39 am    Post subject: Reply with quote

Along those same lines you might find this and this useful as well.
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
Page 1 of 1

 
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