Shutdown Wakeup

From MythTV Official Wiki
Revision as of 09:18, 6 June 2006 by Awilkins (talk | contribs) (Compensated for grub bugs. Clarified need to mount /boot . Emphasised superiority of using grub-set-default and grub halt instead of a shutdown kernel. Advised caution with nvram-wakeup.)

Jump to: navigation, search

This is a basic tutorial on using the shutdown and wakeup features of MythTV as described here [1].

MythTV Shutdown / Wakeup How to

Warning this procedure worked for me, but it may hose your BIOS rendering your motherboard a poor excuse for a frisbee. I hold no responsibility

This assumes you are using a combined frontend/backend machine. Directions are FC2 specific, but should work for many distributions.

# apt-get update
# apt-get install nvram-wakeup
# /usr/sbin/guess-helper.sh
under Fedora Core 3 this might be called just /usr/sbin/guess-helper

Follow the instructions from the script, it will ask you to change the bios settings and reboot several times.

Run through rebooting your computer and creating the config file. The config file nvram-wakeup.conf will be found in the root home directory in the guess-directisa directory. Copy this file somewhere permanent and name it mymb.conf.

To test that you have nvram-wakeup working properly,

 # /usr/sbin/nvram-wakeup -A -C /path/to/mymb.conf -s $((`date +%s` + 10 * 60))
# reboot 

you may not need the -A, but that was the only way it worked for me Check the BIOS upon reboot that the values have been stored correctly. If not, search Google, or as a last resort email the project admin Sergei, he is very helpful.

Be VERY careful with nvram-wakeup. guess-helper incorrectly guessed my offsets, in particular my checksum offset. I only found out because I looked through the source code and found previous versions of my BIOS. The short story is that if your BIOS isn't recognised, check the sourcecode in nvram-wakeup-mb.c after using guess-helper - or get yourself a BIOS Saviour or similar first.

My MB requires a reboot for the wakeup to work properly. This requires a couple more steps. Myth will reboot the computer to a kernel that immediately shuts down the computer.

  • download the poweroff-kernel from the nvram-download page [2]
 $ tar jxvf reboot-2004.10.03.tar.bz2
# cp reboot-2004.10.03/[[bz Image]].2.4.20.poweroff /boot/
  • Now append the following lines to /boot/grub/grub.conf
Title [[Power Off]]
     savedefault --default=0
     root (hd0,1)
     kernel /[[bz Image]].2.4.20.poweroff root=/dev/none

Default should be the same as number as your default kernel listed in grub.conf (remember they are numbered 0,1,2...)

Another (much easier) way to configure grub to shutdown is to use the following lines (instead of the lines above):

Title [[Power Off]]
   savedefault 0
   cat /boot/grub/default
   halt

Edited : recent versions of grub have a bug which fails to flush buffers to disk before the halt command is executed. Reading the file grub uses to store the default data forces it to be flushed to disk.

At this point, all the pieces are in place. We just need to tell Myth what to do. $ mythtvsetup

  • Select General
  • Page through to the Shutdown / Wakeup Options
  • Uncheck Block shutdown before client connected
  • Tweak these as you like, but I used Idle Timeout: 180 | Max. wait for recording: 30 | Startup before rec.: 120
  • Wakeup time format: time_t
  • Set wakeuptime command: /usr/sbin/nvram-wakeup -A -C /path/to/mymb.conf -s $(($time + 300)) (again, you may not need the -A)
  • Server halt command: /usr/sbin/mythshutdown or if you do not require reboot shutdown -h now
  • Pre Shutdown check-command: exit 0

Now create the /usr/sbin/mythshutdown file in your favorite text editor.

 ### /usr/sbin/mythshutdown ###
echo "savedefault --default=1 --once quit" | grub
reboot

Default is whatever place your shutdown kernel is in grub.conf. Most likely 1 or 2 (dual-boot). Make it executable: # chmod 755 /usr/sbin/mythshutdown

The docs for grub recommend you now use the grub-set-default program which is far easier. In addition, many people have a setup where /boot is on a seperate partition and is not mounted in normal system operation for safety. If you don't mount it first, grub-set-default will just write the default option to /boot on your root partition instead. Which doesn't work.

Support for savedefault at the grub prompt has also been removed from recent builds (0.95 - 0.97) as the patch to include this support conflicts with the new location for storing the default (text in /boot/grub/default instead of a binary field in stage2).

#!/bin/bash
BOOT_PARTITION=/dev/hda1
POWEROFF_BOOTOPTION=2
if ! grep -q /boot /etc/mtab
  then mount $BOOT_PARTITION /boot
fi
grub-set-default $POWEROFF_BOOTOPTION
reboot

Finally, change /boot/grub/menu.lst to start from the saved menu entry by default, i.e., add

default saved

to the top of /boot/grub/menu.lst.


Now give it a try. Exit the frontend and wait to see what happens. After the idle time, it should reboot, then shutdown after the grub screen, and wakeup just in time for the next recording. Check the mailing list if you have any problems [3].

Next problem. If you have the frontend startup automatically, it will never shutdown without you manually quitting the frontend. I got around this by starting up the frontend by lirc.

  • Remove link to autostart frontend

$ rm ~/.kde/Autostart/mythfrontend

  • Autostart irexec

ln -s /usr/bin/irexec ~/.kde/Autostart/

  • Edit your ~/.lircrc file to include a button to startup the frontend I used the power button on my grey hauppauge
begin
prog = irexec
button = OFF
repeat = 0
config = /usr/bin/mythfrontend
end

Now when you want to use Myth, just power on the machine and hit the power button on your remote once KDE loads to fire up the frontend.

Good luck, please make additions and comments where necessary.