You are not logged in.
Pages: 1
I have posted another topic about a quiet harddisk and better performance.
These settings are part of a script I am using at boot and shutdown.
The script is copying my home directory to a ramdisk, the same is done with /tmp.
This is ofcourse only possible when you have a separate /data directory, and not only a $USER where all your stuff is stored.
The result;
- almost no harddisk writes when browsing, reading mail, editing etc...
- almost quiet system
- better performance because most things are done from ram
Disadvantages:
- when your system is crashing, your changes are lost
- you do need more ram (advice 1G or more)
- your system is not standard anymore.
Before using the script, please try to understand what I am doing!
BTW; it is necessarry that the users are added to the group audio in /etc/group, because I am using that group to find out which users are available.
Here is the script (changes mentioned some posts below are added):
#!/bin/sh
#
# Performance script
# Maintainer: Lontronics, info@lontronics.nl
# Last modified: april 16th, 2007
action_start() {
#
# Change interval to 10 minutes for pdflush:
#
echo 60000 > /proc/sys/vm/dirty_expire_centisecs
# Let the harddisk spin down when not used for X * 5 seconds
# For example 12 will give a standby time of 24*5=120 seconds
# Also set read ahead to on
if [ -x /sbin/hdparm ]; then
/sbin/hdparm -S 24 -A 1 /dev/sda
fi
#
# Clean ramdisk directory and mount ramdisk for writing temporary information
#
if [ -d /mnt/ramdisk0 ]; then
rm -rf /mnt/ramdisk0/* > /dev/null
else
mkdir /mnt/ramdisk0
fi
mount -t tmpfs tmpfs /mnt/ramdisk0
#
# Check tmp directory...
#
if [ ! -d /tmp ]; then
rm -rf /tmp
mkdir /tmp
chmod 777 /tmp
fi
#
# Find available users and take action...
# We take the audio group in /etc/group, but you can take every group which is containing all normal users
#
NAME=($(grep ^audio /etc/group | cut -d: -f4 | tr "," " "))
count=0
while [ "x${NAME[count]}" != "x" ]
do
#
# If no user directory then extract the backup when available.
#
if [ ! -d /home/${NAME[$count]} ]; then
rm -rf /home/${NAME[$count]}
mkdir /home/${NAME[$count]}
chown -R ${NAME[$count]} /home/${NAME[$count]}
if [ -f /home/${NAME[$count]}.tar.gz ]; then
tar zPxvf /home/${NAME[$count]}.tar.gz --directory=/ > /dev/null
if [ -d /home/${NAME[$count]} ]; then
echo ""
echo "WARNING:"
echo "Extracted backup to /home/${NAME[$count]}"
echo "It is possible some data is lost..."
rm -rf /home/${NAME[$count]}.tar.gz
else
echo ""
echo "ERROR:"
echo "Error occured when extracting files from backup."
echo "Check backup with name /home/${NAME[$count]}.tar.gz and try to extract it yourself"
echo "with the command tar zxvf /home/${NAME[$count]}.tar.gz --directory=/"
echo "New but empty user directory for user ${NAME[$count]} made"
fi
else
echo ""
echo "ERROR:"
echo "Unfortunately there seems no backup available."
echo "New but empty user directory for user ${NAME[$count]} made"
fi
fi
#
# Make backup of user directory for when things are going wrong
#
tar -cPpz --file=/home/${NAME[$count]}.tar.gz /home/${NAME[$count]} > /dev/null
#
# Copy home directory information to the ramdisk for usage
#
mv /home/${NAME[$count]} /mnt/ramdisk0
ln -s /mnt/ramdisk0/${NAME[$count]} /home/${NAME[$count]}
echo "${NAME[$count]}"
count=$(( $count + 1 ))
done
#
# Copy tmp directory information to the ramdisk for usage
#
mv /tmp /mnt/ramdisk0/tmp
ln -s /mnt/ramdisk0/tmp /tmp
#
# Output
#
echo "Performance script started"
echo "Do not forget to run performance stop before shutdown,"
echo "otherwise it is possible you will loose your data!"
}
action_stop() {
ERROR=0
#
# Change interval for pdflush to normal:
#
echo 500 > /proc/sys/vm/dirty_expire_centisecs
# Disable standby (spindown)
if [ -x /sbin/hdparm ]; then
/sbin/hdparm -S 0 /dev/sda
fi
#
# Find available users and take action...
# We take the audio group in /etc/group, but you can take every group which is containing all normal users
#
NAME=($(grep ^audio /etc/group | cut -d: -f4 | tr "," " "))
count=0
while [ "x${NAME[count]}" != "x" ]
do
#
# If temporary user directory available then...
#
if [ -d /mnt/ramdisk0/${NAME[count]} ]; then
#
# Copy ramdisk information to real directory
#
rm -rf /home/${NAME[count]}
mv /mnt/ramdisk0/${NAME[count]} /home/${NAME[count]}
rm -rf /home/${NAME[count]}.tar.gz
else
ERROR=1
echo ""
echo "ERROR:"
echo "The temporary user directory seems not to be available on the ramdisk, probably the performance script was not running"
echo "Therefor the following actions are not performed:"
echo "- /home/${NAME[count]} is not replaced"
echo "- /mnt/ramdisk0 is not unmounted"
echo "Please check if everything is okay"
fi
count=$(( $count + 1 ))
done
#
# If tmp directory on ramdisk is available then...
#
if [ -d /mnt/ramdisk0/tmp ]; then
rm -rf /tmp
rm -rf /mnt/ramdisk0/tmp/*
mv /mnt/ramdisk0/tmp /tmp
else
ERROR=1
echo ""
echo "ERROR:"
echo "The tmp directory seems not to be available on the ramdisk, probably the performance script was not running"
echo "Therefor the following actions are not performed:"
echo "- /tmp is not replaced"
echo "- /mnt/ramdisk0 is not unmounted"
echo "Please check if everything is okay"
fi
#
# If no errors occured unmount the ramdisk to free memory
#
if [ $ERROR = 0 ]; then
umount -f /mnt/ramdisk0 2> /dev/null
rm -rf /mnt/ramdisk0 2> /dev/null
fi
#
# Output
#
echo "Performance script stopped"
}
case "$1" in
'start')
action_start
;;
'stop')
action_stop
;;
*)
echo "usage $0 start|stop"
esac
To use the script:
in /etc/rc.sysinit find:
stat_busy "Removing Leftover Files"
/bin/rm -f /etc/nologin &>/dev/null
/bin/rm -f /etc/shutdownpid &>/dev/null
just above add:
# Activate the performance script
if [ -x /data/scripts/performance ]; then
/data/scripts/performance start
fi
Where ofcourse /data/scripts/performance is my path of the performance script, but you have to change this to where you have saved the script
in /etc/rc.shutdown find:
# avoid NIS hanging syslog-ng on shutdown by unsetting the domainname
if [ -x /bin/domainname ]; then
/bin/domainname ""
just above add:
# Stop the performance script
if [ -x /data/scripts/performance ]; then
/data/scripts/performance stop
fi
Where ofcourse /data/scripts/performance is my path of the performance script, but you have to change this to where you have saved the script
Have fun!
Jan
Last edited by Lontronics (2007-04-17 20:30:57)
Offline
Did you try to put /tmp only on ramdisk? Did you feel any speed up? I believe that home directory on a ramdisk is dangerous - however /tmp is a great idea.
Offline
Is there any objection to putting the script in /etc/rc.d and calling it from the DAEMONS-array in rc.conf?
I'd say that would be a somewhat neater way of doing this than messing with rc.{sysint,shutdown}...
Otherwise... maybe just tmp for me... I'll just stick to a solid home
Nice work though...
I'd change
NAME=($(grep ^audio /etc/group | sed 's/audio::[0-9]\{2,3\}://g' | tr ":" " "))
into
NAME=($(grep ^audio /etc/group | cut -d: -f4))
On the off chance that someone might have provided a password or something else out of the ordinary to the audio-group though. It outputs field 4 of a ':'-delimited input
Last edited by klixon (2007-04-16 08:14:42)
Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!
Offline
@drakosha;
Yes I did, but not for getting better performance. The noticable difference is less writing to the disk, especially with the other settings used in the script. But why not trying yourself with a /tmp ramdrive ?
@klixon;
Thanks for the compliment.
And about your line of script; thanks too, although you were forgotten one thing to make an array from it.
Will use cut though, simple indeed
Line is now:
NAME=($(grep ^audio /etc/group | cut -d: -f4 | tr "," " "))
I think it is not wise to run it from rc.conf because I make a new /<ramdrive>/tmp before something is done with it.
But I will see if it is possible; indeed neater.
Jan
Last edited by Lontronics (2007-04-16 19:58:01)
Offline
Pages: 1