Monday, September 29, 2008

Emulating (1st ver.) ramlog on an eeePC with default Xandros

("save log files" - 1st version) ("save log folders" - 2nd version)

eeePCs use solid state disks (SSD). I don't know if the lifespan of SSDs is a real issue for the average user, but I wanted to reduce writings anyway. This article pointed me (paragraph "Which file system should you use?") to the redirection of logs to /dev/null, but I didn't find any instruction on how to make it once and for all (I don't like running scripts every time an application is added or removed). This program (ramlog) pointed me to redirect logs to ram.
I tried installing ramlog on my eeePC 900, but without success.
I tried to mount /var/log on a ramdisk in fstab, but it didn't work because it results in an empty folder, while many programs need their own subfolder, otherwise they don't go (like kismet, for example).

So I tried my way:

  • the eeePC has a /tmp folder mounted in ram on tmpsf;

  • I only need to make a subfolder /tmp/log and to link /var/log there;

  • copy current logs in /tmp/log at boot-up and save new logs from there to somewhere on the disk at shutdown.


My steps were:

  1. rename /var/log as /var/log-save;

  2. make a symbolic link: /var/log points to /var/log-save (in this manner, programs work as usual until the scripts are completed and running);

  3. in /usr/local/sbin create a simple script named "log-up" to be called at startup in order to:


    • create directory /tmp/log;
    • copy content of /var/log-save to /tmp/log;

    • remove link /var/log (which is pointing to /var/log-save);

    • make new link /var/log, pointing now to /tmp/log;



    #!/bin/bash
    mkdir /tmp/log
    cp -rp /var/log-save/* /tmp/log
    unlink /var/log
    ln -s /tmp/log /var/log

  4. in /usr/local/sbin create a simple script named "log-down", to be called at shutdown/reboot in order to:


    • copy only newer or modified logs in /tmp/log back to /var/log-save;

    • remove link /var/log (which is pointing to /tmp/log);

    • make new link /var/log, pointing now to /var/log-save;



    #!/bin/bash
    cp -rpu /tmp/log/* /var/log-save
    unlink /var/log
    ln -s /var/log-save /var/log

  5. in /usr/bin, edit "startsimple.sh" by adding at the beginning a call to "log-up" (bold lines):


  6. #!/bin/sh

    # change logging dir
    sudo /usr/local/sbin/log-up


    sudo /usr/bin/sessreg -d -l :0.0 -u /var/run/utmp user
    xhost + si:localuser:root # Allow local user root only to access the display
    ...

  7. in /usr/bin, edit "startfull.sh" by adding at the beginning a call to "log-up" (bold lines):


  8. #!/bin/sh

    # change logging dir
    sudo /usr/local/sbin/log-up


    touch /home/user/.kdesession #changed
    killall xinit

  9. in /sbin, edit "fastshutdown.sh" by adding a call to "log-down" (bold lines):


  10. #!/bin/sh

    if [ "$1" = "--ask" ]
    then
    zenity --question && sudo $0
    exit $?
    fi

    [ `id -u` = "0" ] || echo "Must be root."

    # revert logging dir
    /usr/local/sbin/log-down


    /usr/bin/killall --wait usbstorageapplet

    /bin/kill -USR2 1


  11. in /sbin, edit "fastreboot.sh" by adding a call to "log-down" (bold lines):


  12. #!/bin/sh

    if [ "$1" = "--ask" ]
    then
    zenity --question && sudo $0
    exit $?
    fi

    [ `id -u` = "0" ] || echo "Must be root."

    #revert logging dir
    /usr/local/sbin/log-down


    /usr/bin/killall --wait usbstorageapplet

    /bin/kill -USR1 1

  13. reboot.



If you don't care about keeping the the full log history, because you only need logs within a session, you may opt for similar scripts which only save the directory structure (needed by some program installation) but not the files (not needed from session to session).