HOWTO use shutdown & resume with Avicap

back to Avicap Index

docu by: Alexander Rawass (
if anyone can write a better documentation - please do it and tell me

this howto describes how you can shutdown,poweroff,resume & reboot your linux with Avicap, to have a video recording tool with a programmable timer, that allows your computer to be powered-off in-between recordings

Step 1: Check your BIOS

Most modern BIOS have an advanced power management section, which allows you not only to configure sleep/suspend modes, but also on which signals your computer should poweron from 'soft-off'

Goto to the BIOS, to the advanced power management section
Turn on advanced power management on, if you haven't enabled it before, you might want to set most entries to 'disabled'.

For awakening after a soft-off, we need to enable
'RTC Alarm Resume from Soft off'

Below this, you should be able to set the date and the time to wakeup.

If you don't find such entries in your BIOS, well, it won't work for you,sorry.

Step 2: Install nvram-wakeup

Download the latest version of nvram-wakeup.

nvram-wakeup is a tool to set the RTC alarm time in your Bios - WARNING, this may be dangerous, be careful what you do!

compile nvram-wakeup.

Read the README file. Read it again.

Read the README.mb file. Read it twice again!

Now you can be lucky, then your motherboard/bios will be supported by nvram-wakeup.

If you're unlucky (like me with my Asus K7M motherboard), you'll have to find out the bytes in your nvram that contain the RTC alarm date.

Read the README.mb file again.

Maybe you can use the latest CVS version of nvram-wakeup, else you'll have to run the 'guess' script that's delivered with nvram-wakeup, it's usage is described in README.mb

If you've now followed the steps in README.mb and you now seem to have a working configuration for nvram-wakeup, test it yourself, and be aware that false bytes written in your nvram may you cause to loose your precious bios settings.

All I can say, the guess script worked for me, with a little modification.

To use nvram-wakeup with avicap, you should edit 'nvram-wakeup.h' and set these defines to zero like this:
#define WAKEUP_BEFORE    0
#define NEED_TO_SHTDWN   0
cause these values can be set in Avicap's GUI directly.

Step 3: root scripts for your linux

For the shutdown & resume process to work for Avicap, you'll need to have several shell scripts that will be run via sudo:

avicap-shutdown:  let's avicap shutdown your computer
avicap-setnvram:  sets the RTC alarm date in your BIOS via nvram-wakeup
avicap-boot:    a init script for /etc/init.d that starts your computer either via the normal way, or it starts avicap in timer-mode, and manages the 'twice shutdown' problem.

These scripts can be found in avifile/samples/qtvidcap/scripts
They will not get installed by 'make install', you have to copy them to their locations for yourself, cause they could do damage to your system by shutting down unexpectedly.

avicap-shutdown and avicap-setnvram should be copied to /usr/local/bin

avicap-boot should be copied to /etc/init.d

You also have to create these links:

/etc/init.d/boot.d/S01avicap -> /etc/init.d/avicap-boot
/etc/init.d/rc3.d/S99avicap  -> /etc/init.d/avicap-boot

You HAVE to edit all these scripts manually to suit them to your system - especially avicap-boot is highly customized to my system, my way of booting and my preferences.

You also have to edit with 'visudo' your sudoers file to allow avicap to call avicap-shutdown and avicap-setnvram, something like this:
alex ALL= NOPASSWD: /home/alex/sbin/avicap-shutdown
alex ALL= NOPASSWD: /home/alex/sbin/avicap-setnvram

Be aware that using these scripts and letting avicap shutdown & resume your computer interferes severely with the running of a full blown unix system.

The shutdown & resume capabilites should only be used on a 'single-person' workstation, with no running jobs in background.

I've prepared such scripts for my system, they might suit you or not, if you've got better solutions, send them to me.

My system is a SuSE 8.1-based system, running kernel 2.4.18 with apm enabled (this is necessary to poweroff your ATX power...

I am only booting my system to runlevel 3 (no networking, no graphics).

I login in textmode and then do a 'startx' manually.

The avicap-reboot script will check at the end of runlevel 3, if it should do nothing or  start X and avicap automatically, you have to edit this script to suit it to your system and preferences.

On my system, there's a special problem:

the setting of the RTC and the resume will only work, if the system is resetted, after the RTC alarm date in the nvram has been set.

So the shutdown & resume will have to shutdown TWICE, once to reboot to make a reset, and the other to actually shutdown.

It goes like this:

1. Avicap calls 'sudo avicap-setnvram <timestamp>' to set the RTC
    avicap-setnvram will create a file /etc/avicap/next_recording

2. Avicap calls 'sudo avicap-shutdown' to shutdown & reboot my system
    avicap-shutdown will create a file /etc/avicap/first_shutdown
    then it will make a shutdown -r (reboot) to reboot the system

3. The system reboots, and shortly after booting, 'avicap-boot' is called again (in runlevel S)

4. If the file /etc/avicap/first_shutdown exists, the file gets removed and the system will go down again with halt -p -f (force power off) to poweroff the computer.

5. The computer is now off, till the time you've set for first recording.

6. The RTC alarm will poweron your computer

7. My linux will boot in runlevel 3, at the end of runlevel 3 'avicap-boot' is called.

8. If the file /etc/avicap/next_recording exists, then it is assumed that the re-boot is a 'timed' reboot done by the RTC alarm.

9. avicap-boot will then call 'startx' to start X and KDE (takes a long time...) or Gnome or whatever and then 'avicap -timer'

10. and then avicap should start recording as you liked it

11. until the recording stops and it is time to go down again

Step 4: Configuring Avicap for shutdown & resume

There's a new Tab in the 'Configure'-Dialog named 'Shutdown&Resume'

These options tell avicap when to shutdown:

To use that feature, you also have to enable the 'shutdown' checkbox in the main timertable window.
That checkbox will always be de-activated when you start avicap normally (so you have to check it again).
If you start avicap with 'avicap -timer', avicap will open the timertable window, sets that checkbox and starts the timer and waits for the first recording.

avicap is started with -timer from avicap-boot, so it will go down if the recording has finished.

I advise you strongly to test this feature thoroughly, so that you can be sure it works for you,too.
It would be a shame, if a precious recording is lost - but, alas, Free Software comes without any warranty, so be warned

Known Problems

When you've started Avicap from a shell window, it will show it's output there when nvram-wakeup is setting the RTC alarm, you should see for yourself if the RTC is set correctly.