Installing MythTV on Ubuntu 5.10 (Breezy) with a Hauppauge PVR-150/250/350/500

The creation of this HOWTO has taken a large amount of effort and time, and is not polluted with ads.  If you have the means and this HOWTO helps you, please consider leaving a tip!  But, at the same time, please do not feel obligated to.

First, credit where credit is due: I first set up MythTV under Fedora Core 3, using the excellent HOWTO by Jarod Wilson. For reasons better left unexplained, I decided to try out MythTV on Ubuntu. For this, I leaned heavily on two HOWTOS: one written by Andrew Barbaccia and one by Joe Kallo. While each are very useful, I did run into a couple of issues that I wanted to pass along, and therefore, this HOWTO was born. In this HOWTO, I also give you links to various files along the way, so that you can see exactly how it is set up on my system.

Obviously, this guide is meant to help, but may not be absolutely perfect for your own setup. This is written for my own sake as much as yours. I have also included approximate time-to-complete for each step, which include the download times; note that this is how long it took *me* to get it done, not you. Even so, the times should be roughly in line.

For whom it may concern, here is a description of my hardware

MythTV 0.19: On Feb 11, 2006, MythTV 0.19 was released.  This HOWTO uses binaries that are generally available on the Ubuntu repositories in order to install, so you will get MythTV 0.18 for now.  However, I do show you, in section 9.8, how to upgrade your installation to MythTV 0.19 by compiling from source.  So, you get get the new goodies in 0.19 if you desire.

For PVR-250, PVR-350, and PVR-500 users: there is nothing in this HOWTO that is necessarily PVR-150 specific! As such, you should be able to use this HOWTO without much problem, *unless* there is something special that needs to be done for your particular card. As the folks working on the ivtv driver have done a very good job with the driver and making it card-agnostic, I doubt that this will be the case. But, as I don't have any of these cards and can't test them, I just don't know. PVR-500 users should be able to follow this guide with good results, since a PVR-500 is just two PVR-150's on a card. The only thing to be concerned about there would be to set up both tuners in the initial MythTV setup.  UPDATE: There have been success reports submitted by users with PVR-150/250/350/500 cards.  So, that covers them all.

For Kubuntu users: the instructions should work for you as well, but since I don't have a Kubuntu system, I can't be sure.  I will have to rely on user feedback to see if this is truly the case.

For 64-bit users: 64-bit processors are becoming more common now, due to AMD's offerings.  There have been success reports with these platforms, provided that the special instructions for 64-bit users (in the HOWTO below) are followed.

For folks already using MythTV on a different platform and wanting to upgrade, I have some very useful nuggets of information at the bottom of this HOWTO that you might like. The main two problems are repartitioning your disk to make room for Ubuntu while not destroying your initial MythTV install, and migrating your MythTV database from your old install to your new one. This was exactly my situation; I was moving from a Fedora Core 3 install of MythTV to a Ubuntu one.

1. Install Ubuntu (35 minutes)

Go download an Ubuntu ISO, burn it to CD, and install. During the install, you are asked which resolutions to select for your X server; I removed all but the 800x600 and 640x480 resolutions. That's probably not necessary, but I figured that I would let you know what I did personally, since I will be using a standard definition TV. Obviously, you Hi-Def people would not want to do this.

Other HOWTOs have words on how to partition your drive, so I will throw in my 2 cents. I would create a root partition (/) somewhere in the range of 10-15GB; this is where you will install Ubuntu. Also create a swap partition of about 2x your memory size or 1GB, whatever is larger. Finally, create a partition where you plan to store your recordings and videos, and hopefully this is quite a large space (80 GB minimum, say). Furthermore, I recommend using LVM+XFS as your filesystem on this space -- see the end of this HOWTO on how to do this (look for the section titled "Using LVM to create logical volumes").

A good point that I read somewhere else: when prompted to create a user during the installation, do not choose "mythtv"! That user will be created automatically later in the installation, and if you create it now, you might be in for a world of hurt.

Now for a hint. If your new Ubuntu installation boots and ends up at a blank screen (especially if you hear the little 'tom-tom' sound somewhere along the way), that's OK -- that probably means you are using a TV as your monitor. Don't worry, just hit Ctrl-Alt-F1 to get to a text console login and proceed.

IMPORTANT: It drives me crazy to type sudo in front of every single command that requires root access. So, I will ASSUME that you will, right now, open up a Terminal, and type

sudo -i

in order to give yourself a nice root shell. I will not be putting the "sudo" in front of all of my commands in this HOWTO, since I find that to be overly laborious. For normal use, I am fine with sudo here and sudo there; but, when doing a large number of commands as we will be doing here, it gets a little tiring. There are situations in this HOWTO, though, were you need to be issuing the commands as the "mythtv" user. Things should be obvious from the context, but to help differentiate these situations, I will just use color:

commands to be issued by the root user look like this

commands to be issued by the "mythtv" user look like this

On to the fun!


2. Set up where to download packages and update (5 minutes)

Fire up your favorite editor (I use vi, but most people hate vi) with a command similar to the following:

gedit /etc/apt/sources.list

Uncomment lines 19 and 20 by removing the initial "#" mark. Also append the keyword "multiverse" at the end of each line. Also, uncomment lines 35 and 36, and make sure that these two lines also have "multiverse" at the end of the line; if not, put it there. Basically what you are doing here is to allow ubuntu to use download archives that are unsupported by the Ubuntu team (like MythTV, for obvious reasons). Finally, comment out the first line of your sources.list file, if it references the Ubuntu cdrom. My final sources.list file is here. Now, go to a command line and issue

apt-get update; apt-get upgrade

This will make sure that our apt repository database is up to date, as well as updating packages already installed on Ubuntu.

Here are some other packages that you will need to install for this all to go successfully:

apt-get install build-essential dialog apache2 mysql-server phpmyadmin gcc-3.4 
apt-get install libapache2-mod-auth-mysql
apt-get install dvdauthor mplayer-586
apt-get install ntp ntp-simple

During this installation, I just selected "No configuration" when questions about postfix popped up.

You can install the following packages at your discretion. The fonts, in my opinion, are needed, since the fonts in MythTV look a little ugly to me without them; trust me. The tcsh package is needed so that some scripts that I give you a good bit below will work; sorry, they use tcsh and not bash.

apt-get install gsfonts-x11 msttcorefonts
apt-get install tcsh
fc-cache -f -v

3. Install NVIDIA drivers (3 minutes)

For NVIDIA users only, obviously. The following commands worked just fine for me:

apt-get install nvidia-settings nvidia-glx linux-restricted-modules-686
nvidia-glx-config enable

If that doesn't work for you, hop over to BinaryDriverHowto/Nvidia - Ubuntu Wiki and follow the directions there for installation of your nvidia driver.

Reboot now. If you didn't have a graphical login before the reboot, you should now, after the reboot. If not, there is a problem.

4. Configure the database (MySQL) (1 minute)

MythTV uses MySQL extensively, so we have to get this set up before anything else. Fire up Firefox and in the address bar, type "localhost". Click the "phpmyadmin" directory. Type in "root" in the login form, and no password. Look down the resulting page for a "Change password" link, and click it; type in what you want your MySQL password to be. Note that this is *not* your root password, or your primary sudo account password. This one is separate, so make it whatever you want it to be. But remember it; we will need it later.

After the password is set, click the "Back" link (not the Back button in your browser). Click on the "Reload MySQL" link. Now, to verify that you password works, login again, using "root" as the user and your MySQL password that you just set; it should work. Logout from phpMyAdmin. Now try to log back in to phpMyAdmin using "root" and this time, no password. It should not let you in; done.

At this point, make sure you have logged out of phpMyAdmin.



5. Install IVTV (10 minutes)

5.1 Prepare the build environment

To me, this is the hardest part of getting the entire MythTV solution to work -- creating the build environment to be able to compile ivtv properly. It's not really ivtv's fault; it's just that pretty much all distributions nowadays require a certain amount of work out of you, if you are going to do plucky things like compile the kernel and/or kernel modules. Luckily, I've gone through some pain so that you don't have to.

First, type the following, and remember the output.

uname -r

For my system, the output is

2.6.12-10-686

It is important to remember both parts. The 2.6.12 is the kernel version (henceforth referred to as <kver>), and the -10-686 part is the extra tag. This will be important later. Now, to install the proper kernel source, execute the following command:

apt-get install linux-source-<kver> linux-headers-`uname -r`

where <kver> is replaced with your current kernel version that you found out from the uname -r command above. Recall that mine was 2.6.12.  And notice the backticks in the above command!  The tick used here is the one next to your 1 key, not the quote next to your Enter key.

Now that we have the source, we need to unpack it and configure its pseudo-location:

tar xvjf /usr/src/linux-source-*.tar.bz2 -C /usr/src/
ln -s /usr/src/linux-source-<kver> /usr/src/linux
ln -s /usr/src/linux /lib/modules/`uname -r`/build

Now switch to the /usr/src/linux directory:

cd /usr/src/linux

We need to make sure to remember our extra "tag" in the kernel source Makefile. Edit /usr/src/linux/Makefile with your favorite editor, and set the variable EXTRAVERSION (about the fourth line of the Makefile) to your "tag" that we found out from the uname -r command above. My tag was -10-686, for example. Therefore, the line in the Makefile should read something similar to:

EXTRAVERSION = -10-686

Now lets configure the source tree to get it ready for compiling, without actually compiling it:

cp /boot/config-`uname -r` /usr/src/linux/.config
make oldconfig
make prepare0
make scripts

Lastly, do the following:

cd /lib/modules/`uname -r`/
ls -l build

If this symbolic link points to /usr/src/linux, we don't have to do anything.  However, if it does not, manually delete it and make the link yourself:

rm build
ln -s /usr/src/linux build

Yay! We finally have our build environment ready. Now on to the compilation and installation of the ivtv drivers. 

5.2 Compile and install ivtv drivers - 0.4.1 drivers and later

IMPORTANT: If you want to use the 0.4.0 drivers, please do not follow the remainder of section 5 here!  Go to the 0.4.0 ivtv driver HOWTO and follow those instructions. 

Let's go the the ivtvdriver.orgsite and download the latest stable 0.4.x version of the ivtv drivers, and extract them (as of now, this is version 0.4.4).  NOTE that for Ubuntu Breezy, you cannot use the 0.6.x series of the driver; this is for kernels 2.6.16 and later. 

cd /usr/src
wget http://dl.ivtvdriver.org/ivtv/archive/0.4.x/ivtv-0.4.4.tar.gz
tar xvfz ivtv-0.4.4.tar.gz

64-bit users need to look here for further instructions.  Now, compile your ivtv drivers and utilities:

cd ivtv-0.4.4
make
make install

During your make install, it could be that the installer reports that there are conflicts for the files that it is trying to install. IMPORTANT: do not ignore these conflicts! After each conflict, it will tell you exactly the command to issue to "hide" the offending file. Execute each command it tells you, and rerun "make install" until there are no more conflicts.

In some rare cases (I don't believe that this will happen to you, but I am leaving this bit here just in case) the drivers end up installed in the wrong place; they land in /lib/modules/<kver>/ivtv rather than /lib/modules/`uname -r`/ivtv. So, check on this. If they are installed incorrectly, you can fix this just by copying

cp -r /lib/modules/<kver>/ivtv /lib/modules/`uname -r`/

The Hauppauge cards require firmware files, as the firmware is not stored in the ROMs on the card.  We must download and install these properly now.  To do this,

cd utils
wget ftp://ftp.shspvr.com/download/wintv-pvr_150-500/inf/pvr_2.0.24.23035.zip
wget ftp://ftp.shspvr.com/download/wintv-pvr_250-350/inf/pvr_1.18.21.22254_inf.zip
unzip pvr_2.0.24.23035.zip
./ivtvfwextract.pl pvr_1.18.21.22254_inf.zip
cp HcwMakoA.ROM /usr/lib/hotplug/firmware/v4l-cx25840.fw
cp HcwFalcn.rom /usr/lib/hotplug/firmware/v4l-cx2341x-enc.fw
mv /lib/modules/ivtv-fw-dec.bin /usr/lib/hotplug/firmware/
mv /lib/modules/ivtv-fw-enc.bin /usr/lib/hotplug/firmware/
cp ../v4l-cx2341x-init.mpg /usr/lib/hotplug/firmware
ln -s /usr/lib/hotplug/firmware/ivtv-fw-dec.bin /usr/lib/hotplug/firmware/v4l-cx2341x-dec.fw

After this set of commands, if you execute

ls -ltra /usr/lib/hotplug/firmware/

You should see

drwxr-xr-x 3 root root 4096 2005-12-18 10:04 ..
-rw-r--r-- 1 root root 262144 2005-12-23 20:05 ivtv-fw-enc.bin
-rw-r--r-- 1 root root 262144 2005-12-23 20:05 ivtv-fw-dec.bin
-r--r--r-- 1 root root 14264 2005-12-23 20:08 v4l-cx25840.fw
-r--r--r-- 1 root root 376836 2005-12-23 20:08 v4l-cx2341x-enc.fw
-rw-r--r-- 1 root root 155648 2005-12-24 13:33 v4l-cx2341x-init.mpg
lrwxrwxrwx 1 root root 41 2006-01-03 00:40 v4l-cx2341x-dec.fw -> /usr/lib/hotplug/firmware/ivtv-fw-dec.bin
drwxr-xr-x 2 root root 4096 2006-01-03 00:40 .

Now lets tell Ubuntu that we have ivtv modules. Edit /etc/modules, and just stick "ivtv" at the end of the file. Also edit /etc/modprobe.d/aliases, and put the following line in where it fits:

alias char-major-81-0 ivtv

If you have a PVR-500, you also need to add the following line as well:

alias char-major-81-1 ivtv

Then, do the following:

depmod
modprobe ivtv
dmesg

If, at the end of the output of dmesg, you see a section starting with ==START INIT IVTV== and ending with ==END INIT IVTV==, you are in good shape, as long as the text in between these markers is not filled with errors. Mine wasn't, so it was time to write this up and take a break.

5.3 Verification of IVTV drivers

This section is not meant to be exhaustive, but to cover a couple of steps that you can do to make sure that your ivtv drivers are working properly.  First, capture a raw MPG stream to a file:

cat /dev/video0 > /tmp/test.mpg
(hit Ctrl+C to stop the capturing)

and play the file using mplayer:

mplayer -vo xv /tmp/test.mpg

If you get a picture, that's great; time to move on to the MythTV install.  If not, it could be that the tuner is just not tuned to a viewable channel.  Shut down mplayer, and while that is running, let's use the command line utility ivtv-tune to change channels:

mplayer -vo xv /dev/video0
ivtv-tune -c # -d /dev/video0 (in a separate terminal/konsole)

Where "#" is replaced by the channel that you want to tune to.  If you have a PVR-500, you might want to try the same steps above, but with /dev/video0 replaced with /dev/video1.  If you are able to watch TV in this way, great!  Ivtv is working just fine.

6. Install and Configure MythTV (12 minutes)

6.1 Install the software

If you are a 64-bit user, the appropriate packages are not yet ready in the standard repositories; you need to compile MythTV from scratch.  Also if you want MythTV 0.19 (the latest and greatest), you will have to compile MythTV from scratch as well; skip to Section 9.8, follow the instructions there, and then return here.


If you are still in 32-bit land and want MythTV 0.18, we are ready to install the MythTV software. Execute the following:

cd ~
apt-get install mythtv mythbrowser mythdvd mythgallery mythmusic mythnews mythvideo mythweather
apt-get install mythweb mythtv-doc

Notice the absence of mythgame; for some reason, that package is not up to the same patchlevel as the others, and therefore will not install due to uninstallable dependencies. I still need to figure this one out.  

During this install process, you will be prompted for the MySQL password. For this, type in the password that you have in the phpmyadmin configuration step that you completed a couple of steps ago. The installer will also try to start mythbackend, but don't worry if it does not start; we still have work to do.

North American users: Create an account at http://labs.zap2it.com.  This is where you will download TV listings from; and this is a free service.  What it will cost you is filling out a short (about ten question) questionnaire about every four months or so.  In the "Certificate Code" field, enter ZIYN-DQZO-SBUT.  Remember your username and password that you used to create an account here; we will need this later.

European users (thanks to Kenneth Nielsen for this contribution): you need to download and configure xmltv-util

apt-get install xmltv-util
tv_grab_dk --configure (here, choose the proper tv_grab_* for your country)

The configuration will ask for the username and password for the website that is providing the listing information.  The web site address should be there in the configuration (for example, the Danish one is tv2.dk), so just go there and create an account, and use that username and password in the tv_grab_* configuration.

The mythtv install that you just ran automatically created a "mythtv" user. We need to change its password to something that we can remember (wow, lots of usernames and passwords to remember), so do that here:

passwd mythtv

Also, we want to make the mythtv user able to sudo things, so let's add him or her to the admin group. Edit the file /etc/group, look for the line that starts with "admin", and add ",mythtv" to the end of that line, no spaces. And hey, while we are at it, go ahead and do the same operation on the lines that start with "cdrom" and "plugdev". This gives the mythtv user access to the optical disks (you want to watch those DVD's, right?) and any pluggable storage devices such as USB sticks.

Log out from your current X session, and log back in as the mythtv user. At this point, do not open a "sudo -i" shell; we want the following command to be run using the mythtv user:

mythtv-setup

This will pop a graphical window for you to start configuring MythTV. I'll have to be honest and say that I didn't take very good notes here, but I don't remember doing anything at all on the first screen, except to verify that the mysql password that it already had was correct. Perhaps the next person going through this HOWTO can help me out here...

Anyway, once you get through the first little config screen, you will find yourself at a screen with things listed like "1. General, 2.Capture Cards" and so on. Select "General" and flip through the screens. I didn't change anything here, but just take a look to see if you do.  European users will likely have to change tv-format to PAL and the channel frequency to Europe-west.

After you get finished there, select "2. Capture Cards", and do the following:

New capture card--> 
Card type: MPEG-2 Encoder card (PVR-250, PVR 350)
Video device: /dev/video0
Default input: Tuner0

and then click the Finish button. If you have a PVR-500, I'm guessing that you want to also set up Tuner1 as well.  Hit ESC if necessary to get back to the main menu.

North American users: After you get finished there, select "3. Video Sources", and do the following:

New video source-->
Video source name: PVR-150-1
XMLTV listings grabber: NorthAmerica (DataDirect)
User ID: set_to_user_id_from_zap2it_site
Password: set_to_password_from_zap2it_site

Then, select "Retrieve Lineups", and within a short span of time (say 10 seconds or so) it should get the TV listings you configured over at the zap2it web site. Click the Finish Button, and hit ESC to get back to the main menu.

European users (thanks to Kenneth Nielsen for this contribution): select "3. Video Sources", and do the following:

New video source-->
Video source name: PVR-150-1
XMLTV listings grabber: tv_grab_dk (here, select your country-specific grabber)
User ID: set_to_user_id_from_zap2it_site
Password: set_to_password_from_zap2it_site

Then, select "Retrieve Lineups", and within a short span of time (say 10 seconds or so) it should get the TV listings you configured over at your listing web site. It has been reported that this process stops, so you may have to Alt-Tab to the terminal and put in your username and password (for the listings grabber) again.  Click the Finish Button, and hit ESC to get back to the main menu.

Now, select "4. Inputs", and do the following:

Tuner0-->
set video source to PVR-150-1

Again, if you have a PVR-500, I'm guessing that you will set up Tuner1 to point to the same video source.  Click Finish, and hit ESC to get back to the main menu. Hit ESC once more to quit this initial MythTV configurator. Now, run

mythfilldatabase

which will populate your database with listings. This takes quite a while; around five minutes. You may see a few "Unauthorized" errors floating across, but it is OK to ignore these.

I have seen a couple of HOWTOs advise you to turn off the sound server, using System->Preferences->Sound->uncheck "Enable Sound Server Startup". I didn't, and I see no ill effects. However, if you have problems with your sound in MythTV, you might want to try this. [UPDATE: I don't know the event that caused it, but MythTV reported to me that it lost connection to the sound driver, and could continue without sound. I have since disabled the sound server for the mythtv user. Shame...I kind of liked those Ubuntu sounds.]

Let's fire up MythTV for a test run:

mythbackend &
mythfrontend

At this point, you should see MythTV pop up, and you can start playing with it. Most importantly, just go to "Watch TV" and see if you have anything. You should! If not, perhaps you missed a step above, your hardware is not connected (i.e., no coax connected to your tuner card or other silly thing), or, there is a problem that you need to start troubleshooting. Google is your friend!

6.2 Troubleshooting

If MythTV is not working for you at this point (the most common problem is that there is no picture, or just static, we need to try a couple of troubleshooting steps.  As long as you went through section 5.3 to verify your IVTV configuration, we know that ivtv is working; the problem must be with the configuration of MythTV.

One of the first items to check is whether or not the mythtv user can access the sql database.  If you can type

mysql -u mythtv -p mythconverg

and after keying in the mysql password you get a "mysql>" prompt, then you are OK.  Type "quit" to get out of mysql.

UNDER CONSTRUCTION.  Until I get some text here (and even when I do), the best place to go for MythTV is mythtv.org (documentation section), and the MythTV users discussion list at http://www.gossamer-threads.com/lists/mythtv/ and http://www.mythtv.org/mailman/listinfo/mythtv-users/.

6.3 Finalizing the Installation

For a nice, usuable system, you want mythbackend to start during the booting sequence, and mythfrontend to start automatically whenever the mythtv user logs on. First, the backend; as far as I can tell, the mythtv-backend script installed in /etc/init.d just doesn't work as advertised. I had to hack mine to get it to work, by replacing their fancy "start-stop-daemon" line in the start) clause with the following lines:

 su - mythtv -c "mythbackend -d"
su - mythtv -c "mtd --daemon"

and I also replaced their fancy "start-stop-daemon" line in the stop) clause with the following line:

 pkill mythbackend 
pkill mtd

On top of this, I just commented out their restart) clause completely. If you like, you can just grab my mythtv-backend script (instead of making the above modifications) and place it into /etc/init.d. As root,

 cd /etc/init.d
wget http://s91928265.onlinehome.us/hfamily/mythtv/mythtv-backend
chmod a+rx mythtv-backend

Now, for mythfrontend. The most popular method out there in the other HOWTOS seems to be to use the .xsession file to start up mythfrontend when the mythtv user logs in. My problem with that procedure is that the normal window manager doesn't even appear to start up, so it's difficult to fire up a quick terminal and do anything while myth is running; I find that annoying. I think that it's better to go to System->Preferences->Sessions, and select the "Startup Programs" tab [NOTE: Kubuntu users will have to try to find an equivalent place to do this]. In there, put all of the following

:sessions dialog

From now on, if you log in as the mythtv user, you will be immediately greeted by the friendly MythTV interface. And sorry about mixing in other things that belong in a different topic. The "xset" commands are there to make sure that the screen doesn't blank after an amount of time, which would be incredibly annoying while watching TV. The "irexec" command allows us to map remote keys to various functions as we need, outside of MythTV. I'll use this later for power button functionality.

For MythWeb (the nice web interface to MythTV), we need to set the mysql password. Edit the file /usr/share/mythtv/mythweb/config/conf.php, and look for the line that defines the db_password. Change the text in the single quotes to the password that you used when setting up MySQL via phpMyAdmin. And for some strange reason, the file /etc/mythtv/mythweb-settings.php did not have read permissions for world. I think that I caused this from some other monkeying around that I did, but if MythWeb does not work for you out of the box, try

chmod a+r /etc/mythtv/mythweb-settings.php 

Also, the default memory settings in /etc/php4/apache2/php.ini tend not be be high enough, especially as your database gets large. Edit this file, find the setting called "memory_limit" and set it to "32M". The restart the apache server with

/etc/init.d/apache2 restart

When playing DVD's, we probably don't want the default Ubuntu action, which is to mount the DVD as a filesystem under /media.  It doesn't stop Myth from being able to play the DVD, but does keep us from being able to easily eject it when we want our DVD back.  To keep this annoying behavior from happening, as the mythtv user, navigate to System->Preferences->Removable Drives and Media, and uncheck "mount removable media when inserted".  Then, in the same dialog, click on the "Multimedia" tab.  Uncheck both "play video DVDs when inserted" and "play audio CDs when inserted".

7. Remote Control (LIRC) (5 minutes)

These directions assume that you have a Hauppauge gray remote, as the retail PVR-150 package provides (not the MCE package; it doesn't come with a remote). If you have a different remote, I think that the directions are exactly the same until the point at which I tell you to download my personal lircrc file and install it; you will have to find your own, or modify mine to suit. Also, you would probably have to choose a different remote in the lirc ./setup.sh stage (below).

Download the latest version of lirc (0.7.2 at the time of this writing) from the official LIRC web site, and save it in /usr/src. Unpack it and run its setup with

cd /usr/src
tar xvfz lirc-0.7.2.tar.gz ---or--- tar xvfj lirc-0.7.2.tar.bz2 (as appropriate)
cd lirc-0.7.2
./setup.sh

Choose the Driver configuration-->TV Card-->Hauppauge TV Card, then select "Save configuration and run configure". After configure is done, build your drivers:

make
make install

Edit /etc/modprobe.d/aliases, and put

alias char-major-61 lirc_i2c

where it "fits"; you will see what I mean. Also put "lirc_i2c" at the end of /etc/modules. Now test:

depmod -ae
modprobe lirc_i2c
chmod 666 /dev/lircd
lircd
irw

With irw running, press a few buttons on your remote. Obviously, the infrared receiver dongle should be plugged into your PVR-150 by this point, and you should be aiming at the business end of the dongle. If you get a few hex codes as well as the button being pressed, excellent!

** PVR-150 specific **

Now we have the remote working, but we still need to map the keys of the remote to keystrokes within myth and xine. Grab my lircrc-haupgrey-g3.txt file, and place it in /etc:

cd /etc
wget http://s91928265.onlinehome.us/hfamily/mythtv/lircrc-haupgrey-g3.txt

Note that this mapping file is specifically for the grey remote shipped the retail version of the Hauppauge PVR-150 card. If you have a different remote, now is the time to search the web for a corresponding lircrc file, or you can configure your own, using my lircrc-haupgrey-g3.txt file as a model; it's really not that hard.

Now that you have my remote config file (lircrc-haupgrey-g3.txt) in /etc, do the following:

su - mythtv
ln -s /etc/lircrc-haupgrey-g3.txt .lircrc
cd .mythtv
ln -s ../.lircrc lircrc
exit

Lastly, now that we have lirc working, we need to make sure that it gets started at boot. I used a script provided from the abarbaccia site (I hope that Andrew doesn't move it; if so, I will provide it) [UPDATE: it apparently has been moved, so here is my lirc file. This was posted hastily way after the fact, so you may want to look through it and make sure it is referencing the correct lirc binaries as well as the right device]. to accomplish this:

wget http://www.abarbaccia.com/mythtv/lirc
mv lirc /etc/init.d/lirc
chmod 755 /etc/init.d/lirc
update-rc.d lirc defaults 99

Done; not too bad, all told. Well not really; I have horrible problems with my remote conking out every so often (quite often, actually). A band-aid that will keep it working (for the most part) is to reset the IR registers in the IVTV driver every minute (yeah, I know!). Add the following line to your /etc/crontab IF you have this problem:

*/1 * * * * root /usr/local/bin/ivtvctl --reset-ir >& /dev/null

[Update: with ivtv 0.4.2, I do not believe this is necessary; since the switch to ivtv 0.4.2, I have had no remote problems]

8. Modifications for Usability

This section is entirely optional, but can make your experience with MythTV a little (or in some cases, a lot) better. If you have just finishing slogging through the entire installation, I would recommend just playing with your new toy right now, and come back to this section later.

8.1 Turn off the screen saver

We don't want screen savers activating while we are watching TV, so while logged as the mythtv user, navigate to System->Preferences->Screensaver, and disable the screen saver. Then flip to the "Advanced" tab in that same dialog, and turn power management off.

8.2 Automatically login the mythtv user at boot

When you boot your machine, it would be nice if it would go straight to MythTV; however, at this point, it boots to the graphical login screen. This is easy to fix; just edit /etc/gdm/gdm.conf, change the AutomaticLoginEnable and AutomaticLogin variables to:

AutomaticLoginEnable=true
AutomaticLogin=mythtv

8.3 Use of the OK button while in EPG

I didn't like that the OK button while in the EPG took you to record options. I wanted it to let me watch the show. Go to Utilities/Setup-->Setup-->TV Settings-->Program Guide, page 2, and check "Use select to change the channel in program guide".

8.4 Replace MythDVD

Apparently, there is a build problem with the currently shipping mythdvd package; it is compiled without the transcoder, so it does nothing. Our good friend Andrew, though, has a correctly built binary, and therefore, the solution:

wget http://www.abarbaccia.com/mythdvd_0.18.1-4_i386.deb
sudo dpkg -i mythdvd_0.18.1-4_i386.deb

8.5 Use Xine as the DVD player

Personally, I don't like mplayer for usage as a DVD player, because it does not have support for DVD menus. Xine does. So, I first installed xine:

apt-get install xine-ui

and then went to Utilities/Setup-->Setup-->Media Settings-->DVD Settings-->Play Settings, and typed in

xine -pfhq --no-splash dvd:// 

Similarly, I also set xine as the player for my video files; go to Utilities/Setup-->Setup-->Media Settings-->Videos Settings-->Play Settings, and put in

xine -pfhq --no-splash %s

Note that in my personal lircrc file (see the remote section), I have also included keymappings for the xine player; so, your remote should work for xine as well.  Note that the first time xine gets run, it will pop a rather unattractive configuration dialog.  Just close it; it won't happen again.

Now one last thing; when xine quits, the mouse focus might stray back the desktop, which forces all keyboard input (which your remote really is, to MythTV anyway) to go there. To fix this, go to System->Preferences->Windows, and check both "select windows when the mouse moves over them" and "raise selected windows after an interval". That makes the user interface, while you are logged in as the mythtv user, really annoying to deal with, but that does save us from recompiling xine. If you really hate this, hop over to Andrew's excellent site and look in his "Misc" section for how to recompile xine.

If you are outside the US, you may install a library which will allow you to watch all of your rightfully purchased DVD's:

/usr/share/doc/libdvdread3/examples/install-css.sh

We also would like to enable xine to play DivX,  AVI, WMV, etc.  Again if you are outside the US, you may install codecs that allow this:

wget ftp://cipherfunk.org/pub/packages/ubuntu/pool/main/w/w32codecs/w32codecs_20050412-0unofficialubuntu2_i386.deb 
dpkg -i w32codecs_20050412-0unofficialubuntu2_i386.deb

If DVD playback is jerky, make sure that you have DMA turned on for the DVDROM in question. First, type

hdparm /dev/hdd

where "/dev/hdd" is replaced with the appropriate device; look in /etc/fstab if you don't know which device your DVDROM is. If you get a line that says "using_dma = 0", you need to turn it on. Add the following to the end of your /etc/hdparm.conf file:

/dev/hdd {
dma = on
}

Where again, /dev/hdd is replaced by the device that you are trying to change. Reboot for the change to take effect.  Be careful to verify that your drive still works at all after you do this, though.  Certain drives do not play well with DMA.  If that is the case for your drive, it might be time for a new DVDROM drive.

8.6 Create JumpPoints in MythTV

We do this so that the "Video", "Radio", etc. buttons will work on the remote. Download my jumppoints.sql script and run it with the following command:

wget http://s91928265.onlinehome.us/hfamily/mythtv/jumppoints.sql
mysql -u root -p < jumppoints.sql

If you don't like the way I mapped the keys, just modify the script and rerun. There are actually a few ways of setting the JumpPoints, most notably through the MythWeb interface, and you can also do it with phpMyAdmin. But, this is quick and simple, so I like it.

8.7 Install the MythCenter theme

I personally like the MythCenter theme, though this just a matter of taste. If you want it, go to http://www.fotoniq.nl/projects/mythtv/ and follow the directions. It's simple. Here is what it looks like on my box:


8.8 Configure the power button on the remote

For this, all you have to do is download a couple of scripts that I have written and/or modified, and put them both in your /usr/local/bin/directory:

cd /usr/local/bin
wget http://s91928265.onlinehome.us/hfamily/mythtv/mbe.keepup.sh
wget http://s91928265.onlinehome.us/hfamily/mythtv/mythpowerbutton.sh
chmod a+rx mbe.keepup.sh
chmod a+rx mythpowerbutton.sh

As long as you used my lircrc-haupgrey.txt file (in the LIRC step), the mappings are already there for the power button to work immediately. This script will kill the frontend if it is running (and leave the backend alone), or, if the frontend is not running, it will start both the backend (if necessary) and the frontend. Note that for this to work, you should have placed "irexec" in the auto-run section in System->Preferences->Sessions for the mythtv user (done in a previous step).

8.9 Making sure the mythbackend stays up

OK, I'll admit that I'm a little overboard on not wanting to miss any recordings.  I run a script every three minutes to make sure that the backend is still up, and restart it if it is not.  You already have this script if you already did the "Configure the power button on the remote" step above, but just in case, we will re-fetch the required script:

cd /usr/local/bin
wget http://s91928265.onlinehome.us/hfamily/mythtv/mbe.keepup.sh
chmod a+rx mbe.keepup.sh

And now, add the following line to your /etc/crontab:

*/3 * * * * mythtv /usr/local/bin/mbe.keepup.sh cron >& /dev/null

8.10 Smoother video playback (optional)

To allow the video playback thread to be scheduled higher in the priority list than normal, we can set the SUID root bit on mythfrontend:
chmod +s /usr/bin/mythfrontend

There are security issues with doing this, but as my box is behind a hardware firewall, I don't worry about it too much. If my firewall has been breached, I have many worse things to worry about.

8.11 Automatically start computer upon power restore

If the power goes off, hopefully you have a battery and have installed drivers so that Ubuntu will shut down cleanly. Regardless, when the power returns, you probably want your computer to go ahead and turn on as well, booting back to the MythTV interface.

In the BIOS, find the setting which ensures that the computer returns to a power on state each time it is plugged in. This way, if the electricity goes out, the computer will automatically restart and return to MythTV.

8.12 Automatically back up the MythTV database daily

If you ever lose your MythTV database, you will be very sad; it contains all MythTV settings, as well as records of every program that you have watched, the programs you have recorded, etc. etc.  Backing up is easy to do, especially since I have a small script that will do it for you.

cd /usr/local/bin
wget http://s91928265.onlinehome.us/hfamily/mythtv/backup.database.sh
chmod a+rx backup.database.sh

Now, etc /etc/crontab and add in the following line:

30 12 * * * mythtv /usr/local/bin/backup.database.sh /scratch/dbbackup >& /dev/null

Where you change the directory /scratch/dbbackup to wherever you want the backup files to go.  Make sure that this directory is writable by the "mythtv" user.

8.13 Making a simple DVD

It's a shame that DVD burning isn't integrated directly with MythTV.  So, we have to do a bit of work to make our recordings portable.  First, we need dvdauthor:

apt-get install dvdauthor

I have a couple of handy scripts that will make a DVD iso file for you, ready for burning via whatever software you like.  These DVD's are not fancy; just functional.  No menus, just the shows.  Here are the scripts:

cd /usr/local/bin
wget http://s91928265.onlinehome.us/hfamily/mythtv/makedvd.sh
wget http://s91928265.onlinehome.us/hfamily/mythtv/mythshows.sh
chmod a+rx makedvd.sh
chmod a+rx mythshows.sh

Note that you will need to manually edit "mythshows.sh" and set the path to your recordings properly.  It's in the $path variable.
To use makedvd.sh, simply type

makedvd.sh nuvfile1 nuvfile2 nuvfile3... dvdprojectname

The output file will be named dvdprojectname.iso, which you can use in any DVD burning software package to make your DVD.  There is one sticky issue though -- we usually know the name of the show we want to burn, but not exactly what .nuv file that one is.  That is where the "mythshows.sh" script comes in.  This script digs into your MythTV database, and shows you the mapping between each show and its .nuv filename.  You can then pipe this through grep, for example, to isolate what you want.  For example,

mythshows.sh | grep CSI

On my system produces

/scratch/video/recordings/1013_20050427220100_20050427230000.nuv : CSI: NY [Supply and Demand] 
/scratch/video/recordings/1026_20051225230000_20051226000000.nuv : CSI: Miami [After the Fall]

If I wanted to create an burn-ready ISO from these two shows, I would do

makedvd.sh /scratch/video/recordings/1013_20050427220100_20050427230000.nuv \
/scratch/video/recordings/1026_20051225230000_20051226000000.nuv csi

Since I never burn the DVD directly from my Ubuntu linux box, I am a little unsure of the next step.  But, if I read the man pages correctly, you should be able to burn your DVD with the following command:

growisofs -dvd-compat -Z /dev/dvd=csi.iso

8.14 Adding a second PVR-150 card to an existing setup

Here, I am adding a Hauppauge PVR-150 MCE to an existing MythBox; already present is a Hauppauge PVR-150 retail.  I am just using a coax splitter to route one coax input to each card; so both cards will see exactly the same channels and will therefore have the same channel listings. 

This is pretty easy; first just power down your MythBox, and insert the new piece of hardware.  Power up, and as the root user, add the following line to /etc/modprobe.d/aliases:

alias char-major-81-1 ivtv

Note that if you already have multiple tuners in your system, you will need to be incrementing the last number (i.e., char-major-81-2) to one greater than what was there previously.  Now, reboot.  When the machine comes back up, type

dmesg

and look again, like we did in section 5.2, between the ==START INIT IVTV== and ==END INIT IVTV==  lines to make sure that we now have the correct number of cards detected.  In my case, I had two cards (my PVR-150 retail and the PVR-150 MCE).  Assuming that we are OK up to this point, we need to go ahead and shut down the MythTV frontend and backend (make sure you don't have anything recording right now!):

pkill mythbackend
pkill mythfrontend

Also, if you followed my "Making sure mythbackend stays up" tutorial above, it would be wise to comment out the line in the crontab that will restart mythbackend every few minutes, temporarily.

Now, as the mythtv user, run mythtv-setup:

mythtv-setup

At this point, I chose to leave my existing card settings alone as well as my channel settings alone.  After these first two initial screens, select "2. Capture Cards", and do the following:

New capture card--> 
Card type: MPEG-2 Encoder card (PVR-250, PVR 350)
Video device: /dev/video1
Default input: Tuner0

and then click the Finish button (note again, that if you have multiple tuners already, /dev/video1 might not be the right one to pick), and hit ESC to get back to the main menu.

Now, select "4. Inputs", and do the following:

Tuner1-->
set video source to PVR-150-1

Finally, fire up MythTV and take a look around.  Done.

sudo /etc/init.d/mythtv-backend start
mythfrontend &

Remember to fix your /etc/crontab back up if you modified it.

8.15 On-Screen Machine Status Information

I like to know status information about my box, quickly and easily.  I wrote a small script to generate the text I was interested in, and display it as an overlay for a few seconds on the MythTV screen while you are watching either TV or a recording.   To do the same, you can download my small script, modify it to suit your needs, and it should work just fine; I have already mapped the blue button on the remote control to run /usr/local/bin/osd.sh (make sure you downloaded my lircrc-haupgrey-g3.txt file sometime after 1/24/2006), so all you need to do is download my script and place it there.

cd /usr/local/bin
wget http://s91928265.onlinehome.us/hfamily/mythtv/osd.sh
chmod +x osd.sh

That's it; just customize osd.sh to output the information you are interested in.

8.16 Get Channel Icons in your EPG

In the MythTV Electronic Program Guide, you may not see any icons for your channels.  To get these, do the following:

mkdir /opt/src/mythtv
cd /opt/src/mythtv
apt-get source mythtv
apt-get install xmltv
./mythtv-0.18.1/contrib/mkiconmap.pl
mythfilldatabase --import-icon-map iconmap.xml --update-icon-map

8.17 Install vobcopy

I've found that there are several DVD's that won't rip with the built-in MythTV tools, but will with the nice and simple "vobcopy" utility.  To install this, 

apt-get install vobcopy

8.18 Install and configure nuvexport

8.18.1 Install the nuvexport utility

This is a handy tool to export your recordings to an external format.

apt-get install libdate-manip-perl mjpegtools
apt-get install transcode lame mencoder-586
wget http://forevermore.net/files/nuvexport-latest.tar.bz2
tar xvfj nuvexport-latest.tar.bz2
cd nuvexport-0.3/
make install
chown mythtv /usr/share/mythtv/mysql.txt
vi /usr/share/mythtv/mysql.txt, and enter in sql root password

There are some problems with the generally available version of ffmpeg.  So, we want to first make sure that the stock ubuntu ffmpeg is uninstalled, and then compile our own in its place. 

8.18.2 Reinstall ffmpeg from my binaries

At this point, you have two choices: recompile ffmpeg from scratch, or download and install my binaries.  You can simply download  my binary debian install packages as shown below with BitTorrent.  If you don't want to do this, simply skip directly to section 8.18.3 now.

cd ~
mkdir ffmpeg_bins
cd ffmpeg_bins
wget http://s91928265.onlinehome.us/hfamily/mythtv/ffmpeg.torrent
btdownloadcurses ffmpeg.torrent
apt-get remove ffmpeg
dpkg -i *.deb

If the download does not progress, it means that I don't have my BitTorrent client running, and/or there are no others with the file who do.  Be patient,

8.18.3 Reinstall ffmpeg from a fresh compile

If you don't want to download my binaries but would rather compile, continue on.

apt-get remove ffmpeg

Now, let's download and compile the source to ffmpeg manually:

mkdir -p /opt/src/ffmpeg
cd /opt/src/ffmpeg
apt-get source ffmpeg
apt-get install liblame-dev libsdl1.2-dev faac libimlib2-dev libfaad2-dev libfaac-dev
apt-get install fakeroot debhelper
apt-get install liba52-dev libdts-dev texi2html libraw1394-dev libdc1394-13-dev libtheora-dev libgsm1-dev
apt-get install libxvidcore4-dev
cd ffmpeg-0.cvs20050918/debian/

At this point, edit the debian "rules" file, and add the following line *after* all of the other "confflags += " statements:

confflags += --enable-mp3lame --enable-xvid --enable-faad --enable-faac

Now, build the debian package.

cd ..
dpkg-buildpackage -rfakeroot -b

This should compile the package, and deposit four .deb files in the directory /opt/src/ffmpeg.  If you get a complaint from dpkg-buildpackage that you have unsatisfied dependencies, just install them with an "apt-get install <packagename>" and try again.  Finally, install the debian packages with 

cd /opt/src/ffmpeg
dpkg -i *.deb

UNDER CONSTRUCTION:  There is still a problem with yuvdenoise, so you HAVE to answer "No"  to the "enable noise reduction" for nuvexport to work at all.  Still need to compile and install lvemux and avidemux2.

Formats that currently appear to work are: XviD, DivX, SVCD, VCD, DVCD, DVD, ASF, and .nuv->.sql.  Formats that are disabled are MP3, PSP,  iPod,  and MPEG2->MPEG2 cut only.



9. Related Tips (Advanced)

9.1 Resizing an EXT3 partition

My original MythTV setup was Fedora Core 3, and the root partition was on a 40GB ext3 partition, on a 40GB disk. All other disks were already in use for video storage. So, I needed to resize the existing 40GB partition down to 20GB in order to make room for my Ubuntu installation. This turned out to be harder than I expected.

I popped in my System Rescue CD, booted from it, and ran "run_qtparted". Nothing doing; qtparted apparently does not yet support resizing ext3 partitions. Drat. On top of that, the ext2 tools already available on the system rescue cd did not seem to support ext3 (the journaling) either. So, it occurred to me to copy all of the ext2 tools from in the fedora install into /tmp (still operating under the System Rescue CD's OS), and try these versions. That worked....in a nutshell, I mounted the fedora root filesytem under /fedora, copied /fedora/bin/resize2fs, /fedora/bin/tune2fs/, and /fedora/bin/e2fsck to /tmp. Then, ran "ldd" on each of these binaries, and copied each needed library (except for ld-linux.so and libc.so) from /fedora/lib/ to /tmp. Then did "export LD_LIBRARY_PATH=/tmp", and tried running one of my newly copied utilities in /tmp. Lo and behold, it worked!

To resize the partition now, I ran resize2fs to resize the filesystem to 19GB, and then ran fdisk to delete partition 1 (the partition that the filesystem in question was on), and recreated a new partition to start at the same cylinder, and run to a size slightly greater than 19GB. That worked well; I rebooted with no problem.

9.2 Migrating an existing MythTV database

In my case, I already had been using MythTV for a while, so I had an existing database to move to my new system. To do this, as root on the "old machine",

mysqldump -p mythconverg > /mythdb.sql

Then after rebooting to be the "new machine", sudo to root, and

mysql -p -f mythconverg < /mythos1/mythdb.sql

where my old machine's / was mounted under the new machine's /mythos1. At any rate, you get the point; just dump the old database to file, and then dump that file into your new database. I did this after I had already configured the new machine's database a bit; the mythconverg database already existed in mysql. If it had not, then

mysqladmin create mythconverg

would have created a fresh database for me.

9.3 Dealing with GRUB

If you already have other Linux distros on other partitions (such as if you are switching from an existing MythTV setup to Ubuntu, and still trying to preserve the old distro), you will probably have to deal with GRUB to still be able to boot the old distro. This isn't too hard; just edit the /boot/grub/menu.lst file to add in the appropriate lines to reference your old distribution. That's it; nothing else to rerun or do. In addition, make sure that the "default" variable is set to the distribution that you want to boot if there is no interaction from the user at grub-boot time. If you are unsure about what lines to add to your menu.lst file, look in your OLD menu.lst file from your old distribution (some distributions, like FC3, store this in /etc/grub.conf, as well). So, just mount your old distribution under some directory (say /mythos1), and take a look, like this for example:

mkdir /mythos1
mount /dev/hda1 /mythos1
cat /mythos1/etc/grub.conf

where /dev/hda1 is replaced by the device on which the root directory (/) of your old linux distribution resides.

9.4 Repairing your MySQL database

If you believe that your sql database is corrupt, first make sure that there are no applications accessing it.  You can do this by shutting down mythfrontend and backend, as well as mythweb.  Then, execute the following command to repair it:

mysqlcheck -p -r -u mythtv mythconverg

I had to do this once, when MythTV couldn't seem to figure out how long my recordings were.  The fast forwarding went completely haywire, and it was fixed by doing this.

9.5 Using LVM to create logical volumes

9.5.1 Initial Setup of LVM drives

Why do this? Short answer is that MythTV only allows one path to store your recordings in, and you are bound to fill up whatever drive on which that path exists (my personal path is /scratch/video). So, it would be very nice to be able to grow that particular partition as your needs require, and that is exactly what LVM does for us. Let's say we created a 100GB partition for storage of recordings, and we fill it up. To enlarge that partition to 400GB, just buy a new 300GB hard drive, pop it in, type a couple of commands, and we're done. Nice, huh?

OK, to create our initial volume group and logical volume (which, for now, will consist of just one partition), and create an XFS partition on top of this, we just do:

pvcreate /dev/hdb1
vgcreate mythvg /dev/hdb1
lvcreate -L110.78G -nmythlv mythvg
mkfs.xfs /dev/mythvg/mythlv
mkdir /scratch
mount /dev/mythvg/mythlv /scratch

In the above commands, you need to replace /dev/hdb1 with the proper device name (or even /dev/hdb, for example, if you want to take the entire drive as opposed to partition one of that drive), and replace the 100.78GB size with the size of the partition or disk as appropriate, and the path /scratch with the path that you want your logical volume to be mounted. Also, you will need to add the following line to your /etc/fstab file:

/dev/mythvg/mythlv /scratch xfs defaults 0 0

We want the mythtv user to be able to write to this partition, so as long as we added the mythtv user to the "admin" group in the MythTV setup step, we can do the following:

chgrp admin /scratch
chmod g+rxw /scratch

Where "/scratch" is replaced by the path that you mounted your logical volume to.

9.5.2 Add a new drive to an existing LVM setup

Later on, should you want to add a new hard drive to this logical volume, just do the following (here, I am adding the entire 300GB drive /dev/sda to the LV):

umount /scratch 
pvcreate /dev/sda
vgextend mythvg /dev/sda
lvextend -L+279.3G /dev/mythvg/mythlv
mount /scratch
xfs_growfs /scratch

That's it! One thing to remember when choosing the size (in this case, 279.3G), is that hard drive manufacturers measure gigabytes as 1,000,000,000 bytes, and everyone else measures a gigabyte as 1,073,741,824 bytes.  So, if you buy a 300GB drive, the most space you will get out of it is approximately  93.1% of it, or 279.3 GB.

9.5.3 Replacing a drive in an LVM setup with a new (larger) drive

In my case, I was replacing a 120GB drive, on /dev/hdc with a new 250GB drive which I hooked up and had running, so it happened to be on /dev/hdb.  First, we need to make sure the appropriate kernel modules are loaded; in Ubuntu, they are not by default, so we have to do this manually:

modprobe dm_snapshot
modprobe dm_mirror

As a preparation step, you should unmount the filesystem that your logical volume is mounted to.  First kill off all processes that are actively using that mount (for me, I killed mythfrontend, mythbackend, and shut down samba), and unmount it:

umount /scratch

where /scratch was where I had the logical volume mounted; obviously, this might be a different mount point for you.  Now, prepare your new disk and add it to your existing volume group:

pvcreate /dev/hdb
vgextend mythvg /dev/hdb

where, of course, /dev/hdb is device name of the disk you are trying to add.  Now, move the data (high risk operation: if you lose power during this, your entire logical volume is likely to be hosed):

pvmove /dev/hdc /dev/hdb

where /dev/hdc is your old drive, and /dev/hdb is your new drive.  As always, choose these to match your particular system.  Note that pvmove takes a long, long time (moving a 120GB extent took me about 2.5 hours), but it will report its progress.  After we sweat this out, it is time to remove your old disk from your volume group:

vgreduce mythvg /dev/hdc

Now that we have replaced the disk successfully, the procedure is just like adding a new drive; we need to grow our logical volume a bit to utilized the unused extents of our new drive, and then grow the xfs filesystem also:

lvextend -L+122.0G /dev/mythvg/mythlv
mount /scratch
xfs_growfs /scratch

Note that the size that I chose here is roughly the difference between the old and new drives (250GB-120GB), multiplied by 93.1%.  Note that the old disk can now be physically removed from the system (after a power down) or reallocated to serve whatever purpose you wish; it is no longer a part of your mythlv logical volume.

9.5.4 Removing a disk from an LVM setup

Personally, I have not done this.  But, this seems to be documented well at http://www.tldp.org/HOWTO/LVM-HOWTO/removeadisk.html.  This covers the removal of a disk from a volume group, provided that you have enough empty space on other disks to cover the data move (for example, if your logical volume only has 10GB free, you can't remove a 120GB disk for obvious reasons...you would need at least 120GB free).

This doesn't, however, cover what to do with xfs.  As I understand it, the xfs filesystem is not shrinkable, so that is probably a showstopper to having an "easy" way to pull a disk out of an LVM setup.  The obvious solution is to completely copy all data off of your logical volume to somewhere else (either non-LVM'ed disk, or somewhere else on your network), and completely nuke and recreate your logical volume from scratch using section 9.5.1.   Of course, then you have to have enough disk space somewhere else to do this.

9.5.5 Need-to-know LVM tips

Now for one last tip. Should it happen sometime in the future that you want to access your logical volume, and /dev/mythvg/mythlv does not exist, don't panic! This is possible particularly when you are booting another distribution of Linux (such as SystemRescueCD). Your data is probably safe and sound; just issue the following two commands:

vgscan
vgchange -a y

and then check to see if /dev/mythvg/mythlv exists. If it does, you are good to go; mount /dev/mythvg/mythlv to some path somewhere, and use it.

9.6 Monitoring your CPU temperature

Your MythBox will be running, most likely, 24/7.  We need to make sure we place our box in a cool, well circulated environment, and to verify that the system is not running too hot, we would like to monitor the built-in sensors on the motherboard.  I'll offer what I did here, knowing that it might not work at all on your system -- motherboards will vary widely between all users reading this.  But just FYI, here is all that it took for me:

apt-get install lm-sensors
sensors-detect

In sensors-detect, I answered the default responses to everything.  When sensors-detect ends, it will leave you with a "--cut here--" bit of text.  Swipe all text between these two markers, and paste that into your /etc/modules file.  Then run

depmod -ae
modprobe i2c-sensor
modprobe my_module1
modprobe my_module2
....

Thereby "modprobing" every new module that just got put in /etc/modules.  Now test to see if everything works:

sensors

Should give you a block of output with your temperatures, fan speeds, etc. detected.  Here is where I quit, but doing a search on "lmsensors" with Google will yield ways to fine tune your /etc/sensors.conf to match your particular configuration.    Note that the labels in lmsensors are a bit artificial, if I understand correctly; even though an output is labelled "CPU Temp"  doesn't necessarily make it so.

I put together a little script that would monitor the stats I was interested in, and I run it every four minutes.  You can download and install this as you like, but you will probably have to modify it to suit your needs.

cd /usr/local/bin
wget http://s91928265.onlinehome.us/hfamily/mythtv/monitor_sensors.sh
chmod a+rx monitor_sensors.sh

Now, etc /etc/crontab and add in the following line:

*/4 * * * * root /usr/local/bin/monitor_sensors.sh >& /dev/null

This will simply dump a /tmp/sensor.log file, which can can view every now and then to see the trends in the CPU temp.

9.7 Installing APC Battery Backup Software

OK, this is unrelated to MythTV, but I hope that you do have a battery backup for those times that the power company fails you, as well as to provide steady power to your box. The software enables your machine to go through clean shutdown when the power is off for a configurable amount of time. I have an APC Back-UPS ES 500 (usb connected), so I will go through what it takes to install the APC management software, specifically for this model. Your installation should be the same, as long as your UPS is USB connected. If not, please refer to the References section below, and go to the apcupsd website for documentation.

Before you even get started, try

cat /proc/bus/usb/devices

If you can't find your APC device within the list output by this command, stop and connect it (remember, USB). If it is still not there -- sorry, I can't help you! Once you are confident that the APC device is recognized, install the software:

apt-get install apcupsd

Now, edit the apc configuration file at /etc/apcupsd/apcupsd.conf. Scan through this file, making sure that the these particular settings are like this:

UPSCABLE usb
UPSTYPE usb
DEVICE

(yes, make sure that DEVICE is set to nothing). Now edit /etc/default/apcupsd, and set ISCONFIGURED to yes. Start the apcupsd daemon:

/etc/init.d/apcupsd start

Now type

apcaccess status

and if you get a batch of output telling you information about your UPS, you're done! At this point, you can either stop, or go to the Apcupsd daemon for controlling APC UPSes site (click on documentation) to further fine tune the behavior of your battery backup. I found the defaults fine for me, so I stopped here.


9.8  Upgrading to MythTV 0.19

A quick note regarding this section; I have compiled a great many things on this box in the course of trying to make my MythBox has useful as possible.  As such, I might have installed something that is needed below to compile, but as I already had it there, there would be no way for me to pass this knowledge on to you.  So, if during a  compile, you get messages that some dependency is not fulfilled, don't panic.  Read the message, and go to http://packages.ubuntu.com to help you figure out exactly what package to apt-get.

First, go to http://www.mythtv.org to download the latest version of the MythTV source, as well as the source code for the plugins and the myththemes tarball.  Unpack the three tarballs mythtv source, mythplugins source, and the myththemes tarball in /opt/src:

cd /opt/src
tar xvfj mythtv-0.19.tar.bz2
tar xvfj mythplugins-0.19.tar.bz2
tar xvfj myththemes-0.19.tar.bz2

First, we need to make sure that we have all of the packages installed that will be necessary for a compilation of MythTV and the plugins:

apt-get update
apt-get build-dep mythtv
apt-get build-dep mythplugins

 Now, cd to the mythtv source directory and then execute the following commands to configure the source tree:

export QTDIR=/usr/lib/qt3
./configure --prefix=/usr/local/mythtv-0.19
qmake mythtv.pro
make

After the compile finishes (approximately 15 minutes), install the mythtv distribution:

make install

Now, cd to the plugins directory, and execute the following commands to configure the source tree:

./configure --prefix=/usr/local/mythtv-0.19 --enable-transcode --enable-vcd
qmake mythplugins.pro
make

After the compile finishes (approximately 15 minutes), install the mythtv plugins:

make install

Mythweb needs some special attention for proper installation.  We do that here:

apt-get install apache2 libapache2-mod-php4
mkdir /usr/local/mythtv/share/mythtv/mythweb
mv /var/www/mythweb /var/www/mythweb-0.18
ln -s /usr/local/mythtv/share/mythtv/mythweb /var/www/mythweb
cd mythweb
cp -r . /usr/local/mythtv/share/mythtv/mythweb
chown www-data /var/www/mythweb/data
cd ..

make sure that the file /etc/apache2/httpd.conf has the following contents; if not, every line needs to be added:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
LoadModule php4_module /usr/lib/apache2/modules/libphp4.so

<Directory /var/www/mythweb>
Options FollowSymLinks
AllowOverride All
</Directory>

Finally, edit the /var/www/mythweb/.htaccess file and set the correct host and password in the "db_" variables. 

Now unpack the myththemes tarball, and cd into that directory.  Then do the following:

echo "PREFIX=/usr/local/mythtv-0.19" > mythconfig.mak
qmake myththemes.pro
make install

Now, do the following

cd /usr/local
ln -s mythtv-0.19 mythtv

Edit the file /etc/ld.so.conf (create it if it doesn't already exist), and add the line

/usr/local/mythtv/lib

And then run

ldconfig

Also, edit the file /etc/profile, and just before the line which reads "export PATH", place the following line:

PATH=/usr/local/mythtv/bin:$PATH

Also, edit the file /etc/passwd, and look for the line starting with "mythtv".  Ensure that the last bit of that line looks like:

mythtv:x:500:500:MythTV User:/home/mythtv:/bin/bash

and not

mythtv:x:500:500:MythTV User:/home/mythtv:/bin/sh

This will ensure that, for all future shells that you open, the new MythTV installation will be the first path searched in the case that things like mythbackend, mythtranscode, etc. are run from the command line.  Note that this is for the bash shell only; if you want a similar operation done for tcsh, the file to edit is /etc/csh.cshrc.

The last thing you need to do is fully qualify the path in the System->Preferences->Sessions,  then "Startup Programs" tab dialog.  Replace your old entry "mythfrontend" with "/usr/local/mythtv/bin/mythfrontend", and you're done.  This step only makes sense after completing section 6.3 of this HOWTO.  When you are finished, it should look like this:

sessions dialog

Finally, reboot your machine, for all of our changes above to take effect.

====================

10. References

11. Revision History



Daniel G. Hyams(dhyams@comcast.net)

Site Meter


Interested in Computational Engineering? Visit the UT SimCenter at Chattanooga for more information.