Wednesday, May 6, 2009

Zombie X

I'm having a weird and disturbing issue, in which my display completely freezes while watching a recording in MythTV. I've also seen this happen when trying to watch a video fullscreen with mplayer. So it seems to be a video issue. Sometimes the display blanks, sometimes the image freezes, but remains on screen.

When this happens, my only recourse is to ssh in from my laptop, and issue the commands:

sudo /etc/init.d/xdm stop

sudo /etc/init.d/xdm start

Note that sudo /etc/init.d/xdm restart does not work, which is weird, since all that does (IIUC) is to stop/start the daemon!

I have also noticed the following error dump in dmesg when this occurs:

[ 6734.516861] BUG: unable to handle kernel paging request at ffffc20011105428
[ 6734.516867] IP: [] ulReadMmRegisterUlongViaAddr+0x9/0x10 [fglrx]
[ 6734.516957] PGD 12fc08067 PUD 12fc09067 PMD 12eaf5067 PTE 0
[ 6734.516962] Oops: 0000 [#4] SMP
[ 6734.516965] last sysfs file: /sys/devices/pci0000:00/0000:00:18.3/resource
[ 6734.516968] CPU 1
[ 6734.516970] Modules linked in: lirc_mceusb2 lirc_dev video1394 dv1394 raw1394 fglrx(P) ohci1394 snd_hda_intel ieee1394 r8169 snd_hwdep
[ 6734.516981] Pid: 17277, comm: X Tainted: P D 2.6.28-gentoo-r5 #6
[ 6734.516983] RIP: 0010:[] [] ulReadMmRegisterUlongViaAddr+0x9/0x10 [fglrx]
[ 6734.517046] RSP: 0018:ffff880117075c90 EFLAGS: 00010286
[ 6734.517048] RAX: 0000000000000000 RBX: ffff880099859190 RCX: 0000000000000007
[ 6734.517050] RDX: 000000000000150a RSI: 000000000000150a RDI: ffffc20011100000
[ 6734.517053] RBP: ffffc20011100000 R08: 0000000000000000 R09: ffffffffa01939a0
[ 6734.517055] R10: 00000000000fdfe0 R11: ffff88012fc08000 R12: 000000000000150a
[ 6734.517058] R13: ffff880040e3b000 R14: 000000004068646a R15: ffff880038855f00
[ 6734.517061] FS: 00007fdefc2e36f0(0000) GS:ffff88012fc03980(0000) knlGS:00000000f7de36c0
[ 6734.517063] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[ 6734.517066] CR2: ffffc20011105428 CR3: 0000000117076000 CR4: 00000000000006a0
[ 6734.517068] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 6734.517071] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[ 6734.517073] Process X (pid: 17277, threadinfo ffff880117074000, task ffff8800a5488740)
[ 6734.517076] Stack:
[ 6734.517077] ffffffffa00d036b 00000000fdff0000 0000000000000202 ffff880099859000
[ 6734.517081] ffff880099859000 00007fff0430a6e0 ffffffffa00ec124 000000004068646a
[ 6734.517086] ffff880099859000 ffff880099859190 00007fff0430a6e0 ffff880040e3b000
[ 6734.517090] Call Trace:
[ 6734.517093] [] ? ulReadMmRegisterUlong+0x6b/0x140 [fglrx]
[ 6734.517132] [] ? Cail_RS780_RestoreAdapterCfgRegisters+0x24/0x190 [fglrx]
[ 6734.517132] [] ? CAILExit+0x15f/0x190 [fglrx]
[ 6734.517132] [] ? firegl_cail_free+0x3f/0x70 [fglrx]
[ 6734.517132] [] ? hal_init_asic+0x45a/0x5e0 [fglrx]
[ 6734.517132] [] ? capable+0x17/0x36
[ 6734.517132] [] ? hal_init_asic+0x0/0x5e0 [fglrx]
[ 6734.517132] [] ? firegl_ioctl+0x1ea/0xf40 [fglrx]
[ 6734.517132] [] ? ip_firegl_ioctl+0x11/0x13 [fglrx]
[ 6734.517132] [] ? vfs_ioctl+0x5f/0x78
[ 6734.517132] [] ? do_vfs_ioctl+0x37c/0x3aa
[ 6734.517132] [] ? fsnotify_modify+0x62/0x6a
[ 6734.517132] [] ? sys_ioctl+0x55/0x77
[ 6734.517132] [] ? system_call_fastpath+0x16/0x1b
[ 6734.517132] Code: 0f 85 0e ff ff ff 44 89 f2 44 89 ee 48 89 df e8 8e 4d 02 00 85 c0 0f 84 40 ff ff ff e9 f3 fe ff ff 90 31 c0 48 85 ff 74 05 89 f2 <8b> 04 97 c3 66 66 90 48 85 ff 74 05 89 f1 89 14 8f c3 66 66 90
[ 6734.517132] RIP [] ulReadMmRegisterUlongViaAddr+0x9/0x10 [fglrx]
[ 6734.517132] RSP
[ 6734.517132] CR2: ffffc20011105428
[ 6734.517132] ---[ end trace 3dbdfa876caf57b1 ]---
[ 6734.521254] [fglrx:firegl_release] *ERROR* device busy: 1 0
[ 6734.521258] [fglrx] release failed with code -EBUSY


Whoa, scary!

I looked through the Gentoo ATI Radeon FAQ, but didn't find much there. I did find this thread on the Gentoo forums. The person there describes a very similar problem, which he solved by switching to the "zen-sources" kernel.

I figure it's worth a try. zen-sources is not part of the normal Gentoo portage tree, it's in an "overlay", which is a 3rd-party portage tree. To install it, I followed their instructions. Basically: emerge layman; layman -a zen-sources; emerge zen-sources.

Kernel config/compile/install went smoothly, and the major subsystems (network/audio/Xorg) seem to function properly. I even remembered to re-emerge ati-drivers and lirc after installing the new kernel (since those packages provide kernel modules). I'll have to wait and see about the video stability...time for bed!

Update: zen-sources didn't resolve the stability issues. However, I did find a number of new resources online, including this helpful opensuse.org guide and the Unofficial wiki for the ATi Linux Driver.

Following the opensuse guide, I added some lines to the Device section of my xorg.conf (everything after "try these options..."):
Section "Device"

# Driver "radeonhd"
Identifier "Card0"
Driver "fglrx"
VendorName "ATI Technologies Inc"
BoardName "Radeon HD 3200 Graphics"
BusID "PCI:1:5:0"

#try these options to improve stability:
Option "VideoOverlay" "off"
Option "OpenGLOverlay" "off"
Option "TexturedVideo" "on"
Option "BlockSignalsOnLock" "on"
Option "KernelModuleParm" "locked-userpages=0"
Option "UseFastTLS" "2"
Option "UseInternalAGPGART" "no"
Option "mtrr" "off"
Option "no_accel" "no"
Option "EnablePrivateBackZ" "no"
Option "backingstore" "true"

EndSection


Time will tell if these options make it more stable...

The Long Slog: Unleash the photons!

Time to get the remote control working.

I followed the Gentoo LIRC wiki page, supplemented by the MythTV LIRC wiki page. I have a "Windows MCE" remote that came with my old Hauppauge USB WinTV receiver, which uses the "mceusb2" driver. So, the procedure for Gentoo is:


  • add LIRC_DEVICES="mceusb2" to /etc/make.conf.
  • emerge lirc
  • modprobe lirc_mceusb2
  • sudo echo lirc_mceusb2 >> /etc/modules.autoload/kernel-2.6


It worked after following these steps, although it wasn't very clear from the Gentoo wiki page that I would need to load a kernel module (the way I read it was that this was only needed in certain special circumstances).

[Edit: removed bitching about it not "just working"...getting old, Dr. Harris!]

Tuesday, May 5, 2009

The Long Slog: Firewire

I get my TV signal directly from my cable digital set-top box (STB), via its firewire port. This is really great, because the signal coming through that port is already a decoded MPEG2 stream, so there's no need to have a tuner card in your mythbox!

MythTV didn't recognize the STB on the firewire port. I had installed and modprobed the ieee1394 kernel module. I first tried following this guide, which got me up and running when I had a mythbuntu box, but it doesn't apply for Gentoo users. Then I found this guide, which seems to be just what the good doctor ordered. I added two more kernel modules: video1394 and raw1394.

After that, mythtv-setup instantly recognized the STB on the firewire port. I set it to p2p instead of Broadcast (which the above guide says is more stable). I should say, I skipped the p2p setup stuff in that guide; I'm interested to see if it will "just work". Why are you laughing?

Woo! It seems to be working! In your face, Murphy!

Addendum: I should note that I had to select "Broadcast" mode for my firewire capture card in mythtv-setup, rather than "P2P".

Monday, May 4, 2009

The Long Slog: Can you hear me now?

Next up: Get sound working.

I had compiled the wrong kernel driver before. For my onboard Realtek ACL889A card, I need the snd-intel-hd driver. With that fixed, I was able to run alsaconfig, which detected and set up my card. I then started up KDE, and opened the systemsettings tool (which I have to say is really nice, BTW...much better than KControlCenter!).

In the Multimedia section, I saw three options:

  • HDA ATI SB (ALC883 Analog)
  • HDA ATI HDMI (HDMI Audio output)
  • Jack Audio connection kit


I knew I wanted to use HDMI audio output, so I tried that one first; there's a "Test" button in the tool, and on pressing it...woohoo! I heard the dulcet chimes of the KDE startup tune. Woo. I set the HDMI option to be the default output for all sound categories, and pressed Apply. There is also a "Backend" tab in this tool. In my case, this tab has two options: Xine and GStreamer. Xine was selected by default. I also tried GStreamer, but it didn't work immediately, so I went right back to Xine (IIAB,DFI).

Well, it can't all be good news, right? I tried watching a recording in MythTV, and there's still no sound output. I also tried using mplayer directly, and that also lacks audio. Dragon Player does have audio (not too surprising, since it uses Xine as a backend). I found this really nice guide, which gave me lots of good ideas and brought me closer to success, but not there yet. What I mean is, sound still doesn't function in mplayer and mythtv, but at least now here are no error messages :/

I started a thread on the Gentoo forums; hopefully someone will have ideas.

Update: It works now. I don't know what I did to fix it, but both mplayer and MythTV now produce audio!

The Long Slog: More Xorg driver problems

As you may have read in a previous post, I've had some trouble getting Xorg set up on the new mythbox. I first tried getting the radeon driver to work, but it was segfaulting on startup, so I switched to the closed ATI driver (fglrx). That one caused my screen to go blank and become totally unresponsive to keyboard or mouse. Nice. So, I went back to the open source radeon driver (and its radeonhd variant). I eventually got a functional KDE session working, but for some reason MythTV segfaulted whenever I tried to start it. I eventually discovered that MythTV would run, but only if the Xorg GLX module was not loaded (i.e., no hardware-accelerated graphics). I was hoping this wouldn't be a big problem, but the video playback in mythtv was horribly jerky due to many dropped frames.

So, I went back to fglrx, and eventually muscled my way toward a working X session. The only remaining issues are that (1) glxgears reports a higher FPS when GLX is not loaded than when it is (which is pretty bizarre), and (2) I still get the blank-screen catatonia if I stop the Xorg process. I can live with that; under normal circumstances, there's no reason to stop it.

Sunday, May 3, 2009

Migrating MythTV

The task: migrate all my recordings and the mythtv database to the new mythbox.

Steps:

  • rsync the following directories: /myth/tv, /myth/video
  • mysqldump the database, copy the dump file over to the new machine
  • Install mythtv, mythtv-themes, and plugins: mytharchive, mythbrowser, mythdvd, mythflix, mythgallery, mythgame, mythmovies, mythmusic, mythnews, mythphone, mythvideo, mythweather

  • Unfortunately, mytharchive can't be installed, because it depends on mjpegtools-1.8, which is not itself compilable without manually patching the code. I'll just wait for the patch to be released...

  • Wow, mythbrowser also threw a compile error. Well, I don't really use that, so I'm not going to look into it now, I'll just skip it.

  • MythTV pulled in MySQL database as a dependency, but it needs to be configured. Run emerge --config =dev-db/mysql-5.0.70-r1. This will create the main database and set the password for the "root" DB user.

  • Next, start the mysql daemon (/etc/init.d/mysql start, and rc-update add mysql default for all future sessions).

    Edit /etc/mythtv/.mythtv/mysql.txt. Contents:
    DBHostName=localhost #if you aren't using a separate backend computer

    # By default, Myth tries to ping the DB host to see if it exists.
    # If your DB host or network doesn't accept pings, set this to no:
    #
    DBHostPing=no

    DBUserName=<your_db_username>
    DBPassword=<your_db_password>
    DBName=mythconverg #I believe this is typical; you may have to change it
    DBType=QMYSQL3


  • I'm unsure what the correct chronology is for the next few steps. Should I import the database dump from the old mythbox first, or run mythtv-setup first? I'm going to try importing the old database first. But before I do it, the mythconverg database needs to be created first:

    # mysql -u root -p
    mysql> create database mythconverg;
    Query OK, 1 row affected (0.00 sec)

    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    mysql> exit
    Bye


    Then we can issue the command to import the old database information: mysql -u root -p mythconverg < mythtv_backup.sql

  • All right. Next run mythtv-setup. Funny story. It segfaults! No indication why, but digging around in the excellent Gentoo forums revealed this thread, which indicates that the problem is related to video drivers/opengl/mesa. Here's what I did to try to solve it:

    • Unmask mesa-7.4, and emerge it (required unmasking a couple of dependencies as well).
    • I discovered in that thread that there's a "radeonhd" driver, so i am going to try to use that instead of the regular "radeon" driver. So, I also ran emerge xf86-video-radeonhd
    • re-emerge xorg-server and mythtv.
    • revdep-rebuild to recompile dependencies.
    • Reboot to pull in all changes.


    Unfortunately, that didn't work. The other solution in that thread was to disable glx in xorg.conf. That worked; hopefully I won't miss GLX too much :/

    The nice thing was that importing the database from the old mythbox pulled in all of my configuration information as well, so there was very little to change in mythtv-setup!

  • Next, run mythfilldatabase.

  • Start mythbackend: /etc/init.d/mythbackend start, and for all future sessions: rc-update add mythbackend default. This didn't work right away, because I didn't realize that on gentoo, the backend gets the DB information from /etc/mythtv/.mythtv/mysql.txt, not from ~/.mythtv/mysql.txt.

  • Try running mythfrontend and watching a recording (which had been ported over from the old mythbox). Well, it worked, but there's no sound and the video playback is extremely poor quality, because I've disabled GLX in xorg.conf! Argh, what am I to do?

  • Get sound working. This was silly of me: I didn't select my motherboard's sound card in the kernel config. Now I'm compiling it as a module and will add it to modules.autoload. Then I had to emerge alsa-utils, then run alsaconf, then /etc/init.d/alsasound and rc-update add alsasound default.
    Darn: alsaconf doesn't appear to know about my sound chip. Or maybe I misidentified it in the kernel...I'm seeing another module name in the forums.

  • Get firewire connection to cable box working - TBD

  • Get the remote working - TBD

  • Fix deinterlacing settings, if necessary - TBD

  • Get auto shutdown/wakeup working - TBD


I'm already sick of this...

Saturday, May 2, 2009

New Mythbox!

We finally got a cabinet for our home theater stack, which is good, because our daughter is just about to start walking! I had three simple criteria for the cabinet: big enough to hold our components, made of wood, and with glass-front doors that can be child-proofed. It was surprisingly difficult to find something that fit the bill.

Anyway, this post isn't about the cabinet, but the subsequent upgrade that the cabinet instigated: the mythbox is a regular tower PC, so to fit in the cabinet it has to lay on its side, which makes the DVD drive unusable. This doesn't seem like too big a deal, but taken together with my other peeves about that system (very loud fans; looks ugly and out of place in the living room; lacks the horsepower needed to decode HD video; and a fragile and increasingly complex disk partition layout that is perpetually threatening to overrun its capacity). That's right: time for a new Mythbox!

Let's go shopping!



This time, I decided to do it Right: get a media-center computer case with very quiet fans, a decent CPU/GPU that might have a chance to playback HD video, and a single large SATA hard drive that I can partition in a non-insane way to accommodate our needs. It's really amazing how much system can be had for less that $400 these days:


  • Case: Antec NSK 2480 [$100]. This clean aluminum media case looks a lot like a normal piece of A/V equipment, and the internal layout is really thoughtfully designed (apparently, an internet-famous case fetishist was heavily involved). This thing is dead quiet, too. This may sound like hyperbole, but it's literally true: when I first powered it on, I thought I must have missed a connection somewhere, because I didn't think it was on!

  • CPU: AMD Athlon X2 4050e 2.1 GHz dual-core [$40]. The fact that this level of computing power is available for the cost of dinner for two is really really stupid in a really good way. 40 bucks...unbelieveable! I could have spent $70, which would have bumped it up to 2.8 GHz, but really, what's the point? I'd just be chasing a number at that point, I think.

  • MoBo: Gigabyte GA-MA78GPM-UD2H [$100]. I needed a MicroATX form factor for the Antec case, and an AM2 socket for the CPU. I wanted good onboard video/sound/ethernet, and with SATA and Firewire controllers built-in. Oh, and I wanted HDMI and digital audio outputs so I can plug it directly into my Sony soundbar, so I can get rid of my crazy routing through the TV. This one fit the bill, and I've been happy with Gigabyte boards in the past. I'm hoping the onboard Radeon GPU will have enough firepower to decode HD video, but I actually haven't finished setting it all up yet, so we'll see...

  • RAM: OCZ 2x2GB DDR2 800 SDRAM [$50]. RAM is now $10 per GB. That's sick...I remember paying ten times that not to long ago! I love it.

  • HD: WD Caviar Green 1TB [$90]. Not to harp on about how cheap all this tech is (too late!), but ten years ago, someone I knew paid a few thousand dollars for an 18GB hard drive.


And...that's it! Build your own mythbox in five easy pieces. Well, not quite. Normally, I'd have to buy a DVD drive too, but I'm harvesting the one from my Linux-box-that-went-boom. Also, I didn't realize that the CPU didn't come with a heatsink/fan, so I had to run to Fry's to pick one up. Can I just say, the CPU cooling market is getting a bit out of hand. There were all kinds of enormous coolers on the shelf, many with copper tubing and "blingy" LED effects (/me eyeroll...does *anyone* think that's cool?). Some of these were only around $40, but I just couldn't bring myself to buy something so ridiculously overengineered (or rather, I should say, so perfectly marketed to a demographic to which I don't belong). I got a nice, circumspect Thermaltake unit for $20.

Byte by Byte, putting it together...



I like assembling my own system. It's fun! I opened the case, surveying and appreciating all of the little features the case fetishist added to its design. First, you seat the motherboard, aligning its back ports with the port panel on the case. Once it's been screwed into place, carefully seat the CPU. The next step is probably the most difficult: seating the heatsink/fan onto the CPU. It's held in place with a clamp which exerts quite a bit of down pressure on the CPU, to maintain excellent thermal contact. This makes it a bit difficult to clamp on. I'll just note that the clamp designs are much better now than several years ago; I'll never forget a build about 5 years ago, during which I just about punctured a mobo with a flathead screwdriver, with which I was attempting to force a heatsink clamp into place. Ouch. Amazingly, it still worked after that...

Anyway, next up is to seat the memory sticks, and install the HD and DVD drive. Then all that remains is to thread all of the cabling: power to mobo, fans, disks; data from disks to mobo; connect front panel lights and switches to mobo. Voila! Done.

Installing Linux



Dear reader, you and I both know that I've been complaining too much lately about how Linux doesn't "just work" often enough. How I would love to tell you it had gone differently this time. Alas, I cannot.


  • First attempt: Kubuntu-9.04. This was released just a few days ago. I was pretty happy with Kubuntu-8.10 on the old mythbox, so this was the logical choice. Unfortunately, the new mythbox was behaving very erratically during the install. I was seeing weird errors during bootup ("ata1: Softreset failed (Device not ready)"), and frequent stalls and freezes during the installation process. This was pretty frustrating; I probably hard-reset the machine a dozen times trying to get it to install. Googling the problem was not very enlightening, but I did see that others were having similar problems with Ubuntu-9.10 and Gigabyte Mobos, so I was somewhat relieved that it might not be a hardware problem.

  • Second attempt: Kubuntu-8.10. I still had the install CD I burned for the old mythbox, so i gave it a try. Unfortunately, I had the same instability issues.

  • Third attempt: OpenSUSE 11.1 (KDE4 Reload edition). OpenSUSE and I have a colorful history. I have heard good things about it over the years, and have tried to check it out several times, but in all those attempts, I have never been able to install it successfully. I am not exactly a linux newbie, so this has always been pretty frustrating for me. When I've tried to report my issues, I'm basically told that I must have "weird hardware". I am sad to report that my latest experience with OpenSUSE was no better. As with Kubuntu, I couldn't even get through the installation process due to my system freezing up.

  • Fourth attempt: I decided to return to the comfortable embrace of my old friend, Gentoo. At this point, I was becoming more convinced that some component was either defective, or simply so new that it wasn't supported well in the kernel. Either way, I saw an RMA in my future, which is always sad.

    But then...surprise! I had no instability issues whatsoever under Gentoo. No weird messages, no interruptions, no hard resets! The installation process went very smoothly. Well, if you've never done a Gentoo install before, it's way, way more hands-on than Kubuntu or OpenSUSE. With those distros, you select you language, give a partition layout, and press Go. With Gentoo, you almost literally build your OS from scratch. You download a pre-fab compile chain and system toolset, but literally everything else is compiled on the fly, including the kernel. It's kind of fun, if you're into that sort of thing!


Reaching the Desktop: Installing KDE



Once the base installation is complete, the next step is to type emerge kde, which takes many hours to compile (due to dependencies, that one command represents almost 600 packages, including little things like, oh...xorg-x11). So, there's plenty of time to go see a movie, have dinner with friends, get a good night's sleep, and check on its progress in the morning I executed the emerge kde command on Saturday afternoon, around 2:00 pm. It finished around 9:00 am the next day! The good news is, there were zero issues encountered in compiling and installing those 600 packages.

That's not to say there were no issues in trying to use the packages, though. I don't usually go into microscopic detail about why I am sometimes frustrated that Linux is not easier to use (or rather, to administer...I actually think it's already very easy to use); I think this particular case may be illustrative of my general experience:


  • KDE is finally installed. Great! So, let's use it. Start the xdm graphical login service (/etc/init.d/xdm start): FAILED: it's mis-configured to use xdm (which is not even installed) instead of kdm.

  • Find correct configuration file where the DISPLAYMANAGER environment variable lives. It's currently in /etc/conf.d/xdm. Set the variable to "kdm" even though the comments in that file instruct that it should be "kde-NN" where NN is the KDE version number. The comments are wrong/deprecated.

  • Try /etc/init.d/xdm start again: FAILED. Xorg starts momentarily, then I am dumped back to the vt text console with no error message.

  • Try bypassing the login manager by executing Xorg & startkde: FAILED. X starts, shows the default grey mesh screen with X cursor, but the keyboard and mouse are unresponsive, so there's nothing to do but hard-reset.

  • Google around, find a message board post saying that I need to enable the Hardware Abstraction Layer daemon. So, execute /etc/init.d/hald start (and do rc-update add hald default so it gets started at boot from now on). Try Xorg again: MARGINAL. Keyboard and mouse work, but the Xorg is not configured correctly.

  • Run xorgcfg to configure X: FAILED. Error: ":1.1 is not allowed to own the service org.x.config.display0"

  • Instead of googling that error, just try an alternative configurator: Xorg -configure: MARGINAL. Creates a viable xorg.conf file, which I place in /etc/X11. I can now successfully log into a KDE-4.2 session using the KDM login manager! BUT: it looks terrible. The screen resolution is 1440x900 instead of 1920x1080, so everything looks blurry due to the pixel resampling. I definitely need to use my TV's full screen resolution.

  • Install ati-drivers to get better X performance and full 1920x1080 screen resolution: FAILED. Missing kernel option "Enable unused/obsolete exported symbols". Reconfigure / compile / install the kernel. Reboot.

  • Try to install ati-drivers again: FAILED. "ati-drivers-8.552 requires support for pci_find_slot". No hint this time where to find that option in the kernel's menuconfig. Google for it: find this bug report. Basically, I also need "Enable deprecated pci_find_* API" option in my kernel. Sigh. Reconfig / compile / install kernel (again!). Reboot.

  • Try to install ati-drivers a third time: FAILED. Got message from the ebuild: "DRM support is enabled builtin, so direct rendering will not work". Argh! That means I have to Reconfig / compile / install kernel (third time!). Reboot.

  • Try to install ati-drivers a fourth time: SUCCESS!

  • Run aticonfig --initial to tweak xorg.conf for new driver and DRI settings: SUCCESS

  • Execute eselect opengl set ati to enable ATI hardware-accelerated openGL.

  • Start KDM: FAILED! Screen goes black, no response from keyboard. Hard reset.

  • Go back to my original xorg.conf file. I guess I will have to tweak it by hand to enable what I need, which is pretty ridiculous. Try setting the Driver parameter to radeon, which is the open-source driver for ATI cards: FAILED. This causes Xorg to throw a signal 11 error with a useless backtrace. So, let's review: I can use the generic vesa driver and get an ugly undersampled desktop, use the open-source radeon driver and get an immediate Xorg crash, or use the closed ATI driver and get a blank screen. Neat!

  • Digging into this issue, I discovered that my emerge kde command did NOT actually pull in xorg-x11 as a dependency! That seems really weird to me. It obviously pulled in *some* X11 stuff, since I am able to start an X session. I don't understand all of the overlapping X packages, but it would seem pretty important to have xorg-x11. So I emerge it, and it brings about ten friends along for the ride.

  • Next I decided to nuke the ATI closed drivers, and just try getting the "radeon" driver working. I ran X -configure again, and then manually changed the "Driver" to radeon (instead of vesa): SUCCESS! I finally have a KDE desktop at full resolution, and glxinfo says I have direct rendering enabled. However, glxgears is pretty slow (~500, would like to see a few thousand).

  • Though glxinfo claims direct rendering is enabled, Xorg.0.log tells a different story:
    (EE) RADEON(0): [dri] RADEONDRIGetVersion failed to open the DRM
    [dri] Disabling DRI.
    (==) RADEON(0): Will attempt to use R6xx/R7xx EXA support if DRI is enabled.
    ABI class: X.Org Video Driver, version 4.1
    (II) AIGLX: Screen 0 is not DRI capable
    (II) AIGLX: Loaded and initialized /usr/lib64/dri/swrast_dri.so
    (II) GLX: Initialized DRISWRAST GL provider for screen 0
    Module class: X.Org XInput Driver
    ABI class: X.Org XInput driver, version 2.1


    So it looks like hardware DRI failed, so it's falling back to software DRI. A little more digging around led me to conclude that DRI is simply not supported yet for my video card. It's expected in kernel version 2.6.30, so I'll just wait for that.


This post is really long, so I'm going to write about setting up MythTV in a new post. See you there!

Sunday, April 12, 2009

Mytharchive blues

Mytharchive is a MythTV tool that allows you to create DVDs from recorded programs. In theory, anyway.

I spent a frustrating weekend trying to create a DVD from recorded episodes of "Planet Earth"...what a fiasco!


  • First frustration: a "skiplist" is not the same as a "cutlist". So, even if commercials get skipped while watching a recording in MythTV, that isn't enough to ensure that they will be skipped when creating the DVD as well. This distinction seems really unnecessary from a user's point of view. Anyway, you have to watch the recording in MythTV, then press "E" to enter Edit mode, then press "Z" to turn the skiplist into a cutlist.

  • First attempt to use Mytharchive: After navigating a really disorganized and confusing multipage setup interface (par for the course in MythTV land), I get to the actual execution screen, which displays a Log of the activity. The log remains totally blank. No indication of what's happening, what's going wrong. Nothing. After some googling, I discover that this happens if there are some lock files from a previous mytharchive run hanging around. Once these are deleted, it will work correctly. Would be nice if Mytharchive would actually tell me that these lock files are preventing it from executing! Hey, maybe even offer to delete them for me. Crazy, I know.

  • Second attempt to use Mytharchive: Unspecified error when trying to run ffmpeg. Googling led to this thread. Basically, I needed to replace some obscure support packages with "unstripped" variants (whatever the heck that means).

  • Third attempt to use Mytharchive: After the above fix, I finally get a burned DVD...but it's unplayable in every DVD player I have access to, except my Macbook Pro. Even MythTV is unable to play its own DVD.

  • Fourth attempt: I copied the ISO image from #3 over to my Macbook Pro, and used the OS X Disk Utility program to burn it to disc. This DVD is playable on all my computers (Mac, Windows and Ubuntu), but not on my relatively new Sony DVD player (which complains about "region resrictions", even though the disc is region-free.

  • Fifth attempt: I tried to use devede to create the DVD ISO image, but gave up in extreme frustration after a few hours spent trying to get mythtranscode to produce copies of the video files with the commercials stripped out. This process is so arcane and unnecessarily difficult, it just makes me want to throw my machine out the window just thinking about it. Really, really, really user-unfriendly.


So, I'm stuck. I can make DVDs that can be played on computers, but not on my DVD player, but this process requires two computers and is far more hands-on than I was hoping for. My God, is it too much to ask that I just insert a blank DVD, tell it which recordings I want, and press "GO"? Apparently, yes. Yes it is.

And I didn't even get to the fact that all of the menu themes look like monkey-butt, and that the videos seem to suffer from really bad interlacing artifacts...ay, carumba!

Thursday, April 9, 2009

Bye-bye iPhoto!

It was the last straw.

We've been using iPhoto on a mac laptop to manage our rather large photo collection for years. It's nice software for "average" use, but we seem to have outgrown it. We want to store photos on our NAS drive so that they will be accessible from any machine. However, because we have two versions of iLife on our macs, this is a bit problematic. It's also become annoying that iPhoto seems so slow to open and interact with sometimes.

The last straw came the other day, when we opened iPhoto and saw...nothing. Zero photos. I quickly went to the "Originals" folder (hidden inside the locked "iPhoto Library" directory), and was relieved to see all of our photos were still intact. However, I could not convince iPhoto of this fact. As far as it was concerned, we had never taken a digital photo in our lives. I tried googling a few fixes, but then I decided I'd just had enough.

I've installed Digikam on the mythbox, and we'll use that to manage our photo collection from now on. I haven't used it in years, and I really liked it back then, so I'm excited to see what the devs have been up to in the meantime.

By the way, installing digikam was not a no-brainer. A simple sudo aptitude install digikam failed because the normal digikam package is incompatible with KDE-4.2. I followed these instructions to add a PPa repository for new Digikam-0.10 packages that are compatible with KDE-4.2. That's life on the cutting edge, I guess.

Thursday, April 2, 2009

Disk full!

Last night, the root partition on my mythbox reached 100% capacity. I've been dreading this moment, because the partition is rather small (4.6 GB) and has been more than 80% full for a while now. What put it over the edge? Last night, I attempted to burn some recordings to DVD with MythArchive, and the transcoded MPEG file (which would take up to 4 GB for a full DVD) gets stored under /var/lib. Oops.

I'm actually rather impressed that the system didn't die or even panic; processes that needed disk access simply quietly failed. Unfortunately, one of these processes was mythfilldatabase, so I managed to miss a recording due to this issue.

To mitigate this full disk problem, I had the brilliant idea of moving part of my root partition onto my /myth partition (which is ridiculously huge compared to root), and then symlinking it back to its original location. I wasn't crazy enough to try doing this with anything really critical, like /usr or /bin, but I thought /usr/share would be reasonably safe. I used rsync to copy files over to /myth, and then rebooted. The system came back up fine, but then MythTV launched into a database setup screen. Oh. No. Did I somehow hose my MythTV database?! But no, it was just that the MySQL daemon wouldn't start with a symlinked /usr/share for reasons that I can't even pretend to comprehend. After restoring the original /usr/share, MySQL and MythTV behaved normally.

I settled on moving/symlinking large /usr/share subdirectories, like kde4, doc, fonts, and foomatic. THis seems to be working fine, and it allowed me to free up almost 1 GB of acreage on root. Not too shabby.

Someday soon, I'm going to just stick another disk in the machine. Disks are so cheap these days. Heck, I even have a 500GB disk laying around (from a linux box that went boom), but it's SATA, so I first need to buy a controller card.

Monday, March 16, 2009

Sony HT-CT100

When we moved to California, I sold my trusty old Yamaha home theater system, because I knew I was going to transition to HD after the move, and ol' Yama wasn't up to it.

Fast forward five months, and we're still pumping sound through the built-in speakers on the TV. I wanted a nice-sounding system, but didn't want to run speaker wires all over the room. Then I discovered this baby. 3 HDMI inputs, 4 digital audio inputs (3 optical, 1 coax), and one regular RCA analog audio input. Outputs HDMI video to your TV. Less than $300 on Amazon. Sweet.

We just took delivery on Friday, and setting it up was a breeze. I only hit one wrinkle: my mythbox outputs HDMI, but that is a video-only signal (I have a DVI-to-HDMI converter plugged into the box's video card). It doesn't seem possible for the CT100 to receive a video-only HDMI signal and handle audio separately through another input. Fortunately, my TV does allow for this. I cracked the manual and discovered that the advanced audio menu allows you to specify an alternate audio input for any of the HDMI inputs. So, the mythbox HDMI goes directly to an input on the TV, rather than getting routed through the CT100 like the other components. The audio signal is also routed to a TV input, and then sent back down to the CT100 through the TV's digital optical out. So, a bit circuitous, but it works!

Sunday, March 15, 2009

Eye Candy

Ok, enough complaining! Here's a couple of screenshots showing the fruits of my labor in getting my mythbox up and running.

My beautiful KDE 4.2 desktop, scaled down from the native 1920x1080 resolution:



And here is the MythTV main screen:



Ain't it purty?

MythTV can forget how to decode mpegs

Today I was surprised to find that my mythbox was unable to play back any of my recorded programs, including some of which I had watched as recently as yesterday!

By starting mythfrontend from a konsole, I was able to see an error message like:

NVP: Couldn't find a matching decoder for: [path to mpeg file].

Hmm, really? MythTV can't decode an mpeg file?

After some surprisingly futile googling, I eventually hit on the explanation: Last night, I had instructed my mythbox to record a movie on some channel that I apparently don't actually get. So the video file for this recording was somehow corrupt. Ok, so how would that cause mythtv to be unable to play the rest of my recordings? Is the corruption contagious? No, I think the answer is in the thumbnail preview shown for the selected video in the list of recordings. Since the invalid video was the first in the list, mythtv always tried to show its preview. Somehow, the decoder found this file so distasteful, that it refused to chew on any of my other mpeg files!

Anyway, I deleted the offending recording: problem solved. Since it would be nice if MythTV didn't choke up like this when given a corrupt video file, I filed a bug report describing the problem.

Tuesday, March 3, 2009

Make mythfilldatabase Run Automatically

Mythfilldatabase is supposed to run automatically, but it wasn't happening on my new myth-0.21 setup. I found the answer on this page: Although it is the backend that is in charge of running mythfilldatabase automatically, the checkbox to activate it is in the frontend config! I'm pretty sure that this checkbox was in the backend config in 0.20, and it doesn't make a lot of sense to me that it's now in the frontend. But, whatever. It works now.

Oh, and that page also pointed me to a perl script that will download icons for all of the channels in your lineup. Although, the name of the script has apparently changed, because it's called channel_icons.pl on my system. For some bizarre reason, the perl script was gzipped on disk, so I had to gunzip it before running it. Come on, people, it's only 21kB unzipped! I think my disk can handle it. Anyway, once I gunzipped it, I invoked it like: perl /usr/share/doc/mythtv-backend/contrib/ icons/master_iconmap/channel_icons.pl --find-missing --rescan. It worked like a charm, but I had to manually search for many of the channels.

Friday, February 27, 2009

I may write a MythTV Plasmoid

Instead of running MythWelcome, I think it would be really cool to have a MythTV plasmoid on my KDE-4.2 desktop that fills the same role. I'm surprised no one has written one yet. There is a MythTV dataengine in SVN, but nothing's been done with it AFAICT.

The Plasmoid would show basically what you see in MythWelcome: Current activity ("recording Program X", "gathering EPG data", "flagging commercials", "idle", etc), and the next scheduled recording. In addition, I might show the date of the last successful mythfilldatabase. Finally, there would be buttons to start/override the idle shutdown timer, launch the frontend, start/stop the backend, and run mythfilldatabase.

On a mostly-unrelated note, I need to figure out why mythfilldatabase is not running automatically. I noticed this morning that it hadn't run in 12 days! It's supposed to run daily.

Sunday, February 22, 2009

Tweaking MythTV settings


  • MythBuntu's MythTV did not set the bookmark when exiting playback by default, so if I returned to a program, it would always start at the beginning. Fixed the setting in the frontend setup, Playback, page 2: On exit (change from "Just Exit" to "Save position and exit").

  • De-interlacing: displaying an interlaced signal on a progressive-scan display creates really distracting horizontal artifacts in scenes with a lot of motion. To fix this, I went to the Utilities/Setup menu in the frontend, under Setup, TV Settings, Playback. Then go to Page 3.

    There you will see a combobox labeled Current Video Playback Profile; set it to Normal (it was "CPU+" by default on my machine). The Normal profile includes reasonable de-interlacing algorithms which work fine for me. You can also hand-edit any of the profiles, including at least half a dozen different de-interlacing options. Ah, Linux!

Friday, February 20, 2009

Adding metadata to orphaned video files

I have a bunch of videos that no longer exist in my mythtv DB, and so I don't have title/series information for these files. I want to find a way to add metadata to these files easily.


This looks pretty interesting.


Well, I gave up looking. I'm just renaming my video files manually now, which is pretty cumbersome, but not too bad.

Linkstation Redux

When I switched from Knoppmyth to Mythbuntu, one of the casualties was that my awesome Linkstation NAS stopped working. Specifically, mythbuntu wouldn't mount it. After some googling and experimenting, I arrived at a solution. On Ubuntu, you have to use the "Samba" format for specifying the server name. i.e., instead of 192.168.1.127:/share, you have to use //192.168.1.127/share. Note that this doesn't imply that you use smbfs for the filesystem type; it's still cifs. I don't claim to understand these things, dear reader...


So, now a command like this mounts my NAS:

mount -t cifs -o user=admin //192.168.1.127/share /mnt/netdisk


And the /etc/fstab to auto-mount the disk on boot looks like:
//192.168.1.127/share /mnt/netdisk cifs user=admin,rw,defaults 0 0


The big mystery in this change is that specifying credentials=/root/.creds instead of user=admin doesn't work! So why is my Linkstation mounting without a password? Who knows. Luckily, I don't care that much (sorry crypto-geeks!)

Installing KDE-4.2 on Mythbuntu

I'm new to the whole *buntu scene, having recently abandoned planet Gentoo. So I'm not hip to all the package management tools yet.


The command-line tool I've been using to install packages is aptitude. I'm comfortable with its operational similarity to Gentoo's emerge, but I haven't learned all the ins and outs yet.


Anyway, I want to get KDE-4.2 going on my mythbox, so (with full realization of the futility of such naive ambition), I simply executed the command aptitude install -t experimental kde. And...it worked!


Ha, only kidding. Well, it did work, but it installed KDE-4.1. So I started looking around for instructions on how to get the New Hotness, and found this page. The most useful info there is (a) how to add a third-party repo, including GPG keys; and (b), that I should install "kubuntu-desktop" instead of "kde".


My first attempt to install the 4.2 packages failed due to conflicts with the 4.1 packages that I didn't mean to install. So, I next did sudo aptitude remove kde to wipe the 4.1 KDE packages off my disk, and then I did sudo aptitude install kubuntu-desktop. I'm unclear on the operational difference between kde and kubuntu-desktop as a metapackage name, but I suspect kubuntu-desktop pulls in non-KDE things like Open Office.


Anyway, things seemed to go fine installing kubuntu-desktop...until I tried to use it. First of all, aptitude had asked me if I want to use KDM as my login manager instead of gdm, and I said yes. But when I logged out of my XFCE session and restarted X (Ctrl+Alt+Backspace!), I was presented with gdm, not kdm. Worse, KDE was not present in the Sessions menu!


So, to fix this I simply repeated the installation command: sudo aptitude install kubuntu-desktop, hoping that it would find a couple of errors. To my amazement, it told me that over 100 packages needed to be installed! Whoa, that first install didn't go too well, yet it didn't complain. After that process finished, I repeated it again because this time I did notice that about seven packages had errors. After the third iteration of the installation command, it finally reported no errors. This was on a system that was ostensibly clean of any KDE packages.


Ok, all KDE packages are now installed. No errors reported. Log out, restart X...and we get KDM! Awesome, full steam ahead, right? Ah, sweet naive optimism...


Logging in, I get the gorgeous KDE 4.2 desktop. But when I try to open an application, I discover that there is no window manager running (i.e., the application window has no frame, and it won't accept keyboard focus. The usual googling producs no solutions for this problem, so I jump onto #kubuntu on IRC where Slartibartfast points me to the solution:
the command sudo aptitude install kubuntu-desktop installs all of the KDE-related packages, and there are well over 100 of these. It does NOT, however, install the library libkdecorations.so, on which kwin is critically dependent. This is the kind of bug that really should have been caught by the packagers, and I'm sure it will be fixed soon. For now, if you install KDE-4.2 on *buntu, make sure you also do sudo aptitude install libkdecorations.


After that last hoop-jump, I was at last released into the beautiful garden that is a fully functional KDE-4.2 desktop. It's very nice, but there's still some plasma fragility (e.g., I don't recommend attempting to increase the height of the panel!). What's he lesson in all of this? We have some incredibly cool Free Software available these days, and I am truly grateful to all of those who contribute their time to not only develop these programs, but to attempt to package them into an easy, user friendly system. We've made great strides on usability, but it seems we are not quite there, because I keep hitting these walls that require quite a bit of hackery to get around. Now, I will admit that I am usually trying to "push the envelope" when I hit these walls, so if I simply accepted what the packagers gave me by default, I wouldn't have half of my problems (i.e., if I had accepted KDE-4.1 instead of demanding the latest-and-greatest). Anyway, kudos to the KDE developers and the Kubuntu packagers alike.

Wednesday, February 18, 2009

Mythbuntu: Awesomeness and Annoyances

I recently switched distros on my Mythbox from Knoppmyth to Mythbuntu, because I couldn't get my new wireless keyboard/mouse combo to work under Knoppmyth. I'm generally quite pleased with Mythbuntu, and find it to be much more polished than Knoppmyth. There are some weirdnesses, though. This post collects some of my experiences in setting up my Mythbuntu box. Note that not all of these are directly related to Mythbuntu.

Transferring my LVM disk



My mythbox uses LVM to glob three separate partitions into one 600 GB monster mounted as /myth, which holds all of my recordings and other media. It's an ugly solution, but it works for now. The problem is, you can't simply reinstall Linux and hope that an LVM partition will "just work" like a normal partition would. Fortunately, it's pretty straightforward to do the transfer (the following instructions assume the LVM partition is named "vg", and that it is mounted at /myth):


  • Backup all of the data in the LVM partition!
  • Prior to reinstalling the system!, unmount the /myth partition, and "deactivate" the LVM partition by typing vgchange -an vg.
  • "Export" the LVM partition by typing vgexport vg. This allows the new linux system to recognize that the physical partitions are part of a LVM group.
  • Install your new linux system
  • Verify that the partitions are recognized as part of an LVM group with the command pvscan. You should see your partitions listed as "inactive" and "part of EXPORTED VG 'vg'". Note the partition names listed (e.g., /dev/sda1).
  • "Import" the LVM partition using the command vgimport vg /dev/sda1 ... (where instead of /dev/sda1 ..., you put a space-separated list of the partitions).
  • "Activate the LVM partition: vgchange -ay vg.
  • Mount the partition: mkdir /myth; mount /dev/vg /myth and verify that your data are intact.
  • Add a line to your fstab so that the partition will auto-mount in the future.



No TV signal



This problem actually also happened on KnoppMyth, right after I hooked up my Comcast Digital STB via Firewire. The STB was automatically detected by mythtv-setup, but when I set the starting channel to "2", I got no signal when watching TV. Same story after switching to Mythbuntu. In both cases, I modified the starting channel to "9" (our local PBS station), and then it "just worked". Channel 2 is a valid channel that I can tune now with no problem. *shrug*


Sound stopped working



Sound worked out-of-the-box at first, but then it inexplicably stopped after a few days. I eventually ran alsamixer and saw that the problem was that the master channel had been muted somehow. I have no idea how that happened, but it's pretty annoying; what if I was a new Linux user who didn't know about alsamixer and didn't care to find out about it? Wouldn't it be nice if sound didn't spontaneously mute itself and require a command-line tool to fix it?


Auto-shutdown from MythWelcome didn't work



With system idling in MythWelcome, the shutdown timer would count down to zero, and then reset to 300 sec, rather than shutting down the system. By starting mythwelcome from an xterm on the desktop, I was able to figure out the problem from the console output: sudo was asking for the mythtv user's password. This was resolved by adding the mythtv user to the "sudo" group with sudo usermod -G sudo mythtv, and changing the /etc/sudoers file so that it wouldn't prompt for a password. Worked like a charm after that (but wouldn't it be nice if it worked this way out of the box?)


mythtv user can't access the MySQL database



I never figured out why, but mysql does not allow access by the mythtv user. I changed my setup so that my "normal" user does the access instead. It would definitely be nice if I didn't have to muck about with the database like this (although, to be fair, this may have happened because I imported my DB from my previous KnoppMyth installation...)


MythTV doesn't auto-start by default



This is easily solved in the nice Mythbuntu Myth-config tool accessible from the desktop menu. However, one annoyance is that it auto-starts Mythfrontend rather than Mythwelcome, so auto-shutdown will not work. I had to go into the normal settings GUI, in the Autostart Programs tab, and add Mythwelcome (and remove Mythfrontend) from the list of autostart programs. The Myth-config tool did correctly set it up to auto-login my user rather than give a login screen.


HDMI connection to my TV leads to overscan issues




My TV is a 42-inch Panasonic LCD, and my mythbox is connected through an HDMI port, using a DVI-to-HDMI converter I bought at Target. When using my mythbox, it quickly became apparent that the computer display was extending beyond the visible area of my screen, such that I was missing 10-20 pixels along each edge. After much research with the google, I learned that this problem is known as overscan. Basically, TVs routinely crop the displayed image this way. There is a general solution, but it is incredibly obscure: you have to craft a custom "modeline" for your xorg.conf file, which apparently involves understanding not only scan timings and pixel clocks, but also something called the front porch and back porch. This is one of those times that makes me go, "You know what? I don't care what the front porch is, I just want to see all of the pixels on my screen! Why does it havbe to be so difficult?". Then I found out about a tool called xvidtune, which allows you to modify the screen size and position and then spits out the corresponding modeline. Sweet, right? Unfortunately, when I tried to run it, I got an obscure error message (like, "Could not query monitor parameters"), and googling the error didn't yield any leads.


I was about to give up, and just accept that I wasn't going to see the edges of my screen, when I decided to do the unthinkable. I opened the User Manual for my TV. Amazingly, I found an obscure menu option in there called something like "HDMI scaling". Even more amazingly, activating this option did exactly what I was hoping for! The screen is reformatted such that I can now see all the way to each edge. And it isn't done with resampling that destroys image clarity. Sweet.

Update: MythTV Wakeup with kernel >= 2.6.22

In this post, I discussed how to get MythTV to automatically wakeup when it needed to record something, and shutdown when it had finished.


Since writing that post, I switched my setup from KnoppMyth to Mythbuntu, because my wireless keyboard/mouse combo didn't work under Knoppmyth. Anyway, it turns out that the auto-wakeup procedure is a bit different than I described if you are using a linux kernel version 2.6.22 or newer.


The basic differences are that the ACPI timestamp must be placed into /sys/class/rtc/rtc0/wakealarm, instead of /proc/acpi/alarm, and that the timestamp must be expressed in "UNIX time" (i.e., the number of seconds elapsed since 1970/01/01 00:00:00), rather than a "yyyy-MM-dd hh:mm" formatted string. Also, the wakealarm file must first be "flushed" to a value of zero prior to setting the wakeup time. For a detailed discussion of this, see the MythTV Wiki.


You can still follow my previous guide, with the following corrections:


  • In mythwelcome --setup, change Wakeup time format to time_t. Do not change the time format in mythtv-setup! I did that at first...seemed logical, does not work.
  • In mythwelcome --setup, change the Command to Set Wakeup Time to sudo /usr/local/bin/setwakeup.sh
  • Create the file sudo /usr/local/bin/setwakeup.sh. Make it look like this:


    #!/bin/sh
    # $1 is the time, in seconds since 1970/01/01 00:00:00.
    # (a.k.a. the "time_t" format)

    sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm" # clear the alarm
    sudo sh -c "echo $1 > /sys/class/rtc/rtc0/wakealarm" # write new alarm



That should do it. Don't forget to chmod +x /usr/local/bin/setwakeup.sh.

Saturday, January 31, 2009

How to add a Buffalo Linkstation Live to your network

This little beauty is one of those how-did-I-live-without-this gadgets. If you have the means, I highly suggest picking one up (and they aren't very expensive, I got a 500GB Linkstation Live for $160).


So, what is it? It's basically just a hard drive in an enclosure...BUT! The novelty is that it has an ethernet jack, and it's running a customized version of linux. Jack this badboy into your network, and you have an always-on storage solution that is accessible to all of your machines. Extra bonus: if you move your iTunes library onto this disk, it will automagically appear as a shared library on any computer running itunes on your network. Sweet. And for your non-itunes linux box, the same library appears as a hierarchical directory of mp3's so you're golden there too.

Making it work on OS X and iTunes


I set it up on my MacBook Pro first, and it was dead easy. Just use the installation CD that comes with the drive. It was a little unclear how the iTunes thing was going to work, but I just reset the library location in iTunes, then used the "Consolidate library" function to move all of my music to the Linkstation (this took several hours). This procedure is outlined by Apple here. After this completed, it "just worked".

Making it work on Linux


You will be shocked to learn that there's less "it just worked" in this description. However, it wasn't too bad. Basically, you need to mount the drive as a Samba share (which is odd, since samba is for mounting Windows disks, and the Linkstation is running Linux!). However! Samba is apparently no longer called "smbfs", it's now called "cifs". I don't know why, and I don't care enough to find out. Anyway, the relevant command (issued as root) is:


mkdir /mnt/netdisk (only need to do this once </obvious>)
mount -t cifs -o user=admin,password=your_password 192.168.1.127:/share /mnt/netdisk


(where "user" and "password" params should be replaced with the login info for your Linkstation, as set in the drive's installation program, and the IP address is set to the correct value as well...it's shown in the Linkstation config tool). Assuming that worked, the final step is to have it auto-mount by adding a line to your /etc/fstab:


192.168.1.127:/share /mnt/netdisk cifs credentials=/root/.creds,rw,uid=mythtv 0 0

and create the /root/.creds, make it look like:
username = admin
password = your_password


Again, this is the login information for your Linkstation. The "uid" param in the fstab line is the name of a user which will have read/write access to the disk.

Making it work on Windows


This is also quite easy. Open My Computer, then click on "My Network Places" on the left. Then click on "Add a network place" in the "Network Tasks" menu on the left. This opens the "Add Network Place Wizard", in which you will step through the following screens:






Wednesday, January 28, 2009

How to get MythTV-0.21 to wake up and shutdown automatically

MythTV is a Linux-based roll-your-own Tivo, and will probably be a major topic in this here blog.


I recently upgraded to version 0.21, and had a dickens of a time getting automatic wakeup/shutdown working. The problem is typical of linuxy things: there are many poorly described options, some of which seem to be redundant but interact in subtle and nefarious ways. Plus, while there is a huge amount of documentation online, a lot of it is contradictory or only applicable to specific (but often unstated) setups.


With that latter datum in mind: this is for Myth-0.21, and I am using ACPI for wakeup/shutdown, rather than NVRAM. Okay? Okay.


Step the First: Make sure acpi works on your machine



  • Find out what timezone your BIOS clock is using. There are ways to find out from within linux, but let's go straight down to the metal and ask the BIOS. So, reboot your box (bye-bye uptime!), and press Del or whatever to get into the BIOS. Check the clock time; hopefully it's either your local time or UTC. Make a note of it.
  • Boot into linux. If myth starts automatically, get out of it (keep pressing Esc until it asks if you're sure you want to exit...if that gets you the mythwelcome screen, press "M", then select Exit from the menu). At this point you should be in a desktop session of some kind.
  • Attempt a manual ACPI wakeup. I'm going to assume that your kernel has ACPI stuff set up already, so if this step fails you may need to do some kernel recompilin' (hooray!). Open a terminal. We want to send the BIOS a message to boot the machine in about five minutes from now, so query the current time by typing date, or date -u if your BIOS clock uses UTC. Then, we just need to write a time string set for five minutes from now into a particular file. For example, say that date -u returns "Wed Jan 28 12:35:42 2009". In that case, we would next type the following: echo "2009-01-28 12:41:00" > /proc/acpi/alarm. You should, of course modify the time string.


    Next, shutdown the machine. Quickly now, you only have 5 minutes! sudo shutdown -h now should do the trick. Wait five minutes. The machine should power on all by itself! Spooky! If it doesn't...like I said, you could be in for some serious tweaking. Google around for more detailed docu.



Step the Second: Configure MythTV


All right, we've verified that ACPI works and the system can auto-boot given a properly-formatted timestamp sent to /proc/acpi/alarm. Next, we will set up MythTV to enable auto wakeup/shutdown.


In an ideal world, the MythTV configuration for auto wakeup/shutdown would simply be a checkbox, tagged with the simple query "Would you like MythTV to automatically shutdown when idle and wakeup when it's time to record?". This is evidently not an ideal world, so prepare yourself for something rather more labyrinthine...


First of all, get out of MythTV if it's running. Just keep pressing "Esc" until it asks if you want to exit, then select "Yes"! If that gets you to mythwelcome, press "m", then select "Exit" from the menu. You should now be looking at a desktop session of some kind. Before we begin, kill the backend program by typing sudo /etc/init.d/mythtv-backend stop.


There are two screens full of options that you'll need to tweak. The first is in the backend config tool. Open an xterm (on KnoppMyth, you right-click the desktop, then select "XShells", "xterm". Since the default font is unreadable on a TV, I usually Ctrl-right-click on the xterm and select the "Huge" font). Now type mythtv-setup in the xterm to invoke the config tool. Select "General" from the menu, then skip to page 5 (press Enter 4 times). Make it look like this:




In particular:


  • Startup command: /usr/bin/mythwelcome
  • Block shutdown before client connected: checked
  • Wakeup time format: yyyy-MM-ddThh:mm:ss
  • Command to set Wakeup Time: sudo mythshutdown --setwakeup $time
  • Server halt command: sudo mythshutdown --shutdown
  • Pre Shutdown check-command: sudo mythshutdown --check

Set the time intervals to whatever you're comfortable with. I should probably change my "Max. wait for recording" to 30 minutes, because a 30-minute gap between recordings is relatively common. After you're done here, page through the rest of the config's many, many pages until you reach the Finish button (hooray!)


The next step is to run mythwelcome --setup. This tool is thankfully, only one page. Make it look like this:




That first line is truncated in the screenshot. In full, it reads:

sudo /usr/local/bin/convert_utc.sh $time; sleep 1; sudo /usr/local/bin/convert_utc.sh $time

This is an ugly belt-and-suspenders redundancy just to make sure that the convert_utc.sh script does its thing before the shutdown process begins. It would probably be more elegant to add the sleep 1 command to the script itself. (Note to self: do that!)


The other parameters are pretty straightforward. The "Command to shutdown" parameter is a useful place for some kung-fu if you need to diagnose shutdown problems. Just replace that command with killall mythwelcome and instead of shutting down, you'll simply get booted back to your desktop where you can check logs or console output (assuming you had started mythwelcome from an xterm). Pretty useful!


Step the Third: write convert_utc.sh


The convert_utc.sh script just takes the wakeup time string sent from MythTV (in Local time format), converts it to UTC, reformats it, and writes it to /proc/acpi/alarm. Here is my convert_utc.sh:




#!/bin/bash
stamp_file=/tmp/timestamp
#echo $1\ $2 > $stamp_file
echo $1 | sed "s/T/ /" > $stamp_file
# Add TZ info to the timestamp
datum=$(/bin/date -f $stamp_file +%F\ %T\ %z)
echo $datum > $stamp_file
#Express as UTC time
utcdatum=$(/bin/date -u -f $stamp_file +%F\ %T)

#uncomment for testing
#echo $utcdatum > $stamp_file

#uncomment to commit to /proc/acpi/alarm:
rm -f $stamp_file
echo $utcdatum > /proc/acpi/alarm
echo $utcdatum




Step the Fourth: Test Drive


Restart the backend (in an xterm or virtual terminal, type: sudo /etc/init.d/mythtv-backend restart). Next, type mythwelcome to start MythTV. Navigate to "Manage Recordings", "Schedule Recordings", "Program Guide", and pick something to record that's going to start relatively soon (but not too soon: if it starts within the "Max wait for recording" time interval, then MythTV will refuse to shutdown...for this reason, it's a good idea to keep Max-wait short while debuigging things). After clicking on the desired program, you get an extensive menu of recording/storage options. Set the program to record, then be sure to select "Save these settings". You should see an icon in the Program guide indicating that MythTV will record that program. Then exit MythTV (keep pressing Esc until you see the "Are you sure you want to exit???" question).


You should now see the mythwelcome screen, with status messages telling you that the system is currently idle, and that your selected program is the next thing to be recorded. You should see the idle timer counting down to trigger the ssytem shutdown. You can either let the timer run down, or press "m" to get a menu and select "shutdown now" from the menu. Hopefully, in either case your system will then shut itself off.


Now comes the real nail-biter. Will your system wake itself up to record the selected program? The wakeup time is controlled by the "startup before rec" option in mythtv-setup. So if that was set to 600 sec, then 10 minutes prior to the recording time, your computer should boot itself. Go grab yourself a sandwich, read a book, take a walk, ponder your existence, whatever. At the appointed time, you will hopefully hear the beeps and whirrs of your system waking up!


Step the Fifth: What if it doesn't work?


TBCompleted...

Tuesday, January 27, 2009

How to use iSync with a Motorola RIZR Z3

This is based on a fairly old tutorial I wrote in Aug 2007...however, that page is from my old job and could disappear at any moment.


Before you begin, you should quit out of iSync if you have it open (thanks for the tip, Levi!)


The driver can be downloaded from this page
(direct link to the driver). OS X wil automatically unzip the file, giving you a folder named MOTZ3.phoneplugin. Place this file in your /Library/PhonePlugins directory. Note: this is the root Library directory, not the one under your personal directory. Also, I had to create the PhonePlugins directory on my machine. YMMV.


Now, open System Preferences and go to the Bluetooth page. Select the Devices tab. If you've already attempted to pair wih your RIZR, delete its entry from the list (I'm not sure this is necessary, but it doesn't hurt).


Next, we need to activate the RIZR's bluetooth. Open the Main Menu, and select Settings, then Bluetooth Link. Select the [Find Me] entry. This will make your phone "discoverable" for three minutes.


Back on the mac, click the Set Up New Device... button in the SysPref | Bluetooth | Devices page. This launches the Bluetooth Setup Assistant:


  • Click Continue on the Intrduction page
  • Select Mobile phone from the list, click Continue
  • Select your Motorola Z3 from the list of detected phones, click Continue
  • Wait for it to "gather additional information", click Continue
  • Enter the numeric code that appears into your phone
  • Make sure Set up iSync to transfer contacts and events is checked. If this checkbox does NOT appear, then the Z3 plugin was not detected. Make sure you followed the plugin installation instructions.



Now launch iSync. If you don't have a Motorola Z3 button in the toolbar, select Add Device... from the Devices menu, and choose your Z3 from the list. Now you should be able to select the Z3 from the toolbar, and click on the Sync Devices button to sync your contacts and calendar events.


A Caveat



The sync will not copy your contact images over to the RIZR. Or at least, it didn't do so for me. This is a bit disappointing, and I can only hope that Apple's Z3 plugin will work better, assuming they eventually get around to publishing one.

Sunday, January 25, 2009

Manifesto

In which I document my efforts, failures and successes in trying to make my technology work.

These accounts will tend to document small, focused tasks (like "manually inserting videos into a mythtv database"), not huge projects (like "installing and using mythtv").