Sunday, July 20, 2014

Avoid Spinning Down Hard Disks During Restarts – FatDog64 Full Installation

FatDog64 is an excellent OS with an incredible boot speed (< 6 Seconds) and very light on resources (<95MB RAM usage on startup). You can achieve this using the Full Installation Option of FatDog64 described here.

Everything went perfect after the full install, except one. FatDog6 seems to spin down the hard disks even during a restart. But we would expect spinning down the hard disks only during a shutdown. For testing new updates and procedures, we often want to restart the FatDog64 every now and then (Some time 15+ time a day!).

Frequent spin down and spin up of hard disks have the following disadvantages.

1. More importantly, It can easily shorten the life span of the drive.

2. The restart will be slower, as the BIOS has to wait for the hard disks to be spin up and available during boot.

Note: That’s why we’ve opted to, not to spin down disks even in power save or sleep mode as well. You can save a bit of power on a cost of your hard drive.

So the solution will be, during the restart mode, FatDog64 should only unmount the drives. And during an actual shutdown, it should unmount and spin down the disks. Unfortunately FatDog64’ does not support this setup, as it may not be able to distinguish between a Restart/Shutdown mode.

The reason is, Fatdog64 uses busybox init, and busybox init has no state (or "runlevel" like a full-fledged sysv init or openrc). As far as busybox init is concerned, "shutdown" and "reboot" is the same thing and they behave identically. This is clearly mentioned in this discussion forum. Thanks to ‘James Bond’ for clarifying this.

So the solution is not rely on the FatDog64’s native Restart/Shutdown option, but customize it to our own, to distinguish the Restart/Shutdown mode. The custom solution is defined as below.

Solution: We need to update the ‘/etc/rc.d/rc.cleanup’ script, so that ‘Spin Down’ operation should only be invoked during a shutdown only. But there is some way to let this script know, what’s the mode for which it has been called for. Either for shutdown or for a restart! For this we need to write two separate script files. One for shutdown and one for restart. In our custom ‘Restart’ script, we will create a temporary file named ‘Restart.txt’ in ‘/tmp’ location and then invoke the reboot operation. Then we will update ‘rc.cleanup’ script in such a way that, if ‘/tmp/Restart.txt’ exists, then it will skip the ‘Spin Down Disks’ operation. Then in our custom ‘Shutdown’ script, we will delete the temporary file ‘/tmp/Restart.txt’, if it exists and then will invoke the shutdown operation. So in ‘rc.cleanup’, the script will unable to find ‘/tmp/Restart.txt’ file and hence it will ‘Spin Down Disks’ as usual.

Now for a restart and shutdown, we will only use these custom ‘Shutdown’ and ‘Restart’ scripts files. We will not use the normal Shutdown and Restart menu items in FatDog64.

Ok lets implement the solution now.

1. Create ‘Restart.sh’ script

Create the script on the desktop and make it executable.

image

Put the below as the only script content.

image

2. Create ‘Shutdown.sh’ script

Create the script on the desktop and make it executable

image

Put the below as the only script content.

image

3. Update ‘rc.cleanup’ script

Open ‘/etc/rc.d/rc.cleanup’ in your favorite editor.

image

At the very top of the file (See below) just add the below script code marked in green. This code is basically checking for the existence of ‘/tmp/Restart.txt” file and set a boolean flag to 1 (if the file exists) or 0 (if the file does not exists). Remember, we’ve created this temp file with in our custom ‘Restart.sh’ script file, and the restart operation in turn invoked ‘rc.cleanup’.

image

Scroll to the bottom position of the ‘rc.cleanup’ file, that contains the ‘Spin Down Disks’ section. Below we’re changing the console message properly, based on the current mode (shutdown/restart) it has called for. If you don’t care about the message display, you don’t have to make this change!

image

NB: Now the most important change! Put the ‘Spin Down Disks’ section, inside an ‘if’ block that will only trigger, during a shutdown operation. During restart ‘if’ block condition will be false, and ‘Spin Down’ wont happen.

i.e Change the below line

$SDPARM -C stop /dev/$dev > /dev/null)

to

#Change - Checking Restart Mode - Start

#$SDPARM -C stop /dev/$dev > /dev/null

if [ $restartFlg -ne 1 ]

then

         $SDPARM -C stop /dev/$dev > /dev/null

fi

#Change - Checking Restart Mode - End

image

4. Now on, Only rely on the custom ‘Restart.sh’ and ‘Shutdown.sh’ scripts for Restart/Shutdown

Now if you would like to shutdown the machine, click on ‘Shutdown.sh’. For restart, click on ‘Restart.sh’. Do not opt the FatDog64’s native menu entries.

5. Download the script files

If you’re having difficulty editing the scripts files on your own, We’ve shared it here. Just download and put them under proper locations.

No comments:

Post a Comment