# MythTV/Installing

* MythTV Introduction | Getting Started | Installing | Extras | Troubleshooting | Conclusion
The easiest way to install MythTV is to follow a how-to. The following how-to is geared towards Mandrake 10.1 Official (download), but most of the steps will be similar for other linux distributions. The locations of some files may be slightly different, and instead of using urpmi to install updates, you will need a different tool depending on your distribution. So, you should first figure out what packaging tool is used on your linux distribution, and whenever commands involving urpmi arrive, use your tool instead. Examples of tools used on other command-line tools are apt-get, and emerge (used on Gentoo). There are also graphical tools, such as grpmi (graphical version of urpmi), rpmdrake (for Mandrake), Synaptic, etc.
If you're using another distribution and need to find a particular file, you can always use the find command. For instance:
will find everything that starts with "file." (Note that searching starting at the root level, "/", will take a long time, so you should limit your search if you can.) This can be a great way to figure out where a file has been placed in your distribution. You can also use
To find out where a given command or script is located. (The "whereis" command is also useful.) If the command does not exist on any defined path, this will let you know (so that you can either install the required software, or add it to the path appropriately). This is useful when a how-to asks you to run a command that you seemingly don't have. Also, before running any commands you should probably do
to get some information on what the command does and how to use it. Many times the answer to your question is hidden inside a manual page.

## Example installation: MythTV 0.17 on Mandrake 10.1 with a Hauppauge PVR-350
### Download and install Mandrake

You can download the latest Mandrake ISO images from the official download page, or from any number of mirrors. You then burn these ISO images to CD, and perform the installation by booting off the CD. There are many other ways to install linux of course. What you install of course depends on what you want. You should install all the multimedia options, and development tools (so that you'll be able to compile things later). It's probably a good idea to install network client functions, and if you want to access your MythTV remotely, you should install some server packages (web server and ssh server especially). Having your MythTV running an SSH server can be handy if you have another computer at your disposal, because then you can have your MythTV hooked up to your television, but configure it via command line of another computer (this is good because your MythTV, when hooked up to a television, doesn't have very good resolution, and it can be aggravating to use it as a computer). You need to install some sort of window manager. KDE is a good choice if you have no other preference.
In terms of partitioning your disk, it makes good sense to have your linux OS on one partition, and keep another partition for storing your MythTV data. That way you can reinstall linux without deleting your videos. Linux doesn't need very much space (5 or 10 Gb is sufficient). Be sure to make your swap partition (512 Mb is pretty typical, but you can make it bigger if you like). And of course the bulk of your space (100+ Gb hopefully) is allocated for mythTV. You can set the mount point of this partition as "/data/" or "/home/mythtv/data/" or "/home/" or whatever you like.
During installation, you may aswell create an account called 'mythtv'. Once the installation is complete, create the directory where you will store your MythTV data (make sure it is inside your big partition!). So, for example, if you wanted to create /data you would type 'su' to become root, and:
You'll also want to have your kernel source installed (for compiling drivers, later). To install software on Mandrake, we use a convenient tool called "urpmi" that downloads, installs, and configures automatically. Often, you can just type:
and your source will be installed. However, this won't always install the correct kernel source. You must make sure that your kernel source version matches the version of the kernel you're using. To determine your current kernel version, type:
In this example, a 2.6 kernel is running. To install the right 2.6 source:
Of course modify this command depending on what source you're looking for. You can also use "urpmq" to query your urpmi sources, and find out what different kernel sources are available, and what the package names are called (be warned: packages like "kernel-source-2.6" might not be the exact kernel version you have, so look for something that matches exactly). If you can't find the right source, you can try configuring some urpmi sources (refer to the next section), and then use "urpmq" again to find a source that matches your kernel.
Once you have your kernel source installed, it's a good idea to double check that it's the right one:
Thus, make sure that the "linux-*" directory matches what uname returned. If not, you should uninstall the current kernel source (by typing something like "# urpme kernel-source") and then install the correct source. Also, make sure that you have the above symbolic link. If you don't have one, then make it:
There is another symbolic link that is often missing, which you should create if it isn't there. Check:
And make it if it is missing:

### Get urpmi sources

Mandrake uses urpmi to download and install all sorts of software. After installing Mandrake from CD, you probably have three CDs listed as sources inside urpmi. When you tell urpmi to install something, it checks all of its sources, finds the package you want, and installs it. For our purposes, it's best to add some online repositories of Mandrake packages to urpmi. That way, all the dependencies will be automatically downloaded and installed as needed. So that we always get the newest packages, we can remove the current sources (which are the installation CDs):
Now we need to find some good, trustworthy, and fast online package sources. There is a great online tool called Easy Urpmi. You pick your distribution, pick a trustworthy local package source, and it prints out the command you must enter to add the designated source properly. Nothing could be easier! There are numerous mirrors of Easy Urpmi:
* Easy Urpmi official
* Mandriva users
* urpmi-addmedia
* Linux for dummies
* Linux for dummies
* Linux for newbies
* notix
Be sure to pick the right Mandrake version and architecture. If you're not sure what you're using, try this:
An example of what Easy Urpmi outputs, which you then type in a console as root:
Downloading all the package information will take a little while (depending on your internet connection speed). Finally, we must add a source for the Mandrake MythTV RPM. Luckily, Thac's RPMs have what we need:

### Download MythTV

With our sources defined, a single command will download, install, and configure MythTV, including all missing dependencies (MySQL, QT, etc.):
The installer will prompt you for which package to select. You may notice three options, one with "nvidia" in the name, one with "via" and one that is generic. If you specifically have nvidia or via hardware, you can go that route, but the generic packages should work in most cases. When presented with the (long) list of packages to install, say "yes" and wait for it to finish (may take 30 minutes to several hours).

### Install ivtv

Now we need to install the ivtv driver, which is an open-source driver written to enable linux compatibility with Hauppauge WinTV PVR capture cards. The example below should work for the PVR-150, 250, 350, and 500. With a little imagination, you can also adapt these instructions to your own capture card. First off, let's avoid any hardware conflicts by getting rid of the default ivtv driver provided in most Mandrake installs:
The msp3400 module will be replaced too:
If you're nervous about all this, then you can move the implicated files somewhere else for safe keeping. Just make sure you put them out of the modules directory, so that they are not loaded (use the "mv" command and put them in /home/mythtv/tmp for example). Now download the source code for ivtv. Go to the ivtv project page and select download. You'll then have the option to download various versions. As of the writing of this document, the 0.2 drivers are stable, whereas the 0.3 are beta and unstable. A safe bet is to pick the latest 0.2 release (ivtv-0.2.0-rc3j as of this writing). If you have problems with the driver, you can try different versions (or even try a 0.1.9 or a 0.3 driver).
Those last two commands will compile the driver and put all the required files in the right places. Many users experience errors during the make operations. If you have permission errors, try switching to root and make again. Sometimes the problem is fixed by trying a different driver version. Often the problem is simply that your kernel source version does not match your running kernel (see elsewhere in this document). In extreme cases you may have to change to a different kernel. Try searching the internet (and elsewhere in this document) for the error messages you're seeing. Someone else may already have figured out the solution to your problem.
The next step is to extract the firmware for the capture card. This is binary driver information that we need to communicate with the capture card properly. For this next step to work, g++ must be installed, so let's check:
If it's not on your system, install it with urpmi:
Now let's compile the firmware-extraction utility:
So far so good. Now we need to get the capture card driver binary and extract out the part we need. Depending on whether you have a new or old Hauppauge card, these files will be located in slightly different places on the installation CD-ROM that came with your card. The ivtv wiki has lots of helpful information. For older cards, expect a file called "pvr48wdm_1.8.22035.exe" (or something similar) but for newer cards it will be "pvr_1.18.21.22301_inf.zip" or "hcwPVRP2.sys." You can also simply download the appropriate file from the ivtv firmware page. For example:
Then extract the firmware:
This should have placed two new files in the "/lib/modules" directory, 'ivtv-fw-dec.bin' and 'ivtv-fw-enc.bin'. You can go check:
The installer has also placed our new modules into the "/lib/modules/2.6.8.1-12mdkcustom/extra", but our kernel won't see these. Instead, let's put them in the right place:
Now let's reload the module list. You can reboot too, just to make sure everything gets loaded:
After rebooting, we can try loading our new ivtv module and see if it actually works. A few modules have to be loaded in the proper order:
Note that the "tuner type=2" varies depending on your capture card's tuner type. You can find a list of the tuner types in the "tuner.h" file in your ivtv driver directory:
(Note: to exit emacs use "Ctrl-x Ctrl-c".) For North American users, "tuner type=2" (Philips NTSC) will probably work. If the module loaded properly, we can run a quick test. Hook up a video input to your card, and type:
Let this run for awhile (10 seconds maybe) then hit Ctrl-C to stop it. This should have captured a bit of video and saved it to the file "test.mpg". Try playing the file:
If everything is working, you should see some video. If you see snow or even black, that's actually a good sign. It means the driver is probably working, but you'll need to play with settings to get it to capture on the right channel. If you instead get an error message and no video is captured, then you should start looking for solutions. Maybe your tuner type is wrong. Maybe you forgot to remove conflicting ivtv modules. Maybe a different driver version would work. Play around, search for answers.
If everything is working, then you can create a script to load these modules. Let's call it "/usr/local/bin/start-ivtv". Open a text editor (emacs, vi, kwrite, etc.) and put this in:
Save and exit (in emacs "Ctrl-x Ctrl-s" does this, in vi use "ESC, :x"). Remember to make the script executable:
Now if you type "start-ivtv" (as root) everything will be loaded. Later you can modify this script to start MythTV automatically when the computer boots.

### Configure MySQL

First set the MySQL service to automatically load during boot, and start it manually for now:
And now change the database permissions so that MySQL can do what it needs to. Note that you should replace "root_password" with your root password.
Now update the database:
MySQL should be ready to go.

### Configure MythTV

Before configuring MythTV, set up an account with a service that will give you XMLTV listings. In North America, this means setting up an account with zap2it DataDirect. Now we can setup our MythTV using a graphical configuration tool:
The options in this program are fairly self-explanatory. Set everything up consistent with your hardware and preferences.
    1. General:
       For "IP address for localhost" and "Master Server IP address", you can enter your IP address, or leave it with the defaults if you're running the frontend and backend on the same computer
       For the "recordings" and "Live-TV buffers" directories, enter the directories you've chosen. For example, "/home/mythtv/data" or "/data/mythtv" or whatever.
       For the "TV format" selected "NTSC" (or whatever your local setting is).
       For "VBI format" you probably want "NTSC Closed Caption". Depending on your driver, closed captioning might not be supported.
       For "Channel frequency table" most North Americans should select "us-cable".
    2. Capture cards:
       Create a new capture card, set the "Card type" to "MPEG-2 Encoder card", and set "Default input" to whatever you're using (tuner, S-video, etc.).
    3. Video sources:
       Create a new video source.
       Set "XMLTV listings grabber" to "North America (DataDirect)".
       Enter your User ID and password for zap2it
       Select "retrieve lineups".
       Check that the "Data Direct Lineup" is consistent with your zap2it subscription.
    4. Input connections:
       Set the "S-video0" (or whatever you're using) "Video source" to the name of your defined video source.
Now you can fill the MythTV database with your listing of TV channels:
This operation will take awhile, as MythTV downloads all the program data (for the next few weeks). Once it's done, start MythTV:
Use the keyboard to move around and see if things are working. If everything is good, then you can update your "start-ivtv" script to include "/etc/init.d/mythbackend start":
If everything is working, then you may aswell set your "start-ivtv" script to start automatically at boot time. To do this, edit your "/etc/rc.d/rc.local" file, by adding "/usr/local/bin/start-ivtv" to the end:

### Configure remote control

We'll be using LIRC to read the signals from the Hauppauge remote. Refer to the mailing list archive when searching for answers to problems. First get rid of any other version of LIRC that MythTV may have installed:
Go to the LIRC page and download the latest release, then untar it and start the configure script:
What to do is pretty obvious. Select item 1, then item 5 "TV Card", then select "Hauppauge TV card". Then select "Save configuration & run configure". Now make and install everything, and link it up:
Open up the file "/etc/ld.so.conf" and add "/usr/local/lib" to the end. Or just type:
Then run ldconfig (which updates the run-time link libraries):
Copy the configuration file from MythTV documents to your lircrc directory, and add a symbolic link:
Copy the appropriate remote config file:
You could now update your "start-ivtv" script to load the remote (lirc_i2c) modules:
Now you should restart everything:
See if the remote works. It might be a good time to reboot, and see if everything starts up:
Once its booted, you should be able to run "mythfrontend" and use your MythTV. You can open the "/home/mythtv/.lircrc" file and edit it to map your remote properly (more on this later). For the moment, if you're using a Hauppauge silver remote, then you should change "Rew" to "Rewind" and "FFW" to "Forward".

### Configure TV-out

The configuration of your TV-out depends on your hardware. If you're using a video card with a TV-out, then it may simply be a matter of having a TV connected to that output during boot, and the card may output everything (the console, the GUI, and MythTV) to the TV. This is an easy solution. For other cards, you may have to edit your X server configuration file. On older versions of linux, this file would be "/etc/X11/XFree86Config" (there are many similar locations where it may be found). In a modern Mandrake distribution, the file that is used is "/etc/X11/xorg.conf" (which may just be a symlink to another config file mind you). Before going any further, make a copy of your old xorg.conf, and then you can try editing it and see if that helps. After making a change to xorg.conf, you can use Ctrl+Alt+Backspace to exit and restart the X server (and thus your window manager, KDE). If your new settings worked, then you may see output to your TV. If not, you can get back to a console by using Ctrl+Alt+Backspace, and switch back to your old xorg.conf or try something else. Some extra help can be found here and here.
To use the TV-out on the Hauppauge 350 in particular is a good idea, since the 350 has hardware MPEG decoding, which means that it will do the work of decoding the video stream, thereby taking the strain off of your processor. To enable it, there is an option in MythTV that says "use hardware MPEG decoder", which will just use the 350 to output TV. Although this will output recorded playback to the 350's TV-out, you won't have your MythTV menus on that same graphics output. To get everything to work together smoothly, we need our entire X environment (including the desktop and MythTV frontend) to output using the 350's TV-out. Here's what you do:
First, modify your "/usr/local/bin/start-ivtv" script to load "ivtv-fb" also, by adding a line "/sbin/modprobe ivtv-fb":
Now let's get the ivtv driver right. Essentially, X needs a driver to use the 350's TV output. What you want is for the "ivtvdev_drv.o" driver to end up in "/usr/X11R6/lib/modules/drivers". As usual, there are a couple of options. You can build the appropriate driver from the ivtv source you have. The source is here:
The instructions to install are in "/home/mythtv/ivtv-0.2.0-rc3j/utils/README.X11". So essentially you should be able to run install, which will make everything. The second way (which might be easier) is to download a binary version from somewhere, and then just copy it:
Now we need to determine the PCI settings of your card. There are three different ways of getting this info:
or
or
What you will get will be information about the PCI address of devices. Find the one corresponding to your desired TV-out (the Hauppauge 350 card in our running example). The address is usually given in the order "bus", "card number", "function". Pay attention to whether the numbers are decimal or hexadecimal (preceeded by 0x). The lspci and scanpci tools report in hexadecimal, whereas Xorg outputs decimal. Keep in mind that the xorg.conf file expects things to be in decimal, although you can explicitly denote hexadecimal by preceeding a value with "0x" (or just convert them to decimal).
The output of lspci will look something like:
The "iTVC15 MPEG-2 Encoder" is the capture card, which we'll use for TV-out. This card would thus be given the bus designation:
(Remember that 0x0b is 11 in decimal.) Now we need to know what linux device this maps to. The 350 is essentially a special kind of framebuffer device. There are many ways to do this. Let's check "/var/log/messages" and see what "ivtv-fb.o" is mapped to:
You could also use "fbset" and go device by device ("fbset -fb /dev/fb0" then "fbset -fb /dev/fb1" etc.) and see which one corresponds to your required card. In our current example, the output we want is "/dev/fb1" (for video-card TV-out, it may end up being a /dev/fb or a /dev/video).
Now we need to reconfigure xorg.conf, armed with our new information (namely that our card is /dev/fb1 at BusID "PCI:0:11:0" using ivtvdev_drv.o). As usual, be warned: improperly configuring your video settings could damage your video card and/or monitor. These instructions are provided as examples. Use them at your own risk and be sure to double-check that they make sense for your hardware. Now to start, let's add a monitor:
That should work for NTSC. For PAL, it would be something like:
Note that the Identifier in all xorg.conf sections is arbitrary. You can set it to whatever you like. However, once you decide on a name, remember to stick to it. Elsewhere in your file you must refer to the sections by name exactly. Any little typo will break your configuration. Now add a device:
Again the identifier is arbitrary, but remember what you pick. Above we are using the "ivtvdev" driver and the "fbdev" option. The commented-out lines are alternate options that you could try using: they may be better for your particular setup (in that case, be sure to comment-out the other line to avoid conflict). Remember to update the "/dev/fb1" as needed by your device, and change the BusID to whatever you determined before. This is critical! Now we define a screen (this again would be slightly different for PAL):
Lastly we switch the ServerLayout to use our new output. Just by changing this one section, you can control what input and output devices (defined above) are going to be used. This will let you switch between different configurations easily. You can have multiple ServerLayouts defined if you like. For your new ServerLayout, it's best to copy the existing one and just modify it as needed. It will end up being something like:
Save the file, restart X (Ctrl+Alt+Backspace if you are inside the GUI), and hopefully it will begin to output to the TV-out you wanted. Note that for some cards this won't work unless there is a device hooked to that output when X starts up. So make sure the TV is hooked up and turned on before trying to switch to/boot into your new X setting. If it didn't work, you can go back to your older settings or try something else.

### Test everything

So now everything should be working. Upon booting, the drivers should load, and "mythbackend" should have started. If you use "pgrep" you should get a process ID number (PID) for that process:
MythTV should start when you invoke:
Once MythTV is running, you should be able to select "Live TV" and watch TV. Using the keyboard, you can pause ('p' key), rewind and fast-forward (arrow keys) and so forth. You should be able to go into the program guide and select a particular show, and then select "Record" and then wait for it to record that show. There are many options that you can adjust to suit your preferences. You may want to increase the font size or even select an entirely different theme. If the basics of MythTV are working, you can start using it, and over the next while you can continue customizing it, and getting other functions and plugins working properly.