You are not logged in.
I recently built a system with an SSD. The usual recommendation is to mount /var on a hard disk partition, but instead I decided to make a little script that puts /var/log on tmpfs (assuming /tmp is mounted as tmpfs), and then copies the logs back to the SSD on shutdown. Of course there is the risk of losing the logs in a power failure, but I don't really care about them that much.
Copy to: /etc/rc.d/functions.d/mount_log
mount_log() {
mkdir -p /tmp/log
chmod 755 /tmp/log
mv -f /var/log/* /tmp/log/
rm -rf /var/log
ln -s /tmp/log /var/log
}
umount_log() {
if [ "`readlink /var/log`" == "/tmp/log" ]; then
rm -f /var/log
mv -f /tmp/log /var/
fi
}
add_hook sysinit_end mount_log
add_hook shutdown_preumount umount_log
I guess this could be extended for other directories that might get written to a lot - any ideas?
Offline
I made a lot of improvements and generalised the code. It now mounts a tmpfs instead of making symlinks in to /tmp. I came up with the name "nvtmpfs" meaning non-volatile tmpfs.
/etc/rc.d/functions.d/nvtmpfs
#!/bin/bash
NVTMPFS_DIR="/tmp/.nvtmpfs"
nvtmpfs_mount() {
if [ -e "$1" ]; then
if [ -z "`mount -t tmpfs | grep $1`" ]; then
mkdir -p "$NVTMPFS_DIR"
cp -r "$1"/* "$NVTMPFS_DIR/"
mount -t tmpfs -o noatime,mode=1755 tmpfs "$1"
mv -f "$NVTMPFS_DIR"/* "$1"
rm -rf "$NVTMPFS_DIR"
else
echo "nvtmpfs: $1 is already mounted"
fi
else
echo "nvtmpfs: $1 does not exist"
return 1
fi
}
nvtmpfs_umount() {
if [ -n "`mount -t tmpfs | grep $1`" ]; then
mkdir -p "$NVTMPFS_DIR"
mv -f "$1"/* "$NVTMPFS_DIR/"
umount "$1"
mv -f "$NVTMPFS_DIR"/* "$1"
rm -rf "$NVTMPFS_DIR"
else
echo "nvtmpfs: $1 is not mounted"
return 1
fi
}
nvtmpfs_startup() {
nvtmpfs_mount /var/log
nvtmpfs_mount /var/tmp
}
nvtmpfs_shutdown() {
nvtmpfs_umount /var/log
nvtmpfs_umount /var/tmp
}
add_hook sysinit_end nvtmpfs_startup
add_hook shutdown_preumount nvtmpfs_shutdown
Last edited by shaurz (2012-01-22 05:18:53)
Offline
New version using rsync
#!/bin/bash
NVTMPFS_DIR="/tmp/.nvtmpfs"
nvtmpfs_mount() {
if [ -e "$1" ]; then
if [ -z "`mount -t tmpfs | grep $1`" ]; then
mkdir -p "$NVTMPFS_DIR"
rsync -ur --delete "$1/" "$NVTMPFS_DIR/"
mount -t tmpfs -o noatime,mode=1755 tmpfs "$1"
rsync -ur --delete "$NVTMPFS_DIR/" "$1/"
rm -rf "$NVTMPFS_DIR"
else
echo "nvtmpfs: $1 is already mounted"
fi
else
echo "nvtmpfs: $1 does not exist"
return 1
fi
}
nvtmpfs_umount() {
if [ -n "`mount -t tmpfs | grep $1`" ]; then
mkdir -p "$NVTMPFS_DIR"
rsync -ur --delete "$1/" "$NVTMPFS_DIR/"
umount "$1"
rsync -ur --delete "$NVTMPFS_DIR/" "$1/"
rm -rf "$NVTMPFS_DIR"
else
echo "nvtmpfs: $1 not mounted"
return 1
fi
}
nvtmpfs_startup() {
nvtmpfs_mount /var/log
nvtmpfs_mount /var/tmp
}
nvtmpfs_shutdown() {
nvtmpfs_umount /var/log
nvtmpfs_umount /var/tmp
}
add_hook sysinit_end nvtmpfs_startup
add_hook shutdown_preumount nvtmpfs_shutdown
Offline
why don't you just make /var/log an on-disk filesystem like ext4 with a large commit interval setting?
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Because I didn't know you could do that...
Offline
why don't you just make /var/log an on-disk filesystem like ext4 with a large commit interval setting?
Although this would reduce writes against the SSD, wouldn't it be missing the increased read performance of a tmpfs?
(I'm genuinely curious as I'm considering doing something like this myself. Thanks everyone so far for the info.)
PS- profile-sync-daemon may also be of interest to some.
Offline
There probably isn't any real difference. This scripts needs to read the whole directory from disk on startup anyway.
Offline
I came up with the same idea, but with a slight difference. I created a loopback image to store the data between boots. Thus, I have a dedicated section of my SSD for storing my /var/log that doesn't get written to very often. I wrote up my solution at http://jrfom.com/2012/05/09/prolonging- … ng-writes/
Offline
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
Very nice. I was unaware of anyone else's work in this regard when I started. I like your daemon, but it doesn't quite fit my personal requirements. But it's good to know it's there if I need it for another situation.
Offline