# How can I perform a graceful shutdown/reboot?



## ciper (Nov 4, 2004)

I've been rebooting my Tivo ALOT lately (see http://www.tivocommunity.com/tivo-vb/showthread.php?t=360675 ) and would like to find a way to do it gracefully.

Pulling the plug, using "restart the recorder" from the UI, running /sbin/restart or using the reboot binary all crash the system resulting in corruption on the var partition. I'm not surprised that people lose their hacks!

Is there another binary or script that exists which will shutdown the Tivo properly? I always worry about the potential for database corruption that isn't reported since the partitions are not mounted normally.


----------



## ColinYounger (Aug 9, 2006)

I've rebooted my TiVo plenty of times while tinkering with scripts, and have not once had fsck run. I've even used 'reboot' from the shell prompt and not seen a problem.

So I'm wondering if your tinkering has made the TiVo unstable.

Also - is your root partition set to read only before a reboot or RW? I'm wondering if rebooting while in RW mode is causing the problem.


----------



## ciper (Nov 4, 2004)

Check your kernel log. e2fsck always runs even if the FS is clean. I tested this by pulling the drive and cleaning the var partition and then placing it back into the Tivo. I didn't mean mfsfix/gsod. The closest thing I can think of is running

```
sync ; reboot
```
But even that still causes some corruption on var

Here is an example of what to look for.

```
Jan  1 00:03:18 (none) kernel: Loading input section drivers
Jan  1 00:03:18 (none) kernel: [b]Cleanup /dev/hda9 pass 1[/b]
Jan  1 00:03:18 (none) kernel: ext2fs_check_if_mount: No such file or directory
Jan  1 00:03:18 (none) kernel: /dev/hda9 was not cleanly unmounted, check force
Jan  1 00:03:18 (none) kernel: Deleted inode 28712 has zero dtime.
Jan  1 00:03:18 (none) kernel: Set dtime? yes
Jan  1 00:03:18 (none) kernel:
Jan  1 00:03:18 (none) kernel: Fix summary information? yes
Jan  1 00:03:18 (none) kernel:
Jan  1 00:03:18 (none) kernel: /dev/hda9: 505/32768 files (4.0% non-contiguous)
Jan  1 00:03:18 (none) kernel: Cleanup /dev/hda9 pass 2
Jan  1 00:03:18 (none) kernel: ext2fs_check_if_mount: No such file or directory
Jan  1 00:03:18 (none) kernel: /dev/hda9: clean, 505/32768 files, 27338/131072
Jan  1 00:03:18 (none) kernel: /dev/hda9 is clean after pass 2
```


----------



## blindlemon (May 12, 2002)

Try "restart"


----------



## ciper (Nov 4, 2004)

I edited my first post to include restart. It does it too. Here is the log entries from using /sbin/restart


```
Jan  1 00:03:19 (none) kernel: Loading input section drivers
Jan  1 00:03:19 (none) kernel: Cleanup /dev/hda9 pass 1
Jan  1 00:03:19 (none) kernel: ext2fs_check_if_mount: No such file or director
Jan  1 00:03:19 (none) kernel: /dev/hda9 was not cleanly unmounted, check forc
Jan  1 00:03:19 (none) kernel: Fix summary information? yes
Jan  1 00:03:19 (none) kernel:
Jan  1 00:03:19 (none) kernel: /dev/hda9: 529/32768 files (6.0% non-contiguous
Jan  1 00:03:19 (none) kernel: Cleanup /dev/hda9 pass 2
Jan  1 00:03:19 (none) kernel: ext2fs_check_if_mount: No such file or director
Jan  1 00:03:19 (none) kernel: /dev/hda9: clean, 529/32768 files, 32223/131072
Jan  1 00:03:19 (none) kernel: /dev/hda9 is clean after pass 2
Jan  1 00:03:19 (none) kernel: Mounting /var
```
I'm going to now try
sync ; mount -o remount,ro /var ; restart
even though it doesn't take car of the MFS partitions.


----------



## mikerr (Jun 2, 2005)

running restart at least tries to dismount /var ...



> bash-2.02# restart
> Killing processes...
> Dismounting /var
> Couldn't dismount /var
> Restarting system...


umount -f /var
gives the mesage that forced umounts aren't implemented yet 

fuser -km /var

but fuser isn't on tivo series1, unless there is a binary floating around the net ?


----------



## ciper (Nov 4, 2004)

Haha I was just going to post the exact same thing not including fuser.

My attempt above using "sync ; mount -o remount,ro /var ; restart > /var/reboot.log" resulted in me getting stuck at a "mount: /var is busy" prompt and I cant undo it  

Ive been doing all my testing remotely using telnet and a slingbox so it seems I might be done for the night!


----------



## aerialplug (Oct 20, 2000)

rebooting by pulling the plug or using the shutdown in the UI shouldn't lose /var.

In my experience, what causes my /var partition is pulling the plug while a reboot is in progress or possibly immediately after TiVo has rebooted while system tasks are still being completed.


----------



## ciper (Nov 4, 2004)

Even if thats the case any of the current methods of rebooting the system cause some type of errors on the partition and I dont like it. Try it yourself. Afterword search your kernel log for "cleanup"

Looks like there was a discussion about something similar on the other forum http://xaddr.com/sh

Edit: Hmm this is getting a little better but not quite http://forums.oztivo.net/showthread.php?t=962


----------



## iankb (Oct 9, 2000)

aerialplug said:


> In my experience, what causes my /var partition is pulling the plug while a reboot is in progress or possibly immediately after TiVo has rebooted while system tasks are still being completed.


Your local electricity company can also do it remotely by cutting your power twice in quick succession.


----------



## TCM2007 (Dec 25, 2006)

Those error messages just seem to indicate that the "unmounted cleanly" flag (if that's what it's called) isn't set. I can't see this does any harm? /var is only wiped if it fails a second check.


----------



## aerialplug (Oct 20, 2000)

iankb said:


> Your local electricity company can also do it remotely by cutting your power twice in quick succession.


Yes, I suffered this last December.


----------



## boringgit (Jan 20, 2007)

Every now and again my Tivo appears to be interlaced.

Recordings are fine, but entirely unwatchable until you reboot. Happens to me about once a fortnight...


----------



## TCM2007 (Dec 25, 2006)

What do you mean? TiVo's output is always interlaced.


----------



## AMc (Mar 22, 2002)

aerialplug said:


> iankb said:
> 
> 
> > Your local electricity company can also do it remotely by cutting your power twice in quick succession.
> ...


I stuck a cheap UPS on mine to prevent it all going to pot when the power goes out for a couple of minutes which was quite regular over winter. Pleased to learn this should save me more than the odd recording!

I can recommend this 500VA one - you'll need to convert a power strip to a kettle lead connection.
http://cpc.farnell.com/jsp/search/productdetail.jsp?SKU=CS1324907
£33 inc VAT + delivery or free delivery if your exVAT order is over £40.


----------



## mikerr (Jun 2, 2005)

TCM2007 said:


> What do you mean? TiVo's output is always interlaced.


One of my tivos does that too... tivo seems to get its video output clock rate confused, all display including menus are all affected. Its like the effect you get when a PC is its outputting a scan rate the monitor can't handle (no picture roll though)

Its been doing it once a week or so for the past 2 years, and hasn't got any worse. A reboot cures it, and recordings are unaffected.


----------



## ciper (Nov 4, 2004)

The best solution I have found so far is to use

```
/bin/sync ; /sbin/restart
```
This still results in the error on startup that the FS was not unmounted but at least there aren't other errors. The /sbin/restart binary tries to unmount var but is unable to because the FS is in use. I think tivoweb and mfs_ftp are to blame so I'm going try and create a scrip that syncs the disk, kills the offending app and then runs the combination sync;restart.


```
bash-2.02# sync ; restart
Killing processes...
Dismounting /var
Couldn't dismount /var
Restarting system...
TmkLogger:
```


----------



## mikerr (Jun 2, 2005)

I've just found a post from yourself saying you have the fuser binary, so

fuser -km /var

kills any processes that are using /var
then you should be able to unmount it.

fuser -um /var

would show which processes are using /var


----------



## ciper (Nov 4, 2004)

Nice! Ill try that. Its kinda funny but I was planning to re enable mode0 on my tivo and after searching I found a post by myself that I didn't even remember writing that had all the settings in it LOL


----------



## TCM2007 (Dec 25, 2006)

mikerr said:


> I've just found a post from yourself saying you have the fuser binary, so
> 
> fuser -km /var
> 
> ...


Careful; forcibly killing a process running under tivosh which has the databse open can (and usually does) make the TiVo crash and reboot in anything but a nice way!

That's why EndPad, mfs_ftp and other have these convoluted ways of unloading themselves, 'cause kill -9 ends up with the "Almost there..." screen.


----------



## ciper (Nov 4, 2004)

Shoot. I used to have just about every binary imaginable that would run on the S1. After my A drive crapped out recently I lost everything and had to start from scratch. I thought I had a complete backup but come to find out many of the files are missing.

By chance did anyone download the archived copy of the "complete" S1 binary set? I'd love to get my hands back on it as it took a long time to find and sort the binaries to weed out the MIPS versions.


----------



## BTUx9 (Nov 13, 2003)

remember that syslog does a lot of scribbling on /var... you'll need to turn off logging just before rebooting.


----------

