Showing posts with label log. Show all posts
Showing posts with label log. Show all posts

Monday, September 29, 2008

Emulating (2nd 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.
And then made a variant. It is useful if you don't need to keep the logs from the old sessions: only logs of the current session are written to ram and then discarded at shutdown.



My steps were:

  1. make a new folder /var/log-save-dir;

  2. copy only the directory structure of /var/log to /var/log-save-dir:


  3. prompt/> cd /var/log-save-dir
    prompt/> (cd /var/log; find -type d ! -name .) | xargs mkdir

  4. delete (or rename for a spare copy) /var/log;
  5. make a symbolic link: /var/log points to /var/log-save-dir (in this manner, programs work as usual until the scripts are completed and running);
  6. in /usr/local/sbin create a simple script named "log-up" to be called at startup in order to:


    • create a directory /tmp/log;

    • move content of /var/log-save-dir to /tmp/log;

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

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



    #!/bin/bash
    mkdir /tmp/log
    mv /var/log-save-dir/* /tmp/log
    unlink /var/log
    ln -s /tmp/log /var/log

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


    • copy all folders only from /tmp/log back to /var/log-save-dir (just in case you installed some program which requires its own log folder);



    #!/bin/bash
    cd /var/log-save-dir
    (cd /tmp/log; find -type d ! -name .) | xargs mkdir
    cd /
    unlink /var/log
    ln -s /var/log-save-dir /var/log

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


  9. #!/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
    ...

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


  11. #!/bin/sh

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


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

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


  13. #!/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

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


  15. #!/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

  16. reboot.



If you care about keeping the full log history, you may opt for similar scripts which save all the logs up to ram and down to disk, but be prepared to an increasing bootup and shutdown time.

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).