CD-eject after shutdown.


Forum: Other Help Topics
Topic: CD-eject after shutdown.
started by: Zucca

Posted by Zucca on June 12 2006,08:19
Because I'm lazy...
Somebody please tell me how to tune DSL NOT to eject cd on shutdown or reboot. I think I should edit some shutdown script. But it's not the /opt/powerdown.sh.
It would be nice to be able to reboot my DSL server remotely...

And Is it possible to make DSL to be loaded into RAM by default?

Posted by ZoOp on June 12 2006,08:58
Hi,
please, just post your first question on the appropriate forum:

< http://www.damnsmalllinux.org/dsl-n/f/ >

Second question: add toram in your boot line and you will have DSL running in your ram. With DSL, you have to have at least 128 MB in order to run it toram. With DSL-N probably 256MB.

yours
z

Posted by Zucca on June 12 2006,09:29
:D

You got me wrong. ;)

I want my system not to eject my CD on reboot / shutdown. ;)

And yes. I know toram boot command. But how to make it default?
If I boot remotely I would like it to load into ram automatically/by default.

Posted by ZoOp on June 12 2006,10:44
Hi,
sorry for the misunderstanding :)

in order to do what you want at best, I would really consider a frugal install with grub. You can then start DSL remotly, you don't need a CD and you can edit grub in order to have DSL toram at each boot.

Otherwise, I think it is impossible to do what you say with the live-CD without remastering (a lot of threads in the forum related to the script mkmydsl) it in order to profile the boot line as you want to. In my machine, DSL 2.4 don't eject the CD when I shut down or reboot my machine, so you maybe can try it.

yours
z

Posted by Zucca on June 12 2006,12:03
The eject problem occurs only when DSL isn't loasded to RAM...
Well. I'll try to find solution to this.

And why I'd like to use Live CD wihtout any kind of install is beacause I'm currently 'developing' nice DSL server based on protability. Only thing you need is DSL cd and usb memory stick with server settings.
Well... I could burn my own server DSL CD, but then it would lack all the features future DSL relases could offer...

Loading automatically to RAM isn't that neccessary. I just have to find that script that ejects cd.

Posted by Zucca on June 13 2006,03:38
Solved!

I didn't get any real answers so I strugled trough DSL system and stumbled into /etc/init.d/knoppix-reboot.
Ok that's a symlink. You must copy the real one and replace the symlink. Then add it to your filetool.lst.
Then edit it:

Near end you'll see line like this:
Code Sample
NOEJECT=""

Replace it with:
Code Sample
NOEJECT="yes"


That's it. It works just fine. :cool:
Note that on halt/shutdown it still ejects your CD if you ran DSL from CD without toram boot option.
For shutdown/halt tuning, tweak /etc/init.d/knoppix-halt file. ;-)

Posted by Zucca on June 13 2006,14:01
Oh. Seems like it's not gonna work as I believed... ;(
I have to investigate this again.

Posted by Zucca on June 13 2006,14:15
A HA! :D

You need to edit few lines at the very end:
Quote
if [ -z "$INSTALLED" ]; then
 # echo -n "${CYAN}Wait for CD to eject, then remove CD, close cdrom drive and press enter.${NORMAL}"
 echo "${CYAN}No CD eject when rebooting.${NORMAL}"
 sleep 5
fi


Those are just example lines, but now It it SHOULD work.

*boot*

Posted by ZoOp on June 13 2006,15:00
:)

cool!! thanks a lot

yours
z

Posted by mikshaw on June 13 2006,19:43
With a frugal/poorman's install, the wait message appears unless you use the "dsl frugal" boot option.  I have never tried it with a live cd, but i think it's worth a test...it would save having to add another file to a backup.

A possible issue with this is that DSL may try to remount the cd read-write, which would fail and probably print an error mesage.

Posted by Zucca on June 14 2006,02:19
The final line in knoppix-reboot seems to execute some short of command that finalizes the reboot
Code Sample
exec $FINALCMD $options 2>/dev/null

I have spent now 2 hours of time to figure out what that line might execute...
One thing is clear: it executes halt or reboot with some arguments. But I can't find the wait command that waits user to press any key.
CD-eject problem is now solved but this is not. ;(

Posted by mikshaw on June 14 2006,03:27
Code Sample
case "$CMDLINE" in *noeject*) NOEJECT="yes";;; esac

This apparently means that you don't need to edit the file.  Try adding "noeject" to your boot options.

$FINALCMD is either /etc/init or /KNOPPIX/etc/init, depending on your setup.  This is likely a copy or symlink of /sbin/init. The options are set around line 36 (case "$0" in...), and are dependent on whether you halt or reboot.  I don't know what those options do, though....they aren't listed in the man page, so i'm guessing the init in knoppix/dsl is a custom application.

Posted by Zucca on June 14 2006,06:41
I'll try that after I get home from work. ;)
I wonder if it needs appending '--'. Like this: reboot --noeject.

I don't wanna risk and try booting now.

Posted by mikshaw on June 14 2006,14:55
"noeject" in this situation is a boot option, as in something you add to your bootloader's config or enter at the "boot:" prompt in a live cd. It is not something that can be applied after the kernel has loaded.
Posted by Zucca on June 14 2006,17:49
Jeah. I just figured that out too... ;/
Now I'm at the point where's two choices to do:
Code Sample
case "$0" in
 *halt)
 exec $FINALCMD $options 2>/dev/null
 ;;
 *reboot)
 exec /sbin/shutdown -r now
 ;;
esac

That would be just what I'm looking for BUT, it says that there no /sbin/shutdown file at all. Ok it's because we have already unmounted filesystems. One thing I know is that /etc/ it left. Sooo... I must add a cp line somewhere...

Another way is to do shutdown -n (if I remember correctly) which will force reboot immediately. I wouldn't like to use that.

I've been getting "No more processes on this runlevel" even it is runlevel 6. And then it freezes there...
Maybe I'm missing some big point but doesn't it should reboot after there's no commands to execute on runlevel 6?

I'm thinking to rewrite whole script... But trying to avoid that to the last point.

Posted by Zucca on June 15 2006,17:59
Ok. finally I managed to bypass the "press any kay to continue" -phase.

Code Sample
#!/bin/sh
#/etc/init.d/knoppix-reboot

PATH=/sbin:/bin:/usr/bin:/usr/sbin
export PATH

exec >/dev/console 2>&1 </dev/console

NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
WHITE=""

stringinstring(){
 case "$2" in *$1*) return 0;; esac
 return 1
}

INSTALLED=""
TORAM=""
FRUGAL=""
[ -e /KNOPPIX/bin/ash ] || INSTALLED=yes

if [ -e /etc/sysconfig/toram ]; then
 INSTALLED=yes
 TORAM=yes
fi
if [ -e /etc/sysconfig/frugal ]; then
 INSTALLED=yes
 FRUGAL=yes
fi

case "$0" in
 *halt)
message="
${YELLOW}DSL halted.${NORMAL}"
command="halt"
options="-p -d -i -f"
;;
 *reboot)
message="${GREEN}Preparing for reboot...${NORMAL}"
command="reboot"
options="-r -d -i -f"
;;
 *)
echo "$0: call this script as \"halt\" or \"reboot\" please!"
exit 1
;;
esac

[ -n "$INSTALLED" ] || options="$options -n"

mysleep() {
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
do
usleep 75000
echo -n "$1.${NORMAL}"
done
echo ""
}

if [ -x /opt/powerdown.sh ]; then
 /opt/powerdown.sh
fi

echo "0" > /proc/sys/kernel/printk

if pidof cardmgr >/dev/null 2>&1; then
echo -n "${BLUE}Shutting down PCMCIA devices...${NORMAL}"
cardctl eject >/dev/null 2>&1
sleep 2
echo ""
fi

killall5 -15
sleep 2
echo -n "${BLUE}Sent all processes the TERM signal...${NORMAL}"
mysleep "$BLUE"

killall5 -9
sleep 2
echo -n "${RED}Sent all processes the KILL signal...${NORMAL}"
mysleep "$RED"

NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2>/dev/null)"
if [ -n "$NETMOUNTS" ]; then
echo "${BLUE}Unmounting network filesystems.${NORMAL}"
umount -t nfs -arvf 2>/dev/null
fi

NETDEVICES="$(awk -F: '/eth.:/{print $1}' /proc/net/dev 2>/dev/null)"
if [ -n "$NETDEVICES" ]; then
pidof pump >/dev/null 2>&1 && { pump -k; sleep 2; }
echo -n "${BLUE}Shutting down network device${NORMAL}"
for n in $NETDEVICES; do
echo -n " ${MAGENTA}$n${NORMAL}"
ifconfig $n down
done
echo ""
fi

NOPROMPT=""
read CMDLINE <<EOT
$(cat /proc/cmdline 2>/dev/null)
EOT
case "$CMDLINE" in *noprompt*) NOPROMPT="yes";;; esac
FINALCMD="/sbin/$command"
if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
[ -x /etc/init ] || cp -p /sbin/init /etc/
[ -x /etc/init ] && FINALCMD="/etc/init"
fi

if [ -n "$FRUGAL" ]; then
  stringinstring "KNOPPIX" "$FINALCMD" || FINALCMD="/KNOPPIX$FINALCMD"
fi
if [ -n "$TORAM" ]; then
  stringinstring "KNOPPIX" "$FINALCMD" || FINALCMD="/KNOPPIX$FINALCMD"
fi

swapoff -a >/dev/null 2>&1

echo "${BLUE}Unmounting file systems.${NORMAL}"
NOEJECT="yes"
read CMDLINE <<EOT
$(cat /proc/cmdline 2>/dev/null)
EOT
case "$CMDLINE" in *noeject*) NOEJECT="yes";;; esac
for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
if [ -z "$NOEJECT" ]; then
for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
fi


cd /

umount -arvf 2>/dev/null
if [ "$?" != "0" ]; then
for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
umount -arf 2>/dev/null
fi

rmmod -a >/dev/null 2>&1

[ -n "$INSTALLED" ] && mount -o remount,ro / 2>/dev/null

echo "$message" >/dev/console

if [ -z "$INSTALLED" ]; then
 # echo -n "${CYAN}Wait for CD to eject, then remove CD, close cdrom drive and press enter.${NORMAL}"
 echo "${CYAN}No CD eject when rebooting.${NORMAL}"
fi

case "$0" in
 *halt)
 exec $FINALCMD $options 2>/dev/null
 ;;
 *reboot)
 echo "Executing \"${RED}$FINALCMD $options${NORMAL}\"."
 $FINALCMD $options
 ;;
esac


I don't know what 2>/dev/null does, but I tested and leaving it was the solution...
Ok It's not the best wat to bypass it but it worked on my Compac Armada E500.

It tries to unmount cd two times. At the third time it gives up and tells you to reset. My laptop reseted automatically. There might be cases where you must do it manually.

Anyone care to test?

Posted by mikshaw on June 15 2006,20:13
2>/dev/null nullifies any error messages sent by the preceding command.  It's done here simply to give the user a false sense of calm and to confuse him when something goes wrong =o).

A more suitable use for it would be when setting a variable from the output of a command, when the only time you want that variable to have a value is if the command succeeds.

Posted by Zucca on June 19 2006,02:29
Ok. Then it must be the exec command...
Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.