1The scsi-idle package contains small programs to start and stop SCSI disks 2and a daemon that spins down drives when idle. You must apply the supplied 3kernel patch in order to add drive spin-up functionality. NB: scsi-idle will 4currently only spin down 1 scsi disk at a time. please feel free to patch! 5 6To install: 71. obtain kernel and untar in /usr/src 8 92. apply the kernel patch 10$ cd /usr/src/linux-2.4.23 11$ patch -p1 < scsi-idle-2.4.23.patch 12 133. install new kernel (read README from kernel) and reboot using it 14 154. run "make" to create scsi-idle utilities 16$ cd ~/scsi-idle-2.4.23 17$ make 18 195. run "make install" as root 20# cd ~/scsi-idle-2.4.23 21# make install 22 23To use: 24To immediately stop scsi drive /dev/sda: 25# /usr/local/sbin/scsi-stop /dev/sda 26 27To immediately start scsi drive /dev/sda: 28# /usr/local/sbin/scsi-start /dev/sda 29 30To automatically stop scsi drive /dev/sda after 30 minutes of inactivity: 31# /usr/local/sbin/scsi-idle /dev/sda 1800 32This loads the scsi-idle daemon which monitors drive's idle time and stops the 33drive accordingly. On access, the drive spins back up, and the daemon will 34notice this and continue monitoring. 35 36Just place the line to start the daemon in your init scripts. 37 38Read the rest of this README for some more hints with scsi-idle... 39 40I do not know of a patch for linux kernel 2.6. I will work on this when I 41get a chance.. 42 43Email me (Daniel Sterling) at dan@lost-habit.com if you have something to 44say. Patches welcome :) 45 46December 2003: 47 48Thanks to Dirk Jagdmann ( doj at cubic org ) for fixing up the Makefile and 49includes. 50 51Updated against stock 2.4.23. 52 53After a long hiatus, my email works again. If you tried to email me while it 54was out, I apologize. Try again if you like. All emails welcome. 55 56August 2002: 57 58Updated the patch for stock 2.4.19 (this was trivial). 59 60Commented out logging of spin-down, as this will spin the drive back up 61as your log file is written to! 62 63Gernot Zander had changed the scsi-idle daemon to send SCSI_STOP only 64once, ever. Unfortunately, this meant if the drive spun back up, the daemon 65wouldn't spin it back down again. I added a line so now the daemon notices 66if the drive has spun back up, and will spin it back down again after the 67timeout (as one would expect). 68 69I am using this to spin down my main drive, mounted on /. It seems to work 70alright for me. In order for the drive to sit mostly idle: 71I told syslogd not to write -- MARK -- (syslogd -m 0) 72crond only runs jobs once per day (for locate etc) 73no atd 74a tmpfs for dnetc's buffers and ntpd's drift file (copy to tmpfs on startup, 75and from it to disk daily and on shutdown) 76 77Note that smbfs likes to access the local disk, so if you have a program 78running on a smbfs mounted drive, your local disk might not sit idle. 79 80Note that this still is a "dirty hack", so use it at your own risk. It works 81for me. 82 83Let me know if it works, or doesn't, for you, or if you have suggestions or 84improvements. 85 86Daniel Sterling (dan@lost-habit.com) 87 88********************************************************************* 89Changed the patch to work with 2.4.18. Because the kernel's scsi 90structure has changed a lot, the old concept of starting the disk 91doesn't work anymore. To start the disk sd_init_onedisk is called 92instead, which re-reads the sector size, capacity and so on, too, 93but this shouldn't hurt. The SCSI command, which caused the 94access, is saved during the init. 95Instead of running into the NOT READY error and spinning up the 96drive then, the state of the drive is saved, so the spinup is 97done _before_ any other command is sent to the drive. 98Added logging output of up and down. 99Changed the scsi-idle daemon not to send the stop command 100again and again, but only once, if the idle time is exceeded. 101 102WARNING: This is something like a dirty hack. I'm far away 103of understanding all the SCSI stuff in the kernel source, I just 104looked for a place to drop this in, I don't know if there are 105side effects. Don't blame me if it causes data lost or crashes! 106 107I don't recommand it at devices the system itself is running 108at. I use it for a drive where I keep archive files (and there 109is a backup of it), and to spin down a drive with windows, 110if I run linux on this machine. This works fine at least for me. 111 112Tell me if you have problems or improvements. 113 114Gernot Zander <hifi at scorpio dot in-berlin de> 2002-07-31 115------------------------------------------------------------------------------- 116Changed the kernel patch so it would work with the 2.2.10 kernel. Also had to 117fix the user space programs to work with the new kernel includes. 118scsi-start/scsi-stop is now a single program that looks at its name to see 119what effect it should have. 120 121Trent Piepho <xyzzy@speakeasy.org> 122------------------------------------------------------------------------------- 123 124I patched this so it would apply to the 2.0.36 kernel. I also made two 125programs called 'scsi-start' and 'scsi-stop' which will start/stop a SCSI 126device. You don't need to apply the patch to use these programs. The patch 127is needed if you want to use the idle timeout program, scsi-idle, or if you 128want your drives to spin up automatically when accessed. 129 130Note that the auto spin up part of the patch doesn't work so well. If you 131access a spun down drive directly via the device file, e.g "cat /dev/sda1" or 132"mount /dev/sdb2" you might end up hanging the SCSI bus and have to reset! 133 134Trent Piepho <xyzzy@u.washington.edu> 135------------------------------------------------------------------------------- 136 137I attempted to get a hold of the originator of this patch a while back, 138but was completely unsuccessful, so here's my update. 139 140I've simply updated this patch so it can be easily be applied to 141kernel 2.0.30 source. I've not tested it on any other kernel versions and 142make no guarantees. I've had a bit of trouble with one of my drives, 143a Seagate ST51080N. It won't spin back up after being spun down. I have 144no idea why this is and probably won't look into it, since it's 145not a very noisy drive. 146 147Below is the original README file contents. 148 149Matthew Jachimstal 150jachim@jachsys.resnet.mtu.edu 151 152------------------------------------------------------------------------ 153Original README: 154---------------- 155 156 157`scsi-idle' is another attempt to spin down SCSI-disks after a period 158of inactivity. Some people have had trouble with my earlier patch, so 159I'm trying to to things differently this time. 160 161scsi-idle-x.y.z.patch is the kernel patch, where x.y.z is the kernel 162version it was made for. To apply the patch, cd to /usr/src and type: 163 164$ patch -p <scsi-idle.x.y.z.patch 165 166scsi-idle.c is a small user-level program which decides when to spin 167down disks, compile it with: 168 169$ gcc -o scsi-idle scsi-idle.c 170 171When invoked with only one paramer -- a device name -- scsi-idle shows 172how long the disk has been idle: 173 174$ scsi-idle /dev/sda 175/dev/sda has been idle for 78 seconds 176 177When invoked with two parameters, a device name and a timeout, 178scsi-idle does one of two things. A timeout of zero will spin down 179the disk immediately, anything else will place the program in the 180background, where it will monitor the disk and spin it down when it 181has been idle for timeout seconds. 182 183$ scsi-idle /dev/sda 0 184[the disk will hopefully spin down] 185$ scsi-idle /dev/sda 300 186[starts scsi-idle in the background and spins down the disk after 5 minutes] 187 188Any comments or bugreports are very welcome. Have fun! 189 190 /Christer (wingel@ctrl-c.liu.se) 191 192DISCLAIMER: This stuff works for me, but I can't give you any 193guarantees. If it breaks something, it's not my fault. 194 195Micro-FAQ: 196 1971) The disk keeps spinning up all the time 198 199 If you're using scsi-idle on your root disk, it's probably 200 spinning up all the time. This is because `crond' runs `atrun' as 201 a cron job every 10 minutes, and for each cron job, `crond' writes 202 a temporary file which is saved to disk. Making /tmp a ram-disk 203 will probably cure this problem. If you can survive without `at', 204 just run `crontab -e' as root and comment out the line with 205 `atrun' in it. If you can live without `crond' altogheter, feel 206 free to comment out the line which starts it in `/etc/rc.d/rc.M' 207 (at least, this is where you find it on Slackware system). 208 2092) The disk still spins up but not as often 210 211 There are quite a few programs which access the disk every now and 212 then, `crond' does some periodic housekeeping once every hour which 213 might spin up the disk, `sendmail' might also be a culprit. Other 214 than that, if you're sitting on a busy network, broadcasts, bad 215 network packets and whatnot can cause `syslogd' to make an entry in 216 the /var/log/messages-file which (of course) will make the disk 217 spin up again. If you have a system which is short on memory, 218 random events (such as network activity, timer interrupts or the 219 phase of the moon) might cause a program to get swapped in which 220 will (surprise) start the disk. Since Linux is a multitasking, 221 multiuser system, there really is no way that you can win, the disk 222 will spin up every now and then. 223 2243) What use is it then? 225 226 Well, it's perfect if you have a new, quiet and power-efficient 227 SCSI or IDE disk as your root disk and have some old noisy monsters 228 for FTP, storage, or backup purposes. Personally, I have a DEC 229 RZ25 (not all that new or quiet, but the newest one I have) for my 230 root and /usr partitions, a Fujitsu full height 5"25 for my /home 231 partition and an old Maxtor disk which sounds like jet engine when 232 running. My root disk runs continuously, the home-disk spins down 233 after 30 minutes and the FTP-disk spins down after 3 minutes. Then 234 there are all those disks that I connect externally every now that 235 tend to be a bit on the noisy side too. 236 2374) How is it different from the old scsi-idle (1.2.x) stuff? 238 (not really interesting but some people were wondering) 239 240 The main changes are that I've moved the `stop-disks' functionality 241 to a user process and implemented a new SCSI-ioctl to stop or start 242 a SCSI-unit immediately (this works for any SCSI-device). This 243 way, it's much easier to change the behaviour of the idle- 244 algorithms since I don't have to recompile the kernel and reboot 245 each time. The functions which restarts disks has also undergone 246 major changes. Most importantly, it has been changed to check the 247 return status from the drive and if the drive reports "NOT READY", 248 the function tries to restart it. This way, disks which have spun 249 down for any reason are automatically restarted. I have an external 250 disk with a flakey power supply, and quite naturally this disk 251 doesn't spin up on power up; the old version just set a flag when 252 a disk was spun down and got confused when a disk which was 253 supposed to be running wasn't. 254 255