Edit this page Lock this page References to this page History of this page Home Page Recent Changes Upload file attachments Search Site Administration Help Guide

Automating Root Partition Mounting

Up one level to the SOFTWARE parent page
Based on information posted by Steve Jenkins of the Tivo Undergroud.
The original post can be found here

Semi-Automatic remounting:


With a couple of simple scripts, you can manually remount your file system as "read/write" any time you need to, and you can manually run another script to remount as "read only" at will - but as an extra safety precaution, your file system will be automatically remounted as "read only" whenever you log out from the telnet session. For obvious reasons, this is the recommended method, and the one that will be explained below.

How to Set Up Semi-Automatic Remounting

Before we start editing files, I will assume you already have a text editor (such as JOE) installed, and that you've manually remounted your file system with read/write permissions using the following commnd (so you can make the changes I'm about to explain).

mount -o remount,rw /

Let's start by writing a couple of simple scripts that will set the file system permissions we want. It's not a bad idea to store scripts in a directory that is in your PATH. If you haven't already set up your PATH statement, then read my how-to on the subject available here.

On my TiVo, I put scripts in a directory called /var/hack/scripts. If you haven't created this directory yet, type:

cd /var/hack [ENTER]

to change to the /var/hack directory, then type:

mkdir scripts [ENTER]

Now change into the scripts directory with:

cd scripts [ENTER]

Now we'll create two scripts with the JOE editor - one for remounting as "read/write" and another for remounting as "read only."

Create the first script (called makero.tcl) by typing:

joe makero.sh [ENTER]

Enter the following lines:

#! /bin/bash
mount -o remount,ro /
echo "File system is now READ ONLY"


Press CTRL-K then X to exit and save your file.

Now make the second script (called makerw.tcl) by typing:

joe makerw.sh [ENTER]

Enter the following lines:

#! /bin/bash
mount -o remount,rw /
echo "File system is now READ/WRITE"


Press CTRL-K then X to exit and save your file.

Once you've written both scripts, you need to chmod them so that they are executable. Do this with:

chmod 755 makerw.sh [ENTER]

and

chmod 755 makero.sh [ENTER]


Now that we have a couple of scripts that can remount the file system, lets create some simple aliases you can use to invoke them at will. Aliases are set up in your .profile file.

The .profile file is a file in the root directory (which is simply "/") that tells your system what your preferences are when you log in. Get to the root directory by entering the following from your bash prompt:

cd / [ENTER]

This will place you in the root directory. Next, type:

joe .profile [ENTER]

If you already have a .profile file, then JOE will open it to edit. If you don't then JOE will create one for you.

Put the following 2 lines somewhere in your .profile file:

alias rw='/var/hack/scripts/makerw.sh'
alias ro='/var/hack/scripts/makero.sh'

Then press CTRL-K then X to exit and save your file.

You're almost done! Now let's create your .bash_logout file. Linux looks for this file in your home directory and follows the instructions in there before it logs out of the shell. By default, your home directory is the root directory. Unless you've taken steps to change your home directory, you're already there since you edited your .profile file in that directory. But just to make sure, simply type:

cd [ENTER]

Typing that command with no options will always place you in your home directory, no matter where it is located.

Next, use JOE to create (or edit) your .bash_logout file:

joe .bash_logout [ENTER]

Place the following TWO lines at the top of the file:

mount -o remount,ro /
sync


According to lightn, the sync command forces a cache flush to disk and returns when it is finished.


The sleep command gives the file system long enough to remount as read only and write any cached file system data before your log out is completed, and by now you should recognize the command under it as the manual command to remount as read only.

Exit JOE and save your file with CTRL-K then X.

IMPORTANT! Make sure that when you're finished with any telnet session from now on, you end it by typing either:

exit [ENTER]

or

logout [ENTER]

and waiting until your TiVo closes the connection (it will take at least 10 seconds because of the sleep command in your .bash_logout file).

This will make sure that the .bash_logout file is parsed before your session closes. Simply closing your telnet client does not log out properly, and you are risking file corruption by doing so.

Just to be safe, manually remount your file system as read only before logging out and logging back in to test your automation settings. Do this with:

mount -o ro,remount / [ENTER]

Now log out (using exit or logout), wait for your telnet client to close the connection, then log back in and test your settings. You should now be able to type:

rw [ENTER]

to change your file system permissions to read/write, and:

ro [ENTER]

to change them back to read only. But even if you forget to do so, your .bash_logout file is there to make sure you remount to read only before you end you telnet session, as long as you always terminate your session properly.



Corrections or updates for this page:
Note: Do not post questions, unrelated comments, or information of which your are uncertain. This section is reserved for corrections and updates only.