Previous section   Next section

Hack 34 Installing Unix Binaries on TiVo

figs/beginner.giffigs/hack34.gif

Continuing where we left off a little earlier [Hack #31], let's install those useful Unix utilities we copied over to TiVo's hard drive.

So you have a prompt [Hack #33], now what? By default, you don't even have the ability to do an ls (list the files in a directory). How lame is that? Not at all, really, when you consider that, from TiVo's point of view, all those human-usable utilities are superfluous for its purposes—to record television shows and play them back to you on demand. But, from a human's perspective, it's pretty lame indeed.

Let's check in on those Unix utilities you copied to your TiVo [Hack #31] and get them installed.

With your TiVo up and running, the /dev/hdX9 partition should be mounted as the /var directory. This is easily verified, like so:

bash-2.02# mount
/dev/hda4 on / type ext2 (ro)
/dev/hda9 on /var type ext2 (rw)
/proc on /proc type proc (rw)

And there it is. Partition 9 (/dev/hda9) is mounted read-write (rw) as the /var directory. Partition 4 (/dev/hda4) is mounted read-only (ro) as /. You'll remember it was known as /dev/hdX4 when mounted in our PC, but to TiVo it is mounted as the active primary master partition, as expected.

Now all we need to do is make our way back to the hack directory created earlier and unarchive that tar file, right? Well, yes; the only problem is that we don't yet have the tar command installed. We do, however, have cpio (read "copy input/output") with which we can manipulate the file just fine.

Expand the contents of the archive and rename the resultant directory (tivo-bin) to bin (short for "binary"):

bash-2.02# cd /var/hack
bash-2.02# gzip -d tivobin.tar.gz
bash-2.02# cpio -idu -h tar < tivobin.tar
bash-2.02# mv tivo-bin bin

As a last step, let's make sure that all the utilities are executable:

bash-2.02# chmod 755 bin/*

Now, let's give one of the utilities a whirl, shall we?

bash-2.02# cd bin
bash-2.02# ./ls

As expected, you should see a list of all the files in the bin directory.

The last step is to put these binaries into your path by setting the PATH variable so that your command-line shell knows where to find them. Otherwise, you'll have to specify the path to ls and its kin each time you use one of the utilities. Trust me, typing /var/hack/bin/ls each time will get really old really fast. And simply typing ls won't get you very far:

bash-2.02# ls
bash: ls: command not found

The PATH environment variable specifies which directories the Bash shell should look in when you ask it to run a command. Bash just goes down that list one directory at a time looking for the command you asked for; when it finds it, it runs it for you. Let's take a quick look at that PATH variable as it is natively:

bash-2.02# echo $PATH
/bin:/sbin:/tvbin:/devbin

Those colon-separated words are the names of the directories it'll be looking in. Notice it is not looking anywhere near your new /var/hack/bin directory. Adding it is a piece of cake. Simply tell Bash to reexport the PATH variable, tacking on the location of your bin directory:

bash-2.02# export PATH=$PATH:/var/hack/bin

Taking another peek at the modified PATH, you'll see the new directories listed:

bash-2.02# echo $PATH
/bin:/sbin:/tvbin:/devbin:/var/hack:/var/hack/bin

Try that ls command again; it should work like a charm no matter where you are on the drive.

Unfortunately this change to your path is not permanent. The next time your TiVo reboots, PATH will revert to its default. What you need to do is change your path's default, accomplished by altering your profile via the aptly named .profile file. The .profile file is read whenever the Bash shell starts up, so it's a perfect place to set some preferences right off the bat for your shell session. TiVo's home directory is the / directory, so the .profile file should live there. Let's go ahead and create it.

Now, if you've been reading carefully, you'll remember that the partition mounted at / is still read-only. If we attempt to change anything at that mount point, TiVo will complain that we are attempting to write to a read-only location and stop us in our tracks. So, let's remount that directory as read-write:

bash-2.02# cd /
bash-2.02# mount -o remount,rw /

Now we can create that .profile file without any problem. Don't forget to remount the / directory as read-only again. Otherwise, you'll only confuse TiVo at some point:

bash-2.02# echo "export PATH=\$PATH:/var/hack/bin" >> /.profile
bash-2.02# mount -o remount,ro /

Note that extra backslash before the $ in $PATH. If you don't have that there, Bash will expand the value of PATH before it gets written to the file.

Whew! That was slightly painful, but worth it! You now have a rudimentary, but usable, Unix account on your TiVo. Just in case you haven't really meandered around a Unix shell before, Table 3-1 provides a quick summary of a few of the more common useful commands. For a comprehensive guide to the bash shell, check out O'Reilly's Learning the bash Shell (http://www.oreilly.com/catalog/bash2/).

Table 3-1. Unix commands to use when poking around TiVo's filesystem

Bash shell command

Purpose

ls [dir]

List files either in the current directory or a specified directory.

pwd

Print the current working directory (i.e., tell me where I am).

cd [dir]

Change directories, either to your home directory (/ in TiVo's case) or the specified directory.

cat [filename]

Print the contents of the specified filename to the terminal. Output can be redirected to another file (e.g., cat file1 > file2), concatenating (thus the name) the contents of the first onto the second.

touch [filename]

Set the modification date of a specified file to the current time. Touching a nonexistent file creates a blank or zero-length file.

mv <original> <renamed>

Rename or move a file or directory from original to renamed.

rm <filename>

Remove the specified file.

mkdir <directory>

Create a new specified directory.

rmdir <directory>

Remove a directory. This works only if the directory is empty, all its contents having already been removed using rm.

See Also


  Previous section   Next section
Top