disklog - using a Linux ramdisk to monitor spindown/active state of a hard disk

Jim Jackson <jj@franjam.org.uk>


This directory contains some info for creating ram disks and populating them with set of utilities to do things without the need for a hard disk.

The idea is to setup a "root" file system at mount point, sufficiently populated so that a chroot to the mount point of the file system can execute the wanted program/script/etc.

This usually means getting lib's, bin's, dev's and enough of /etc so that the hard disk is never touched. See below for more hints.

I use this so that I can run things over long periods with the hard disk spundown in power saving mode, but monitoring programs etc can continue to run.

This document can be found at http://www.franjam.org.uk/linux/disklog.html


Down load the gzipped tarball from http://www.franjam.org.uk/linux/ramdisks.tgz which contains

A Tool: mkramdisk

mkramdisk -d device -t filetype mountpoint archive

make a file system of type "filetype" (default minix) on device "device" (default /dev/ram) and mount it on "mountpoint", optionally installing files from the compressed tar "archive".



contains enough to run a script to monitor the active/standby state of a hard disk setup with a spindown timeout.


    ./lib/                where libraries go
    ./lib/ld-linux.so.2   most utilities need some version of these 2 libs
    ./lib/libc.so.6       there maybe smaller versions to cut down size
    ./etc/                odd config files might need to go here
    ./bin/                where most utils go
    ./bin/ash             the small footprint shell for scripting
    ./bin/date            *** without timezone stuff things are in UTC/GMT ***
    ./bin/watchdisk       the script that checks spin down state of drive
    ./bin/sh              soft link to ash
    ./sbin/               system binaries - could be a hard link to bin
    ./log/                directory where output from watch disk goes
    ./dev/                various devices that are needed

To run this, copy the mkramdisk script and the tar archive into a directory and ....

 % ./mkramdisk /mnt disklog.tgz
 % chroot /mnt bin/watchdisk &

This will periodically check the state, active or spindown, of the disk /dev/hda (edit to watch a different disk), and it will log the times when the state changes. The log file is /mnt/log/disklog, when mounted as above.

Hints on setting up and using ramdisks

After you have made and mounted your disk, you need to decide what to populate it with. You will know what programs you want to run, find out where these are using the "whereis" or "which" programs, and then make subdirectories under the mount point to match and copy the files across, e.g.

  % which ls
  % cd /mnt
  % mkdir bin
  % cp /bin/ls bin

Next figure out which libraries your programs need using the "ldd" command, and make the subdirectories required and copy across the libs, e.g.

 % ldd bin/ls
        libc.so.6 => /lib/libc.so.6 (0x40016000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
 % mkdir lib
 % cp /lib/libc.so.6 lib
 % cp /lib/ld-linux.so.2 lib

Copy across any scripts, remember most systems have a link from /bin/sh to the "sh" variant the system uses, e.g. bash. You should do the same if you are using a shell. "ash" is a useful small shell for scripting. Ramdisks are usually small, 4Mb by default, so you have to be careful about not filling them up. They also eat into your ram, so if the program you run needs significant amounts of memory you will have to watch total memory usage carefully - you can't swap if you are running without a hard disk.

You could now check that you programs run by running chroot to execute them. e.g.

 % cd /mnt
 % chroot /mnt bin/ls -l /
 total 6
 drwxr-xr-x    2 0        0             352 Apr 13 21:53 bin
 drwxr-xr-x    3 0        0             128 Apr 13 21:32 dev
 drwxr-xr-x    2 0        0              96 Apr 13 21:25 etc
 drwxr-xr-x    2 0        0             128 Apr 13 21:20 lib

This shows the restricted view that ls has when run.

Once you have checked that your program will run ok, has all the configs files, libs, etc it needs then it is good to archive your setup so it can be reloaded after a powerdown or reboot.

 % cd /mnt
 % tar cfz /root/ramdisks/testram.tar.gz .

Reloading after unmounting the ramdisk, or power cycling or rebooting is now easily done with the mkramdisk command....

 % cd /root/ramdisks
 % ./mkramdisk /mnt testram.tar.gz

HomePage http://www.franjam.org.uk

This document was generated using AFT v5.095