Archives 2009

HowTo: Build a MythTV box from scratch using Ubuntu Jaunty 9.04

MythTV is a project that brings analogue and digital television to your Ubuntu-powered PC. It primarily functions as your television and personal video recorder (PVR), but can be made to do many other things (refer to the official MythTV site for more information), however one thing that can catch people is actually building a MythTV box from scratch. Over the years, MythTV has been one of the largest causes of baldness in users who have torn out their hair in frustration.

Nowadays, tailored distributions such as Mythbuntu make the task pretty much trivial, but not everyone likes to use the tailor-made distributions. For one, Mythbuntu has a lot of its own branding across it which I personally don’t really like, and I’d prefer not to have it install all of that plus XFCE as the default desktop and then have to undo it all just to get back to a regular Ubuntu desktop.

Since I recently built a MythTV server for my folks, and on top of that connected it to their aging CRT television rather than the latest in visual technology, this makes for a perfect tutorial on how to take a vanilla Ubuntu Jaunty 9.04 installation and turn it into a simple, functional MythTV server without all the branding. We are going to just install only the components required to get MythTV up and running. Anything else you add is purely up to you.

Note: This tutorial covers installation of MythTV 0.21 as supplied with Ubuntu Jauty 9.04. It does not apply to the forthcoming 0.22 release which will sport a vastly different interface. It is not known yet whether Ubuntu Karmic 9.10 will still have 0.21 supplied or if 0.22 will be ready for release by then.

The system I built for my folks comprised of the following hardware:

  • Silverstone LC17 case (just to match the lounge gear, but you can use pretty much any case)
  • Gigabyte 500w PSU
  • 2GB of Kingston DDR2/800 RAM (should have bought two sticks instead of a single stick, so I could run it in dual-channel mode – ah well, it’s not really a performance killer for MythTV)
  • A Gigabyte S-Series EG41M-S2H motherboard (which has built-in optical out and HDMI based on an Intel gfx chipset)
  • An MSI NX8400GS (NVidia GeForce 8400GS) PCI-E graphics card (because it’s passively cooled for no noise and has Composite/S-Video output as well as VGA and DVI)
  • An Intel E5300 Pentium Dual-Core CPU
  • A Seagate 1TB hard-drive
  • LG SATA DVD-RW optical drive (for playing DVD movie discs)
  • Two Asus MyCinema-U3100-Mini DVB-T digital-only TV tuners
  • Digitech “generic” Windows Media Centre Compatible remote control and USB infra-red receiver (cheaper than the real thing and doesn’t have any Windows or Microsoft branding on it)

I won’t detail the hardware build process since it’s an ordinary PC at the end of the day, but here is how it looks in my folks’ AV cabinet (it’s on the bottom shelf):

A PC in an AV-style case (bottom shelf)

I performed a vanilla Ubuntu Jaunty 9.04 with the following partition layout:

  • 100MB for /boot formatted as EXT2
  • 1GB for swap formatted as SWAP
  • 8GB for / (root) formatted as EXT4
  • Remainder of drive for /home formatted as EXT4

Since I also installed a UPS, I do not foresee any issues with the EXT4 file system and power-loss-related data corruption. I used EXT2 for /boot because, frankly, it doesn’t need journalling there. You’ll only ever write to that partition when you do a kernal update and having as a separate partition will make any future system recovery easier.

My folks are still using an old standard-definition widescreen CRT television. It comes equipped with SCART inputs which can accept Composite, S-Video and Amiga-style RGB signals, but not Component ability. I elected to connect the PC using S-Video, and it looks pretty sharp for what it is – certainly far more readable than Composite.

I came across a strange issue when I started the Ubuntu installation process – it couldn’t start X. Basically put, it cannot detect the “monitor” and thus cannot setup a suitable screenmode. I decided to do the initial installation via a traditional VGA monitor and once the NVidia drivers were installed, I’d switch back to the TV only.

I configured the primary login account, password and machine name to all be “htpc” and set it to auto-login. Once installation was complete and rebooted for the first time, I quickly installed the NVidia Binary driver and updated the system with any outstanding general system updates.

Setting up the TV

Once rebooted for the second time, I physically disconnected the VGA monitor and left only the TV connected. Ubuntu appeared quite cheerfully, though annoyingly it had switched to NTSC 60Hz mode, and I wanted PAL in 50Hz.

I opened up the xorg.conf configuration file into GEdit as follows:

$ sudo gedit /etc/X11/xorg.conf

…and located the “Screen” section which describes what the X screen to be used is. It looks something like this:

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "TwinView" "0"
    Option         "TwinViewXineramaInfoOrder" "TV-0"
    Option         "metamodes" "nvidia-auto-select +0+0"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

I added the following two lines into that section:

    Option         "TVOutFormat" "SVIDEO"
    Option         "TVStandard" "PAL-B"

…so now the Screen section looked like this:

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "TwinView" "0"
    Option         "TwinViewXineramaInfoOrder" "TV-0"
    Option         "metamodes" "nvidia-auto-select +0+0"
    Option         "TVOutFormat" "SVIDEO"
    Option         "TVStandard" "PAL-B"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

This ultimately outputted a 1024×768 display on the TV, stretched horizontally (a 4:3 screenmode stretched to fit a physical 16:9 display). If your Ubuntu desktop is larger than the screen, just adjust your TV’s picture size until everything fits in. In my case, only the top and bottom panels got slightly chopped off which was fixed with a minor vertical size adjustment on the TV.

Installing MythTV

First we need to enable the system to access the Multiverse repository. Do this by going to System->Administration->Software Sources and place a check mark against all five boxes, click OK and acknowledge the prompt to reload your package lists.

We now set about installing the extra software I required to turn this box into a MythTV server (which was going to run both Backend and Frontend):

$ sudo apt-get install mythtv

That’s all you need to get the main MythTV stuff working – the “mythtv” metapackage installs the MythTV Frontend, MythTV Backend, MySQL Server, MySQL Client, MythTV database configuration, all the default MythTV themes, etc. In my case, however I also installed the following for extra video/audio codecs (such as MP3 for listening to music files or watching movie rips), Java, Flash, the Microsoft Fonts, the Compiz Configuration manager for doing desktop eye-candy, the SSH server daemon to remote control the box when my folks call for help, and finally the MythWeb add-on that allows you to look at the MythTV server’s TV guide and schedule programs to record using a web browser interface:

$ sudo apt-get install mythtv ubuntu-restricted-extras compizconfig-settings-manager ssh mythweb

…and from the Medibuntu repository, I installed the following for extra codecs and DVD decrypting/playback:

$ sudo apt-get install non-free-codecs libdvdcss2 mplayer mencoder

Note: I did not need to install lirc for the remote control because the Digitech remote is actually a USB keyboard in disguise, not a “proper” infra-red remote.

During the installation of these packages, you will be prompted for a few things, namely:

  1. Create a password for the root MySQL account. If this MythTV installation is purely for in-house use only, then just go with something simple like “password”. Many suggest leaving it blank, but I’ve personally seen this create authentication problems later on.
  2. Create the MySQL database. When prompted for the MythTV server address, change the default “localhost” to the IP address of the PC you are installing the Backend on. If the Backend Server has an IP address of 192.168.0.10, then type in 192.168.0.10 in place of “localhost”. If you only intend to run one machine only for everything, then you can leave “localhost” as is.
  3. When prompted for the name of the MySQL database, leave it as the default “mythconverg”.
  4. Make note of the password generated for the MythTV database. You will need this to configure your MythTV Frontend.
  5. Indicate whether or not you intend to have more than one Frontend client connect to your Backend server.
  6. If you elected to install MythWeb, then you will be asked a question as to whether or not you want your MythWeb site password protected.
  7. Acknowledge other prompts that tell you about creating the “MythTV” groups etc.
  8. Your PC now has a user and Home directory called /home/mythtv and we need to ensure that the “mythtv” group can write to it as well as the owner, so at a terminal, type in:

    $ sudo chmod -R g+w /home/mythtv

    …and hit Enter.
  9. Finally, if you intend more than one Frontend to access your Backend machine, we need to tell MySQL to allow other PC’s on your network to access the database, or those Frontends (other than the one on the Backend server) will not be able to start. To do this, type the following at the $ prompt. Everyone else can skip to Step 12.

    $ mysql mythconverg -u root -p
  10. When prompted, enter in the root MySQL password you specified earlier.
  11. You will then be shown a MySQL prompt. If your local network’s IP topology is 192.168.0.x, and the password that was generated for MythTV’s database was “8tSpxGiM” then type the following to grant access to all PC’s on your local network to the MythTV MySQL database, at the “mysql>” prompt:

    mysql> grant all on mythconverg.* to mythtv@"192.168.0.%" identified by "8tSpxGiM";
    mysql> flush privileges;
    mysql> quit


    …this will allow all PC’s with IP addresses starting with 192.168.0.x to access the MythTV database. If you are paranoid and only want to allow specific PC’s to access the database, then simply issue the “grant all” line for all explicit IP addresses only, by replacing the “%” wildcard character with the explicit IP address you want to allow, ie: to allow just 192.168.0.67 in, replace “192.168.0.%” with “192.168.0.67”.

    Repeat for all specific IP’s to allow. You only have to issue the “flush” command once at the end to make your changes take effect.
  12. Confirm that you can access the MythTV database as the MythTV user at the $ terminal prompt. If you are only using one machine, do this on the Backend server. If you are using multiple Frontends, test this on the remote PC’s that will be running the Frontend software (obviously replace the IP address with the actual IP address your Backend machine is using):

    $ mysql mythconverg -h 192.168.0.10 -u mythtv -p

    …when prompted, enter the MythTV password that was generated earlier. If successful, you should be looking at a “mysql>” prompt. If not, you will get an error, probably along the lines of “access denied”. NOTE: If you configured “localhost” to be the Backend Server in Step 2, then you must use the name “localhost” to connect to MySQL. Using “127.0.0.1” instead will not work because you have not configured “127.0.0.1” to have access to the mythconverg database. If you wanted these permissions, you would modify Step 11 to be the following commands:

    mysql> grant all on mythconverg.* to mythtv@"192.168.0.%" identified by "8tSpxGiM";
    mysql> grant all on mythconverg.* to mythtv@"127.0.0.1" identified by "8tSpxGiM";
    mysql> grant all on mythconverg.* to mythtv@"localhost" identified by "8tSpxGiM";
    mysql> flush privileges;
    mysql> quit


    …which will allow the “mythtv” user to connect from any IP on the 192.168.0.x network, from 127.0.0.1 and any host called “localhost”, all using the specified password. 
  13. Quit the MySQL client by typing “quit” at the “mysql>” prompt:

    mysql> quit

Configuring MythTV – the Backend

At this point, make sure your TV tuners are connected. In my case, the Asus U3100’s are connected into two free USB ports at the rear of the PC and have automatically been detected as Ubuntu carries full support for the U3100 already.

Now we need to start MythTV Backend Setup for the first time. Go to System->Administration->MythTV Backend Setup. When you do so, it will prompt you that your user (in my case “htpc”Smilie: ;) needs to be added to the “mythtv” group. Acknowledge this and then accept being logged out for the change to take effect. Log yourself back in. Once logged back in, restart the MythTV Backend Setup again. You will be reminded that the MythTV Backend needs to be stopped before you can continue. Click OK.

You are presented with several options. Choose “General” (if you are using a remote, you should find the basic Up/Down and OK buttons work here already).

  1. Change the “Local backend” and “Master backend” addresses to be “localhost” (in lower case and one word). Leave all the “port” numerical figures alone.
  2. Click on “Next”. If you’re only using a keyboard, then press ALT + N to proceed. The screen content will change.
  3. Change the “TV format” to suit your local country. In my case, this is “PAL”. If you are in America or Japan, you’ll use “NTSC”. Check your local TV standards if you are not sure.
  4. Change the channel frequency table option to your local country. In my case, this is “australia”.
  5. The timezone for your guide XML data will ultimately depend on how you get your guide data. In my case, I just use Auto.
  6. Click on “Next” or ALT + N on the keyboard.
  7. We don’t need to change anything on this screen or the five screens that follow it, so click on “Next” again until you get to the last page where the button now says “Finish”.
  8. Click on the “Finish” button or press ALT + F on the keyboard. You will be returned back to the main menu.

Now choose the “Capture cards” option.

  1. Choose the “New capture card” option from the list.
  2. What you choose here will be dependent on what your tuner hardware is. In my case, I change the “Card type” until it says “DVB DTV Capture Card (v3.x)” and you will see that the “Frontend ID” will show “DiBcom 7000PC” and the “Subtype” will be “DVB-T” indicating a “Digital Video Broadcast – Terrestrial” device was found.
  3. Click on the “Recording Options” button and ensure that the “Max recordings” option is set to “2” (most digital tuners can record two channels at once from the same network, thus two physical tuners effectively become four usable tuners within MythTV).
  4. Go back to the previous screen by clicking on Finish and then click on Finish again. You will be returned to the Capture card list and you will now see a new line for the card you just setup.
  5. Since I have two tuners, I repeat this whole process again – the system will pick up the second tuner and label it accordingly – you can’t setup a card more than once accidentally. In my case now I have two cards called DVB:0 and DVB:1 listed.
  6. Press ESC to return back to the main menu.

Now choose the “Video sources” option.

  1. Choose the “New video source” option from the list.
  2. Give your video source a name, eg: “Digital Free-to-Air”. This can be anything you want.
  3. For your Settings Grabber, just choose the “Transmitted guide only (EIT)” or “No grabber” option for now. If you already have a preferred grabber, then choose it here now.
  4. Click on Finish.
  5. We only need one source for both tuners, so we’re done here. Press ESC to return back to the main menu.

Now choose the “Input Connections” option. This is where we tie our source to the tuners.

  1. Choose the first tuner in your list. In my case I have “DVB: 0 (DVBInput) -> (None)”.
  2. Change the “Display Name (optional)” to be something that describes the tuner, eg: “Digital tuner 1″. This can be anything you want and will serve to highlight what tuner you are using to watch or record a particular show.
  3. Change “Video source” to the one you created in the “Video sources” earlier. In my case, I choose the only option I have – “Digital Free-to-Air”.
  4. Now press the “Scan for channels” button.
  5. Ensure that “Scan Type” is set to “Full Scan” and that your Country is correct.
  6. Make sure that your TV aerial is securely connected to your TV tuner and then click on “Next”. The tuner will begin looking for TV channels. This can take several minutes to complete. Do not interrupt the process, even if it looks like it has gotten stuck – it will finish eventually. Any channels found will be listed in the status window at the back.
  7. Once finished, press “Finish”.
  8. Now press “Next”. Don’t change anything here.
  9. Press “Finish”. You will be returned to the “Input Connections” list.
  10. Repeat steps 1 to 3 only for any additional tuners you have (in my case, I had to repeat for the second tuner). We don’t need to re-scan for channels because the tuners are using the same source and we’ve already populated it with channels in the first run. In this instance, once you have done steps 1 to 3, just click on “Next” and then “Finish”.
  11. Press ESC to return back to the main menu.

Now choose the “Channel Editor” option and review all the channels that were picked up in the scan. Optionally, you may also have MythTV automatically download what it believes are the correct network icons for those channels from the Internet using the “Download icons” button. Delete any channels you don’t want to review. Eg: in my case, I also picked up some digital radio channels. I’m not interested in those, so I could delete those if I so choose.

Press ESC to go back to the main menu.

Now choose the “Storage Directories” option. This is where we tell MythTV where to put all our TV recordings.

  1. Choose “Default” from the list.
  2. Choose the “/var/lib/mythtv/recordings” path already defined and change it to “/home/mythtv” (or whatever you prefer).
  3. Click the “OK” button.
  4. If you want to add more directories from other devices such as secondary hard-disks or network drives, just “Add directory” and specify them accordingly.
  5. Once done, press ESC to return back to the main menu.

We’re now done configuring the Backend, so press ESC again to close the MythTV Backend Setup application. If you get an error, review it and see if you can fix it based on the information provided. In particular, if it tells you that it couldn’t write a “.test” file to /home/mythtv, then you did not grant the “mythtv” group writer permissions to “/home/mythtv” (See Step 8 in “Installing MythTV” earlier in this article).

Upon exiting, after a couple of seconds a dialog box will appear asking if you wish to run “mythfilldatabase”. Say YES. Once this is done, the MythTV Backend should automatically restart in the background briefly and then its output window should disappear.

Configuring MythTV – the Frontend

We’re nearly there! Now to configure the Frontend! Go to Applications->Sound & Video->MythTV Frontend. After a brief delay, you will see the default MythTV menu.

  1. Choose “Utilities/Setup” from the menu.
  2. Now choose “Setup” in the next menu.
  3. Now choose “General” in the next menu.
  4. If the PC you are on now is the Backend server, then this should already show that the”Database Server Settings” hostname is “localhost”. If you are installing a laptop/desktop that is NOT the Frontend, then you need to have the IP or hostname of the Backend machine here instead so that Frontend client knows who to talk to. In the case of your installation example, I’m using 192.168.0.10.
  5. The port number can be left empty. It will use the MythTV default automatically.
  6. The database name should already be “mythconverg”.
  7. The user name should already be “mythtv”.
  8. The password should already be the one that was randomly generated during the installation process.
  9. Press “Next”.
  10. Nothing to change on this screen, so press “Next” again.
  11. Change the audio settings to suit your own configuration. If you are using an ordinary stereo setup, you can leave pretty much all of this unchanged, however I’d recommend adjusting the “Master Mixer Volume” to 100 and the “PCM Mixer Volume” to 80 or 90 (don’t set PCM to 100 as some motherboards will output scratchy/distorted audio depending on the quality of your on-board sound hardware).
  12. Press “Next” through the next four screens.
  13. Press “Finish”. You will be returned to the Setup menu.

Special setup: Configuring your MythTV Frontend to output digital audio via SP/DIF on the PC’s motherboard.

  1. By default, motherboards with on-board SP/DIF out generally have their output muted, and as a result you will not see any laser light from any toslink cable connected to the motherboard. Unless you’re lucky, 9 times out of 10, the SP/DIF controls will not appear in the graphical Volume Control applet. To get around this, open a terminal.
  2. Now type in “alsamixer” and you will be presented with a terminal version of the Volume Control applet.
Alsamixer’s Interface
  1. Now press the right-arrow key until you come across any “IEC958″ related options. There will generally be two or three entries. You will probably find they have “MM” above them which means they are Muted.
The muted IEC958 output
  1. Press the M key on your keyboard to toggle the Mute status of that option so that it now shows “OO” instead. This means it is no longer muted.
IEC958 is now un-muted
  1. If you’re looking at your toslink cable, you should now see the fibre optic line in it light up with red laser light as you unmute it. You’re done, so press ESC to close the Alsa Mixer interface.

Now choose “Appearance” from the menu.

  1. You can now choose a different theme from here which makes the interface look more attractive than the default theme. My personal favourite is “Blootube” and “Blootube Wide”.
  2. If you are using 3D-enabled video drivers such as the NVidia binary drivers, you can elect to change the Paint Engine to OpenGL which will do nice crossfade transitions from one menu to another (note that there are no 3D transitions).
  3. I also change the “Menu theme” here to “classic” as I believe it provides a more intuitive menu tree within MythTV. I encourage you to explore these options and choose what works best for you.
  4. Page the “Next” button until you get to the end and then click “Finish”.
  5. If you’ve chosen a new theme, it will now be scaled appropriately for your display and switched over.

You are now ready to begin watching TV, but you may want to quickly duck back into Setup->Playback OSD and change the theme there to “Blootube” or whatever you prefer as well as the On-Screen-Display when watching TV has a separate theme setting to the menus.

To watch TV, simply choose “TV” and then “Watch TV” from the MythTV menu. Use the up and down arrow keys and Enter to change channels.

Examples of the Blootube-themed main menu and TV OSD (on a full high definition display):

The Blootube theme on a Full HD display
The Blootube theme over the top of a Full HD TV channel

Using MythWeb

MythWeb is completely automatically configured. Using our installation example Backend host IP of 192.168.0.10, you can access it by opening your web browser and surfing over to http://192.168.0.10/mythweb and you will be presented with the main menu of MythWeb.

Being a web site, MythWeb is obscenely easy and self-explanatory to get around, so I won’t detail any of its most common functions here. I encourage you to explore the interface.

The MythWeb interface in a web browser

One particularly useful feature of MythWeb is in getting the Digitech generic remote to work. Out of the box, I only found the direction and OK buttons to work right away. All the other buttons generate keyboard presses that do not coincide with MythTV’s default keys. For example, the Play/Pause key on the remote generates “CTRL + P” instead of just “P”, hence MythTV doesn’t act on the button press.

  1. To reconfigure key binds, all you have to do is click on the “Settings” option on the main menu.
  2. Now click on “Key Bindings” in the presented options.
Mythweb Keybindings Menu
  1. You are presented with all the available keybinds for various areas of MythTV. Scroll down the list until you find the keys pertaining to “TV Frontend” (first column).
  2. Now locate the key bind related to “PLAYBACK – Play Program” (second and third columns). You will notice that the key assigned (in the fourth column) already is “P”.
Changing keybindings
  1. To add the CTRL + P key combination without erasing the original “P” key, simply change the text box to read “P, Ctrl+P”. This binds both the P and CTRL + P key combinations to the Playback command.
  2. Change all the other keys you need to change or add.
  3. When done, scroll right to the very bottom of the key binds page and click on the “Save” button.
  4. Restart the Frontend to read in your new changes and test the remote.

This is what the Digitech generic MCE remote looks like:

The DigiTech brand Media Center Edition remote and receiver

OPTIONAL: Setting up the Shepherd Electronic Program Guide (EPG)

Shepherd is an amazing Perl script that enhances and keeps your EPG data up to date in Myth, always providing better information about programs than the networks themselves do. A typical example of a poor network-supplied program description might be “Late Movie: 10:30pm – Pirates of the Carribean starring Johnny Depp” and… that’s it. How boring! Shepherd will use a grading system as well as sourcing categories of data from different sites in order to provide you a comprehensive description of all your programs instead. In the case of the above example, it would go to the IMDB and get the official movie blurb to use instead.

NOTE: Shepherd is geared towards Australian MythTV users only. This is due to long-running (and petty) legal disputes over EPG supply and copyright in this country. If you are outside of Australia, you most likely already have a proper EPG provided for you and you should use that instead.

Setting up Shepherd is trivial (Shepherd was up to version 1.3.39 at the time of this writing – refer to the official installation page for any changes made to the installation process since).

  1. Open a terminal and type in the following:

    $ wget http://www.whuffy.com/shepherd/shepherd

    …and press Enter. This will grab the latest version of the Shepherd Perl script.
  2. Before we run it, we need to install some dependencies:

    $ sudo apt-get install xmltv libxml-simple-perl libjavascript-perl \ libalgorithm-diff-perl libgetopt-mixed-perl libcompress-zlib-perl \ libdata-dumper-simple-perl libdate-manip-perl liblist-compare-perl \ libdatetime-format-strptime-perl libhtml-parser-perl libxml-dom-perl \ libgd-gd2-perl libdigest-sha1-perl libarchive-zip-perl \ libio-string-perl libdbi-perl

    …and hit Enter.
  3. Once all that is installed, now run the Shepherd setup script with the command:

    $ perl shepherd

    …and hit Enter.
  4. Shepherd will initially re-install itself into the “mythtv” user’s home directory, ie: /home/mythtv, and re-run itself.
  5. Shepherd will then begin checking itself to ensure all its data grabbers are the latest versions and download any that are missing. It will then prompt you through the rest of the installation process, which is generally straight forward, but we’ll step through it here:
  6. First you are asked for a region code and are shown a giant list. Type in the number relevant to you and hit Enter. Eg: if you lived in Melbourne, Victoria, you would type in “94” as the code associated with that region. If you were in Sydney, you’d type in “73” instead.
  7. Next you are asked if you would like Guided Channel Selection. Say YES (or just hit Enter as the default response is yes anyway).
  8. You will then be asked if you have High-Definition TV. If you do use HDTV channels, you should say YES to this.
  9. You are then asked if you have PayTV. If you are only configuring MythTV for Free-to-Air TV, say NO to this.
  10. Now MythTV will ask you to match the known channels for your region to the channels that are setup in your MythTV installation. It will prompt you for each channel one by one. Simply enter the number corresponding to the guide data source you believe belongs to the currently displayed channel, eg: in some country areas, Channel Nine is known as WIN, so any references to “Channel Nine” you would tell Shepherd to use guide data provided by WIN. Repeat this until all channels have been prompted for. You may come across some doubled-up channels. This is normal.
  11. When finished, Shepherd will list all your selections so you can verify them. When you are happy, respond YES.
  12. You will then be asked about transitioning from an old grabber. Since this is a fresh installation, choose the zero (“do not transition”) option.
  13. You will be given one more review and will then be asked if you’d like Shepherd to create a configuration file and update MythTV. Say YES.
  14. When prompted about allowing Shepherd to auto-configure MythTV, say YES.
  15. When prompted for Shepherd to create a symbolic link, say YES.
  16. When prompted about the cron job Shepherd sets up, say YES.
  17. Respond YES to the review question.
  18. Shepherd will then begin testing its components and will eventually ask if you would like to install channel icons. This is not necessary (though you can complete it if you really like), so say NO to this.
  19. Shepherd will finish.
  20. Now we need to populate the EPG using Shepherd for the first time. Note that the initial run can take potentially an hour or more to run depending on your connection and quantity of channels in MythTV to find data for. Once finished, however, each subsequent run (once per hour, 24 hours) should be much faster. To run it for the first time manually, simply type in:

    $ mythfilldatabase

    …and hit Enter.
  21. Depending on the minute that Shepherd setup for the cron job, you may find that as you try to run it manually, Shepherd advises that “another instance is running” and will abort itself. That’s fine – the job’s already started then automatically.
  22. When Shepherd has completed its run, you will find that your EPG within MythTV is now nicely populated with highly descriptive blurbs and will remain so for at least 7-8 days ahead as long as the PC has a connection to the Internet.

HowTo: Fix MythTV’s Frontend not going full-screen in Ubuntu Jaunty.

The next version of Ubuntu is here – 9.04 aka “Jaunty Jackalope”. Along with a wealth of new features comes a wealth of new minor bugs to fix. Not enough to be show-stoppers, but enough to annoy the heck out of you, and here’s a doozy.

If, like most people, you have Compiz enabled and you start the MythTV Frontend, you will notice that rather than go full-screen, Myth will start as a window, essentially, even if your settings within Myth say to go full-screen.

In a single-screen scenario, the MythTV window will start just underneath the upper Gnome panel and the lower Gnome panel will sit over the top of the Myth window, obscuring part of the display. Proof that it’s a window can be found by holding down the ALT key and then dragging the MythTV display around with your mouse.

If you’re like me and use two displays with Myth being run on the second screen, you will see a gap at the top of the screen that is the same height as the upper Gnome panel and you will see your wallpaper showing through there, as shown in the illustration below.

Ugly titlebar gaps

Here’s how to fix this problem.

EDIT June 2010: This problem still plagues Ubuntu 9.10 and 10.04, and this fix will work for those releases as well.

The simplest fix is to disable Compiz altogether and MythTV will suddenly go full-screen, but that’s not really a solution – you want to keep your eye-candy! So follow the next few steps instead:

  1. Go to System->Preferences->CompizConfig Settings Manager. If you do not have this option in your Preferences, then you need to add it. Quickly jump into a terminal and type in at the $ prompt:$ sudo apt-get install compizconfig-settings-manager…and hit Enter. Once installed, go back into the Preferences menu and bring it up.
  2. Scroll down until you get to the “Utility” section and then click on “Workarounds”. It should alredy be selected as enabled, but if not, also make sure the checkbox next to it is enabled too.
Compiz Workarounds Plugin
  1. The window changes to show you the Workaround options. The very first option is “Legacy Fullscreen Support”. This is unchecked by default. Click on the checkbox so that it IS checked, and then click on the Back button, then close the window.
Compiz Legacy Fullscreen support
  1. Quit the MythTV Frontend if you had it open already and then restart it. You will now find that the gap has disappeared, and that the MythTV display is now appearing full-screen properly instead of just being a window.
  2. Pat yourself on the back.

Happy viewing! Smilie: :)

Please note: This workaround is just that – a workaround. One minor problem that arises with it is that you may get occasional screen “flashing” or a flash of the background wallpaper appearing when a DBus message is displayed, or if you scroll a window or terminal on the same or other screen in a multi-screen setup. This does not occur often, however, and so may not bother you at all! The bug has been reported, and no doubt will be fixed in due course. When it is fixed, this workaround should be reversed.

HowTo: Reclaim reserved disk space on non-system drives taken by the Ext3 filesystem.

I made a rather alarming discovery today, quite by accident.

Like most people, I use an external hard-drive to backup data to, or to shift things around if I’m low on space on my PC’s internal drive. Well, today that external drive reported that it was full. Damn.

So I fire up Ubuntu’s Disk Usage Analyser, aka Boabab, to find out what’s consuming the most space. I use a 1TB external drive and it’s formatted total is about 916GB, which is about right, however Boabab reported that the total consumption of data on the drive only added up to about 860GB – wtf? Even Nautilus’s Volume Properties window was reporting that the drive still had 50GB-odd free, so why is the system telling me it’s full?

I use Ext3 on my drives and, being a journalled filesystem, some space on the drive is reserved to record these journals among other functions which is expected, but 50GB worth? I did some research and found out that the Ext3 filesystem reserves 5% of disk space by default for itself! In this day and age of large drives, that’s a huge chunk of lost space!!

Thankfully there is a way to tell Linux not to reserve so much space. Read on…

  1. First up, unmount your drive. You can do that by either right-clicking on the drive icon on the desktop and choosing “Unmount volume” or by clicking on the Eject icon next to it in the Places pane of any Nautilus window.
  2. Next, open up a terminal and type the following:

    $ sudo fdisk -l

    This will list all your available drives. Identify which one is your external drive and take note of the device name, eg: in my case my external drive appears as /dev/sdb with one partition on it, sdb1.
  3. Now type in the following:

    $ sudo tune2fs -m 1 /dev/sdb1

    This will modify the filesystem on that drive, on that one partition, to only reserve 1% instead of the default 5%.
  4. Now re-mount your drive by clicking on its name in the Places pane in a Naultilus window.
  5. The Nautilus Device Properties window will still show the same free space as before, because it reports the true total free space, but any Nautilus File Manager window only reports usable free space, which in the case of my external drive had now freed up a very sizable 37GB!
  6. Lather, rinse, repeat on any other non-system drive partitions on the same or different drive you want to reclaim space back for.

You learn something new everyday. Smilie: :)

HowTo: Prevent other sites hot-linking to images on your own Apache website on your Ubuntu Server.

Personal websites, blog pages, etc. You can spend a lot of time, effort, and sometimes money setting them up and maintaining them. The pay-off is when you see lots of people visit your site, take an interest and even provide feedback. The annoyance comes when you notice in your logs that a select handful of images are being downloaded a helluva lot more than every other image on your server, and further scruitiny shows that it wasn’t even your own website requesting them – it was someone elses.

So you go and have a look at the referring site. Worse-case scenario was that they had blatantly plagerised your site – copied everything as their own. Not so bad is that someone has found an interesting pic on your site and linked directly to it on another site to tell people about it, but not necessarily atrributed your site to it.

Hot-linking files between sites is considered bad nettiqette if you have not got permission from the site owner. Image copyright issues aside, it is preferred that if you have an interest in an image that you download a copy and host it yourself, or that you link to the hosting website itself so that people can see proper attribution.

This has already happened to me a few times with the most notable being some Korean blogger’s site blatantly copying word for word one of my articles, but he decided to leave all the images in it hot-linking to my server. I couldn’t believe it, but I knew it wouldn’t be long before someone did that. I dropped a politely worded, but firm, message on his blog where everyone could see it, and he has since deleted the plagerised entry from his blog.

So, how do we go about preventing your Apache web server from serving up images to invalid referrers? Read on…

This HowTo was written with Ubuntu Server 8.04.2 Hardy Heron in mind since most server users would be likely still be using the LTS release for public-facing servers, however these instructions should apply to any version Ubuntu Server until Apache make any radical changes to how their http daemon configuration works. I will also assume that you already have a web site up and running. We are just going to add to its configuration here.

To prevent hot-linking is a simple matter of checking what file is being requested from your server. We can do this by checking for certain file extensions such as .jpg, .png etc. We then have a rule to ensure that such requests are coming from your website, eg: www.acmecorp.com instead of someone else’s site. If the rule matches your site, the requested image is served, otherwise an alternate image is served instead.

What’s the alternate image? Simply it’s a small-sized image that provides a small message to the hot-linker to tell them that you shouldn’t be hot-linking images to your site. The small size ensures that  it is transferred quickly and doesn’t chew up much bandwidth on your connection.

Here is the one I use for serenux.com:

Anti hot-linking message

Can be anything you want, really. Just make it polite or funny. This one was created in The GIMP and saved out with extremely high compression to make it as small as possible without compromising image quality so much that the image is unreadable with compression artifacts. From memory, I think it was 40% quality instead of the usual 80-85% you’d save most photos with.

Create your own message in a picture and save it out to somewhere on your website with some arbitrary name. I use “noop.jpe” in reference to “no operation” and the file extension is deliberately mangled for reasons you’ll see later. I also save it in the root of my website so I don’t have a long convoluted URL to refer to it with. Eg: if your website resides in /var/www on your server, then save this image to /var/www/noop.jpe accordingly.

Now we need to tell Apache to use this image in place of serving other hot-linked images.

If you use SSH to manage your server:

  1. SSH into your web server as normal.

    $ ssh acmecorp@www.acmecorp.com
  2. Change directory to the /etc/apache2/sites-available directory.

    $ cd /etc/apache2/sites-available
  3. Bring up your website’s configuration file into your favourite text editor. In this case, the config file is called “www.acmecorp.com” and i’ll use the Nano editor to edit it.

    $ sudo nano www.acmecorp.com
  4. Add the following lines to the end of the configuration file, but before the </Virtualhost> line:

    # Prevent hotlinking of images from foreign sites and redirect to a new image.
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://www\.acmecorp\.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} ^http://.*$
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://www.acmecorp.com/noop.jpe [NC,R,L]


    (Change www.acmecorp.com to what is relevant to your site, of course)

    What the above does in order is turn on URL re-writing, then check to see if the referrer does NOT start with the string “www.acmecorp.com” (the NC means “not case-sensitive”, so it matches on things like WWW.ACMECORP.COM and www.AcmeCorp.com as well), the referrer is also checked to ensure that is is not blank, and that the referrer had a “http://” string at the start.

    If all these rules match true, then one last rule is applied before re-writing the URL – if the URL string requested ends with .jpg, .jpeg (the e? part tests for whether the “e” exists or not so it matches on jpg or jpeg), .gif, .bmp or .png, then re-write the requested URL as “www.acmecorp.com/noop.jpe” with no case-sensitivity on the match (“NC”Smilie: ;), the “R” parameter will tell your visitor’s browser that they were redirected (you don’t have to do this – you may want the visitor to think this is actually what they requested), and the “L” parameter will stop processing of anymore re-write rules here, ie: this is the “Last” re-write rule.
  5. Save your work and exit the editor by pressing CTRL + X and then “Y” to save.
  6. We’re almost there! Now that we have the rules written, we now need to enable the URL re-writing module of Apache called “mod_rewrite”. Without it, the changes we did to the configuration will cause Apache to error out on startup. Ubuntu has the re-write module pre-compiled in, so all we have to do is enable it. To do this, simply enter the command:

    $ sudo a2enmod rewrite
  7. Now we are ready to rock and/or roll. Restart your Apache server with:

    $ sudo /etc/init.d/apache2 restart
  8. Ensure that no errors were reported during startup and then test hot-linking to your site. NOTE: If you already tested hot-linking from another site and can still see your images, more than likely they have been served up from your web browser’s cache – clear your cache and try again.
  9. Pat yourself on the back. You’re done.

If you use WEBMIN to manage your server:

This HowTo section assumes you’re using Webmin version 1.430 or later.

  1. Open your web browser and get into your Webmin interface as normal.
  2. Click on “Servers” in the left pane. A list of server daemons will be listed underneath.
  3. Click on the “Apache Webserver” daemon. The right pane will then show you your available web sites.
  4. Click on the “Global Configuration” tab at the top-left of the Virtual Server list. The pane will change to show global Apache options.
  5. Click on the “Configure Apache Modules” icon. The pane will change to show the currently available and enabled Apache modules.
  6. Locate “rewrite” in the list and ensure a checkbox is enabled against it. Do not change anything else.
  7. Scroll to the bottom of the list and click on the “Enable selected modules” button. You will be returned to the Virtual Server list page.
  8. Now click on the icon relevant to your virtual server, eg: “www.acmecorp.com”. The window changes to show the options available for that virtual server.
  9. Click on the “Edit Directives” icon. You will be presented with a text editor showing the configuration file.
  10. At the end of the file, paste the following in:

    # Prevent hotlinking of images from foreign sites and redirect to a new image.
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://www\.acmecorp\.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} ^http://.*$
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://www.acmecorp.com/noop.jpe [NC,R,L]


    (Change www.acmecorp.com to what is relevant to your site, of course.)

    See the description of what all this does in the SSH instructions.
  11. Click on the Save button.
  12. Click on “Apply changes” at the top-right of the Webmin window.
  13. Test hot-linking images on a foreign site to your own.  NOTE: If you already tested hot-linking from another site and can still see your images, more than likely they have been served up from your web browser’s cache – clear your cache and try again.
  14. Pat yourself on the back. You’re done.

Notes:

Now, you’ll rember that I called the anti hot-linking image “noop.jpe” instead of “noop.jpg”. Want to know why? Well, it’s the only image on your entire server that you DON’T want to be matched on for anti hot-linking. Despite the URL being re-written to deliver that image to the visitor’s web browser, that very image is still subject to the re-write rules as well. If you were to tell your Apache server to re-write the URL for every .jpg image on your server, then the “noop.jpe” file served as “noop.jpg” instead would be re-written to “noop.jpg” again and again and again in an infinite loop, hanging your server and not actually serving it to the visitor! Thankfully Apache today is a little smarter and will detect and abort an infinite loop, but it still serves nothing to the visitor. This is why we called the file “noop.jpe” so that it does NOT match the “.jpg” or “.jpeg” rules. We could fix this by simply adding another rule that says “don’t re-write if noop.jpg is being requested” but I’m just lazy. Smilie: ;) You want the rule? OK, fine – add this before the “ReWriteRule” line:

RewriteCond %{HTTP_REFERER} !^http://www\.acmecorp\.com/noop\.jpg.*$ [NC]

Now what if you participate on other forums and want to allow hot-linking of images on your site from that site? What about Google and other search engines – can you omit them from being blocked? You sure can. Just add these rules in before the “ReWriteRule” line, and modify them to your requirements:

RewriteCond %{HTTP_REFERER} !^http://(www\.|forums\.)?overclockers\.com\.au/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(images\.)?google.*$ [NC]

The first condition says “don’t re-write if the referrer string starts with either “www.overclockers.com.au” or “forums.overclockers.com.au” and the second condition says “don’t re-write if the referrer string starts with either “images.google.<whatever>” or “google.<whatever>” (so that means it’ll allow things like images.google.com.au, google.com, google.co.uk, images.google.co.uk etc, but will NOT allow things like banana.google.com or freddo.google.co.uk”Smilie: ;). You can adapt this easily enough to other search engines like Yahoo etc.

Finally, what if you simply want to be a bastard and present a broken link to the hot-linker instead of a friendly message? Hot-linkers be damned! An easy way to do that is to re-write the “ReWriteRule” line as follows:

RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]

The dash and the “F” parameter essentially drops the request and serves nothing back. Not even an acknowledgement. As far as your hot-linker is concerned, the image file doesn’t exist.

Happy blocking!

HowTo: Upgrade Ubuntu to the next version without burning a physical CD.

As you are probably aware, Ubuntu has a regular six-month release cycle, and if you are someone like me, then you are probably regularly downloading all the Alpha and Beta versions as well as the final releases. The problem with such regularity is that this would use up an awful lot of blank CD’s that you will probably only use a few times before discarding just to install these upgrades.

Fortunately, you don’t have to burn Ubuntu CD ISO images to a physical disc to upgrade your installation to the next version. Here’s how to do it using just the ISO image, or wholly via the Internet with no ISO image or CD at all.

There are three ways to upgrade Ubuntu from one version to the next:

  • Wholly on-line via the graphical Update Manager application, or
  • Wholly on-line via command line Apt application, or
  • The quicker and more easily repeatable method of using an upgrade CD, especially if installing multiple machines (this process optionally will also retrieve additional updates from the Internet released since the CD’s initial release). I will outline all three methods here.

NOTE: You cannot upgrade one CPU architecture to another, ie: you cannot upgrade Ubuntu 8.04 x86 (32-bit Intel/AMD compatible) to Ubuntu 8.10 AMD64 (64-bit Intel/AMD compatible), etc. If you previously used the 32-bit version of Ubuntu and wish to upgrade to the 64-bit version, you will need to do a complete fresh installation from scratch.

Upgrading via the CD ISO image

First up, you will need to download the Alternate Installer CD ISO image of the new version of Ubuntu you want as opposed to the Desktop Live CD version, which cannot do upgrades. All Ubuntu Alternate discs are named in the format of ubuntu-x.xx-alternate-yyyy.iso where x.xx is the release version, eg: 8.10 or 9.04, and yyyy is the target architecture, eg: amd64 for 64-bit Intel-compatible platforms and i386 for 32-bit Intel-compatible platforms. Thus the Ubuntu Intrepid 8.10 64-bit version is called ubuntu-810-alternate-amd64.iso and when it’s eventually released, the Ubuntu Jaunty 9.04 64-bit version will be called ubuntu-9.04-alternate-amd64.iso accordingly.

Once you have the CD image downloaded, make a note of where you downloaded it to, eg: /home/jbloggs/downloads/ubuntu-8.10-alternate-amd64.iso and then jump into a terminal window.

Make sure that you do not have any actual physical CD’s inserted into your CD-ROM drive.

At the $ prompt type in:

$ sudo mount -o loop /home/jbloggs/downloads/ubuntu-8.10-alternate-amd64.iso /media/cdrom

…and hit Enter. If all is well, it should look as though nothing happened, however you will notice a CD icon appear on your desktop simply called “cdrom”.

Now start the upgrade process with the following command:

$ gksu /media/cdrom/cdromupgrade

…and then just follow the prompts. When you reboot after the upgrade, the CD image will no longer be mounted and you can use real CD’s again without any issue.

Upgrading via the Internet only – GUI installation

This method is possibly more convenient, but generally takes longer to do and is not the ideal way to upgrade multiple machines. Using this method, you don’t need the ISO image at all. Everything is handled by the Update Manager.

Open a terminal (or press ALT + F2 to bring up the Run Application dialog) and type in the following:

gksu "update-manager -d" 

…and hit Enter. This will launch the familiar Update Manager. If you are not immediately advised of a newer version of Ubuntu to upgrade to, as illustrated below, then click on the “Check” button to update your system’s cache of available updates, then click on the “Upgrade” button that appears at the top.

Before Update Manager is aware of the next distribution version:

Update Manager now showing the Upgrade option

And after Update Manager is made aware of the next distribution version by clicking on the “Check” button (note that the Upgrade option will NOT appear if you did not start Update Manager with the “-d” parameter):

Update Manager showing the Upgrade button

Follow the prompts.

Upgrading via the Internet only – Command Line installation

This method is identical to the GUI Update Manager installation, except that it is done wholly via the command line using Apt.

First of all, make sure that Apt is fully up to speed with current updates by jumping into a terminal and type in at the $ prompt:

$ sudo apt-get update && sudo apt-get upgrade

When that has finished, commence the upgrade to the next version of Ubuntu with:

$ sudo do-release-upgrade

Follow the prompts.

That’s it!

Mini-Review: Ubuntu Intrepid Ibex 8.10 on the PlayStation3

Sony PlayStation Logo

So I finally joined the masses in next-gen console gaming nirvana when I finally bought myself a 40GB PlayStation3 that I got cheap at a Big W clearance sale for AUD$398!

After playing a couple of games, one of the next things I did was to partition the hard-drive and install the PPC version of Ubuntu 8.10 onto it. This is a quick run-down of my experience installing and playing with it.

Well first up I needed to grab the PPC version of Ubuntu. I was under the impression that Canonical had ceased PPC Ubuntu development, but it appears they haven’t. I found the Alternate Install for a dedicated PS3 Ubuntu Intrepid 8.10 ISO here for download. This disc is tailor made for the PS3 to get you up and running with the minimum of fuss.

EDIT September 2009: The release of the new “slim” PlayStation3 console has unfortunately seen Sony Computer Entertainment remove the ability to install Linux onto the hard-drive. Only owners of the older, larger PS3’s will be able to install Linux to their systems from now on.

While that downloaded, I prepared the PS3 itself. Thankfully Sony had the foresight to allow alternate operating systems to be installed, thus creating a greater attraction for tinkerers like myself. Unfortunately the ability to install Linux is marred by the fact that access is provided through a Hypervisor which does not give access to the PS3’s graphics hardware, thus preventing the possibility of creating home-brew games. It also limits you to 217MB of the total 256MB system RAM, presumably with some RAM being used for the video framebuffer much like a cheap motherboard with no dedicated video RAM.

Preparing the PS3 for a Linux install is simple enough. First you need to partition the drive. The PS3 OS allows you to allocate 10GB to the “other OS” or 10GB to the PS3 OS. You do not have any ability to set the size manually. Since I don’t really intend to use the PS3 as a workstation for any serious work, I opted to give Linux only 10GB. The system partitioned the drive and rebooted. WARNING: This process will destroy any data already on the drive, including downloaded games and configuration data. Make sure you backup your PS3 data before doing this!

Preparing the PS3 HDD for installation

After that, you need to install the bootloader for the “other OS”. The ISO image I downloaded contained the required PS3 bootloader KBoot and once the ISO finished downloading and I burned it to a CD, I stuck it into the PS3’s optical drive and told the PS3 to go looking for the boot loader there. It found it, installed it and all was good.

Getting ready to start the bootloader

You then need to tell the PS3 to change its “default OS” when turning on the system. By default it’s “PS3″, so I changed this in the system settings to be “Other OS” and the PS3 immediately asked if I wanted to reboot into the “other OS” now. I said “yes”. The machine shutdown and rebooted.

Default OS setting on startup
Ready to reboot into the “Other OS”

Almost right away I was looking at two penguins and a bit of text centred on my Benq E2200HD screen (connected via HDMI). Like most Linux distros, all I had to do was hit Enter to begin loading the installation program. To do that, however, I needed a keyboard! I grabbed my Microsoft USB keyboard and mouse, connected them to a passive USB four-port hub and then connected that to the PS3, so I could keep the other powered USB port free if I needed it for things like external HDD’s and the like. One USB port can happily power a USB keyboard and mouse together without a problem.

The Linux installer booting on the PS3

Ubuntu’s Alternate installer for PPC processors starts and looks exactly like its x86 bretheren, so I won’t go into detail about it here other than point out that when it asked which device I wanted to install on, the hard-drive presented was just the 10GB partition that the PS3 had created – you cannot see the rest of the drive at all (because this is all the Hypervisor presents to you).

The rest of the installation went as normal as any x86 install, however I did notice that the overall installation time was about double that of a typical desktop install. I put this down to two factors – the PS3’s HDD is only 5400rpm and the low available memory probably slowed it down too.

Once installed, the system rebooted. Unlike the desktop flavour of Ubuntu, you don’t get the splash screen, only Linux’s trademarked scrolling of information (most of which has been suppressed by the “quiet” kernel option in the KBoot configuration file). The console was in 1440×900 mode, but the screenshot below shows the console in 1920×1080 mode after I changed the config (see further below).

Booting Linux natively from the PS3 HDD after installation

Once loaded, the ever-familiar GDM login screen appeared. I logged in and within 10 seconds I was looking at the default Ubuntu Intrepid GNOME desktop. Unfortunately it didn’t fill my screen. In fact, it was only 1440×900 in size on my 1920×1080 monitor, neatly centred in the middle of the screen.

We needed to fix this, so first up was a quick review of the Linux PS3 wiki that had a reference for all the available screenmodes and the required changes to the KBoot configuration file that were required. In my case, I wanted to envoke a 1080p screen mode. I edited the KBoot configuration with:

$ sudo gedit /boot/etc/kboot.conf

…and added the following onto the ends of the two kernel lines in that file:

video=ps3fb:mode:165

This will tell Ubuntu to use 1080p “full screen” on reboot. I saved the configuration, performed a full system restart (you can’t just restart X) and viola! Ubuntu’s console and X displays were now in glorious 1080p.

If you are using an ordinary television, you can try:

video=ps3fb:mode:166

…which will give you full DVD resolution at 720 x 576 (576i mode), but you may need to adjust your TV’s settings to be able to see the entire picture as this will make use of your display’s “overscan” area which is generally beyond the visible area of the screen.

The GNOME login screen on PS3

Logging in and starting a few apps, Ubuntu runs exactly as you’d expect on any desktop PC system. Unfortunately due to the low memory available, performance is a little sluggish, but it’s not bad enough that you couldn’t make serious use of it.

Using the GNOME desktop on PS3

I did notice that general performance improved once you had used a few applications. For example, OpenOffice.org took a full minute to load up for the first time, but subsequent starts only took about 5-10 seconds. Mozilla took about 30 seconds to start, but once up, it surfed the ‘net quickly and no differently to a normal desktop installation. I was also able to use the optical drive and read the content of CD, DVD and Blu-ray media. I could also happily playback most media without issue after installing the Ubuntu Restricted Extras package as well.

Unfortunately desktop effects such as Compiz are not possible on the PS3 because the Hypervisor does not give you direct access to the PS3’s “RSX” GPU. This was a deliberate move by Sony to prevent homebrew games being developed. Not a great loss, however, as the PS3 is already a little hampered by the fact that it has less than 256MB of RAM to work with.

The PS3 is now “permanently” in Linux mode until you tell it to go back to the normal PS3 OS. If you shutdown and reboot (or indeed turn the console off and back on again), it will boot straight back to Linux every time. To get back to the PS3 OS, all you have to do is issue the following command at the kboot prompt, before Ubuntu starts to boot:

ps3-boot-game-os

…and hit Enter. The PS3 will shutdown, restart and next thing you know you’re looking at the PS3’s normal Xross-Media Bar (XMB) menu again. To get back into Linux again, you simply change the “default OS” back to “other OS” again and reboot when prompted.

Ubuntu is of course not the only Linux distribution that can be installed onto the PS3, and there are plenty of videos on YouTube of people using one or more PS3’s running Linux to great effect. Check them out!

Conclusion: It’s awesome that Sony allow people to play with their hardware (with certain restrictions) and makes the PS3 a far more attractive option to buy than the XBox360 or even the Wii. The latter two options really are geared towards playing games only whilst the PS3 can entertain you and help you with serious work, especially tapping into the awesome power of the PPC. For families who are a cash-strapped for a new PC, the speed of Ubuntu on the PS3 won’t blow you away, however it is perfectly viable to use as a cheap home computer that can also keep the kids happy and play high-definition Blu-ray movies, however after trying out Ubuntu on a regular TV display (an old Amiga 1084 monitor) for the hell of it, 576i takes me right back to the days of Amiga Workbench in 15KHz interlace complete with full flicker!! No, you really need to have a proper 720p or preferably a 1080p display to use Ubuntu properly, to not only keep the sanity of your vision but to give you enough desktop real estate to move around as well.

Review score: 8 out of 10

HowTo: Get SigmaTel STAC 9200 chipset audio working in Ubuntu Intrepid

I was asked to rebuild a friend’s old Medion laptop – you know, those ones Aldi used to sell for peanuts. It’s an AMD Turion64 based machine with NVidia GeForce Go 6100 gfx and SigmaTel STAC 9200 “High Definition” audio and a 1280×800 display. I have to admit it’s not a bad little machine.

Anyway, the default installation of Ubuntu Intrepid picks up everything except the Fn keys, wireless LAN adapter and the audio. The wireless LAN adapter has proven to be a bit of a challenge, so if I suss it out, I’ll write up about it later. Fn keys I’m not really fussed about (and neither is the laptop’s owner), but we needed the audio.

The SigmaTel STAC 9200 has a dotted history of frustration among Linux users in general, but thankfully it was fixed in Kernel 2.6.27-7 and Alsa 1.0.15. Unfortunately a vanilla installation of Ubuntu it still is unable to autodetect the hardware 100% properly (it will find it and name it, but all you get is silence), so you have to make one tiny manual adjustment before sound will work properly.

  1. Open up a terminal and type the following at the $ prompt:

    $ sudo gedit /etc/modprobe.d/alsa-base
  2. This opens up the file in the GEdit text editor. Scroll to the end of the file, hit Enter to make a new line and add the following:

    options snd-hda-intel model=gateway
  3. Save your changes and close the editor.
  4. Now reboot. When Ubuntu comes back, you will have working audio!

Note: Reader Mouhcine has suggested that if “model=gateway” does not work for you in step 2, try using “model=gateway-m4″ which may give you more success in Ubuntu Jaunty.

HowTo: Uninstall software that makes Ubuntu’s boot process fail

Whilst rebuilding a friend’s Medion laptop, in my attempt to get the Wireless LAN adapter working, I set about trying to use ndiswrapper and the Windows drivers. Unfortunately upon rebooting, the system failed to boot, always locking up when the boot process tried to load the Windows driver. It was so bad that I wasn’t even able to boot to a recovery prompt because it still attempts to load the hardware drivers before dropping you into a root shell.

The solution was simple – get rid of ndiswrapper and that will prevent the offending Windows driver loading which I can then delete afterwards, but how do you do this when you can’t even boot to a terminal?

With the assistance of an Ubuntu LiveCD (on USB stick in this case), I was able to remove ndiswrapper without needing to do a complete re-install of the system. Here’s how to do it.

  1. Shutdown your system, insert your Ubuntu LiveCD and turn on your system.
  2. Allow the system to boot to the LiveCD desktop and then open a terminal.
  3. Determine what your system’s root partition is called by getting a list of available drives and partitions with:

    $ sudo fdisk -l
  4. In my case, this Medion lappy had Windows installed and a couple of other partitions too. The root Linux partition ultimately resided on sda8, so I need to mount this somewhere. First I need a mountpoint:

    $ mkdir /dev/shm/medion

    …this creates a directory in the RAM disk called “medion” (but you can call it whatever you want).
  5. Now mount the partition to the mountpoint with:

    $ sudo mount /dev/sda8 /dev/shm/medion
  6. Check that we can access the mounted drive with:

    $ ls -l /dev/shm/medion
  7. If it contains the root filesystem of your lappy’s Ubuntu install, then you’ve done well so far. Now we need to change the system’s root filesystem from the LiveCD over to the hard-drive’s root filesystem so we can work on it. Type in:

    $ sudo chroot /dev/shm/medion
  8. This will temporarily make the current session’s root filesystem the one that is on your hard-drive, as though we’d actually booted from it. From here, it’s now a simple case of removing the ndiswrapper application that was causing all my problems (notice that we are at a root prompt designated by the hash symbol):

    # apt-get remove ndiswrapper-common
  9. A few warning messages popped up advising that it couldn’t find the log to write to, but that’s OK – the software still gets removed, and thus will prevent the Windows driver from killing the boot process. Once Apt had finished doing its thing, just type in:

    # exit

    …and the root filesystem will revert back to the LiveCD’s root filesystem.
  10. Shutdown and reboot as normal without the LiveCD, and viola – the system boots without hanging this time!

As you can see, the ability to change root filesystem can be very useful in trouble-shooting a non-booting installation but also has other uses too, one of the most common being creating custom LiveCD’s by modifying the squashfs filesystem on the LiveCD and burning to a new disc – thus allowing you to add or remove components from the default Ubuntu LiveCD environment.

HowTo: Encode a Blu-ray rip into a smaller format without losing quality

Those of you who archive or backup their Blu-ray movie media to hard-drive will already be aware that the average movie comes out at a good 25GB. Some of the bigger titles top out at around 40GB or more. This eats up an awful lot of disk space.

Blu-ray titles are already compressed down using the MPEG2 codec, and quality pundits will abhor the idea of re-compressing the title again for fear of losing image and audio quality. Certainly if you go down the Xvid route, you will definitely lose image quality, but as per my previous DVD HowTo, you can do excellent rips with virtually indistinguishable quality to the original using the x264 codec, and have a significantly smaller footprint to go with it.

The process of encoding a Blu-ray rip isn’t quite the same as doing a DVD, however, so here’s a quick guide on how to take your decrypted .m2ts file and finish up with a much smaller, but 99% perfect copy in a Matroska .mkv file.

Pre-requisites:

  • A pre-decoded Blu-ray movie file (.m2ts file).
  • Approximately the same amount of free disk space as the size of the movie file. Eg: If you have a 25GB movie file, then you should have another 25GB free space to work with. You can have less, since the final resulting file will be much smaller than the original movie anyway, but since this process can take a number of hours to complete, you don’t exactly want to discover you ran out of disk space and have to start over, do you?
  • A nice powerful CPU. I use a Intel quad-core Q9450 CPU at 2.66GHz. It takes my machine roughly 9-12 hours to process just one movie using four threads. A dual-core will take longer.
  • Time to let the PC do its work, eg: overnight.

This guide was written using Ubuntu 8.10 Intrepid Ibex 64-bit, but will work quite happily in 32-bit and should also work with most previous versions of Ubuntu.

  1. You will need some extra software installed if you haven’t already got it. Open a terminal and type in the following at the $ prompt:

    $ sudo apt-get install mencoder mplayer gpac x264 mkvtoolnix

    (Don’t worry if you’ve already got some of those apps installed, Ubuntu will skip over them if they already exist on your system)
  2. Create a new text file somewhere using your favourite text editor, eg:

    $ gedit ~/encodevideo.sh

    …will create a new text file called “encodevideo.sh” in the root of your Home directory using the GEdit text editor.
  3. Now copy and paste the following script into it:

    #! /bin/bash
    # =====================================================================
    # Blu-ray encoding script by HyRax February 2009 http://www.serenux.com
    # =====================================================================
    # Make sure the user has specified what to work on.
    if [ -z "$1" ]; then
    echo "\nBlu-ray movie encoding script\n-----------------------------"
    echo "Written by HyRax February 2009\nhttp://www.serenux.com"
    echo "\nUsage: $0 <m2ts file without extension>"
    echo "\nExample: If your movie file is called TheDarkKnight.m2ts then\nyour usage will be: $0 TheDarkKnight\n"
    exit
    fi

    # The crf=21 option controls encoding quality, and indirectly the final
    # filesize. The higher the value, the more compression and thus smaller
    # file size. Reduce the value and file size will go up. A value of 21
    # should produce a file of approximately 4GB in size for a typical movie.

    # Encode the video using x264, ignore the audio for now.
    mencoder $1.m2ts \
    -ovc x264 -x264encopts crf=21:frameref=3:bframes=3:b_pyramid=normal:direct_pred=auto:weight_b:partitions=all:8x8dct:me=umh:mixed_refs:trellis=1:nopsnr:nossim:subq=6:level_idc=41:threads=4 \
    -nosound \
    -of rawvideo \
    -o $1.x264

    # Dump the first original audio track (should be the English track) but
    # don't re-encode it. Ignore the video.
    mplayer $1.m2ts -dumpaudio -dumpfile $1.ac3

    # Copy the raw x264 encoded video into an MP4 container so we can set
    # the correct framerate (generally 23.976 - adjust it if MPlayer or
    # MEncoder report something different)
    MP4Box -add $1.x264 $1.mp4 -fps 23.976

    # Finally, merge everything into a single MKV file
    mkvmerge -o $1.mkv $1.mp4 --track-name 0:Eng $1.ac3

    # Remove the hash in front of the next command to have the script delete # your working files when encoding is complete.
    # rm $1.m2ts $1.x264 $1.ac3

    # Tell the user we're done.
    echo "All done! Your final movie file is called $1.mkv - enjoy!"

  4. Save and exit your text editor.
  5. Change directory to where you have your original .m2ts file, eg:

    $ cd ~/Videos/BDRips/MyMovie
  6. Let’s say your movie file is called TheIsland.m2ts. To begin encoding it, you will use the following command:

    $ sh ~/encodevideo.sh TheIsland

    (Notice that we don’t specify the file extension – the script assumes .m2ts on the end already)
  7. Hit enter and the encoding process will begin. The script does the following in order:
    1. Extract the video component only and encode it in a single pass to a raw x264 video file called TheIsland.x264 (in this example).
    2. When that has finished, go back and extract the first audio track only and save it to a file called TheIsland.ac3 without any re-encoding.
    3. When that has finished, take the raw x264 video data and put it into an MPEG4 container so we can fix the framerate at 23.976 frames per second, typical of most Blu-ray movies. If you don’t do this step, then the video will play faster than the audio in the final product.
    4. Finally we create a new Matroska container called TheIsland.mkv and in it we place the framerate-adjusted MPEG4 video track and the unmodified audio track, producing our final product..
  8. When the script has finished some 9-12 hours later, you will have a file called TheIsland.mkv ready for playback in Totem, MPlayer, VLC, or whatever your favourite player is. You will notice that the filesize is significantly smaller than the original but when you play it back, the image quality will look pretty much 100% identical to the original. About the only compression artefacts you may notice is around the edges of some text titles such as opening credits, but you’d really have to look hard to spot them.
  9. We’ve finished with the working files now, so you can delete the .m2ts, .x264 and .ac3 files now to reclaim the disk space and enjoy your new .mkv file.

Enjoy! Smilie: :)

NOTES:

  • While not covered by this HowTo (I’ll add to this later), you can optionally extract other audio tracks from the .m2ts file such as other languages or the commentary track, and add them to the .mkv file at any time. You can also download subtitles and add them to the .mkv file at a later date also, all without needing to re-encode the entire video again because all you’re doing is adding tracks to the existing Matroska container. see the man pages for the mkvmerge utility for more information.
  • A high-definition x264-encoded movie takes a fairly reasonable amount of CPU power to decode. Since Ubuntu Intrepid and previous versions do not make any direct use of on-board video decoding hardware such as that found on NVidia and ATi based video cards, you may find certain busy scenes in your movie may stutter or even skip altogether during playback – this does NOT mean you are missing data from your movie file – it’s just that your PC is having trouble decoding AND displaying the movie all at once because the CPU is doing everything, especially those with slower CPU’s. Indeed you will notice that your CPU usage will probably be quite high in the 80-90% region. Ubuntu Jaunty will bring forth with it VDPAU support for NVidia-based video cards (restricted NVidia driver v180 and above). Using a patched version of MPlayer with VDPAU support, all the decoding work is passed completely to the video card, freeing up your CPU considerably to concentrate on other tasks, and dropping utilisation rates down to about 3%. This makes busy movies that much more watchable. If you can’t wait for Jaunty, there are some backported VDPAU modified versions of mencoder, mplayer and even MythTV available here, however you try them at your own risk. If you are an ATi video card user, you’re out in the dark for the moment. Go buy yourself an NVidia card – they are much better supported under Ubuntu than ATi are.
  • If you are using only a dual-core processor, you should modify the threads=4 section of the mencoder line in the script to read either threads=2 or threads=3. If you are using a single-core processor, change this to threads=1 or threads=2 depending on how your CPU performs (and while you’re at it, seriously consider an upgrade!).
  • If you wish to modify the quality of the encoded video to make the resulting file larger or smaller, re-edit the encodevideo.sh script and change the crf=21 value in the mencoder line to a different value. There is no definitive filesize that the resulting encode will have. This value simply adjusts the quality of the encode. With some trial and error, I have found that the average 1080p movie encode ends up roughly 8GB in size when using a value of 21 and provides excellent image quality. If you make the value larger, this will apply greater compression and will reduce the final file size at the expense of losing some image quality. If you reduce the value, then your final file size will increase, however your image quality will also go up. As a guide, animated movies such as those made by Pixar and Dreamworks and visually dark movies such as Underworld, compress very well. In one instance, the final product was only 3.5GB in size. Visually complex movies such as Transformers blew out to 12GB in size using the same encoding script, so you can see that there is no exact science to this. There are mencoder options to specifically set bitrate and target filesize, but I chose to ignore those options for this HowTo as I’m a bit of a quality freak, not a size freak. I store all my movies on a MythTV server at home and backup to an external drive as I’m not a fan of doubling up my movie purchases on the shelf with a second disc containing the compressed version of the same movie!

Power failure!

My site’s been offline for most of the last 24 hours due to an unexpected power failure caused by a constant week and a half of rain shorting underground mains power lines, and taking half of my street with it. I have to admit I’ve been a bit complacent and have never acquired a UPS for the server that serves this blog!

But the power’s back now, and meantime I’ve gone and bought a shiny new UPS to keep the server running should there be any future power issues. Sorry the inconvenience, folks!