I love Knoppix, I really do, but there is one and only one thing that royally pisses me off about it: the X11 server crashes from time to time (from memory leaks, code pages getting corrupted, and other miscellaneous problems), and when that happens, instead of returning to init level 2 and a nice little bash prompt, the machine usually shuts down completely. Why? Because the startx script assumes that when the X11 server exits, the user meant for this to happen, and it simply falls through and goes into the shutdown sequence.

When the machine doesn't shut down on its own, it's because things have gotten hung. Same result, only I have to grit my teeth and rip the battery out of my laptop because the machine won't shut down no matter what else I do. The odd thing is, even though the power button doesn't work to shut the machine off, the disk-access light blips when I push it the first time, so something clearly happens.

Data? Forget it, there was absolutely no way for me to save it in either case. Yeah, I know about the "magic sysreq" and a few other tricks, nothing works. If the server died and fell through, it all shut down too fast to stop it. If the server hung, nothing could get me to a text console.

Well, I have come up with a way.

In /usr/bin/startx I replace the line:
Code:
 xinit $client $clientargs -- $server $display $serverargs
with
Code:
until test -f /var/lock/reallyshutdown ; do
    xinit $client $clientargs -- $server $display $serverargs
    bash
done
And in /etc/acpi/powerbtn.sh I add some scripting. Instead of:
Code:
 /sbin/shutdown -h now "Power button pressed"
I now have:
Code:
mount /mnt/sda1
mkdir /mnt/sda1/emergency-backup/
cp -r /home/knoppix/.mozilla /mnt/sda1/emergency-backup/
sync
cp -r /home/knoppix/Desktop /mnt/sda1/emergency-backup/
sync
umount /mnt/sda1
This saves the data that I want -- the stuff in my /home/knoppix/Desktop directory, and whatever browsing I've been doing -- off to the hard drive on my laptop. It's not a part of the disk I normally want to use (it's actually the Windows recovery partition for the drive, hah), but it works, and it's pretty much useless to me otherwise.

This got a live-fire test tonight when for no apparent reason, the X11 server suddenly croaked, probably due to a memory leak. The change to startx meant that the machine wouldn't exit out completely, but the machine was hung in graphics mode and so the X11 server wasn't restarting. I hoped like hell that I had run my script to modify the startx and powerbtn.sh scripts, and I pushed the power button. The disk light went on for a lot longer than usual. When I restarted the machine, all my data was saved.

If you use these changes, you'll obviously need to tailor them to however your machine is set up and what directories you save data in during a Knoppix session. Also, of course, it may or may not work depending on whether your power button has any effect after a crash. (A "real" power button will obviously just shut the machine off, but if you have a "soft" power button, which merely suggests to the OS that someone wants it to power down, as is the case on most modern machines, it might work.)