Categories
Linux

grub-probe: error: not a directory. (grub 1.99 in Ubuntu Linux 12.04)

I upgraded some packages earlier (including a kernel) and received an odd error from grub (version 1.99-21ubuntu3.9)

$ sudo grub-install --recheck /dev/sda
 /usr/sbin/grub-probe: error: not a directory.
 Auto-detection of a filesystem of /dev/sdb1 failed.
 Try with --recheck.
 If the problem persists please report this together with the output of "/usr/sbin/grub-probe --device-map="/boot/grub/device.map" --target=fs -v /boot/grub" to <bug-grub@gnu.org>

I couldn't complete the configuration of the updates that I had downloaded, and worse the machine was probably now unbootable. Poking around a bit, I find that the error reported by grub-probe could be reproduced with:

$ sudo grub-probe -d /dev/sdb1 --target=fs_uuid
grub-probe: error: not a directory.

I didn't know where to go from here so the first thing I tried was to purge grub and reinstall it.

sudo apt-get purge grub*

sudo apt-get install grub-pc

Didn't make any difference, so the next thing I tried was to downgrade to an earlier version of grub (1.99-21ubuntu3).

sudo apt-get purge grub*

sudo apt-get install grub-pc=1.99-21ubuntu3 grub2-common=1.99-21ubuntu3 grub-pc-bin=1.99-21ubuntu3 grub-common=1.99-21ubuntu3

Unfortunately this made no difference either. So the next thing I tried was to install the version of grub from Ubuntu 12.10. There were some dependency conflicts which I had to manually fix as you can see here:

sudo apt-get remove apport-hooks-medibuntu apport-gtk apport

sudo dpkg -i liblzma5_5.1.1alpha+20120614-1_amd64.deb grub2-common_2.00-7ubuntu11_amd64.deb  grub-common_2.00-7ubuntu11_amd64.deb  grub-gfxpayload-lists_0.6_amd64.deb  grub-pc_2.00-7ubuntu11_amd64.deb  grub-pc-bin_2.00-7ubuntu11_amd64.deb

Finally, grub installed ok! Crisis averted.

Categories
Linux

Strip audio from a video in Ubuntu Linux

Lets say you have a video you recorded on your mobile phone, and you want to send it to someone but there is a noisy audio track which is irrelevant to the subject. Stripping out the audio track is fairly simple using the libav-tools package.

sudo apt-get install libav-tools

avconv -i INPUT.3gp -an -c:v copy OUTPUT.3gp

"-i INPUT.3gp" specifies the input file

"-an" specifies that there will be no audio track in the output file (or -vn would have no video track). Note that if "-an" appeared before "-i INPUT.3gp" we would copy no audio track from the input file (but there would still be an audio track in the output file, albeit empty possibly).

"-c:v copy" specifies the codec we use to encode the video track in the output file. Here we specify copy which means we don't transcode it. So rather than rendering the input video track to a buffer, then re-encoding it we are just copying it directly from the input file to the output file which means we don't lose any quality (whereas if we re-encoded it with a lossy codec then we would have a lower quality output file). Note that if we specified "-c:v <CODEC>" before the "-i INPUT.3gp" we would be specifying the codec used to decode the input file, rather than encode the output file.

"OUTPUT.3gp" specifies the output file. Obviously.

Categories
Linux

ZoneMinder: Bareword "ZM_PATH_LOGS" not allowed while "strict subs" in use

Since a recent burglary I have been using ZoneMinder to provide CCTV security for my house on my Ubuntu 12.04 machine. I noticed earlier today that zoneminder had stopped running over the weekend and when I tried to start the service again, I got the following error:

Starting ZoneMinder: Bareword "ZM_PATH_LOGS" not allowed while "strict subs" in use at /usr/share/perl5/ZoneMinder/Logger.pm line 153.
BEGIN not safe after errors--compilation aborted at /usr/share/perl5/ZoneMinder/Logger.pm line 168.
Compilation failed in require at /usr/share/perl5/ZoneMinder.pm line 34.
BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder.pm line 34.
Compilation failed in require at /usr/bin/zmpkg.pl line 37.
BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 37.
failure

Looking through the ZoneMinder code I discovered that the error indicated that a configuration variable somehow wasn't set. My first thought was that perhaps a new configuration variable had been added in an upgrade but hadn't been automatically added to the configuration file. So I added a line containing ZM_PATH_LOGS to /etc/zm/zm.conf but now when I tried to start zoneminder, I received a similar (but different error):

Starting ZoneMinder: Bareword "ZM_USE_DEEP_STORAGE" not allowed while "strict subs" in use at /usr/share/perl5/ZoneMinder/General.pm line 207.
BEGIN not safe after errors--compilation aborted at /usr/share/perl5/ZoneMinder/General.pm line 226.
Compilation failed in require at /usr/share/perl5/ZoneMinder.pm line 35.
BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder.pm line 35.
Compilation failed in require at /usr/bin/zmpkg.pl line 37.
BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 37.
failure

I added a line for this then another similar (but different) error appeared! Clearly this approach isn't correct. So I logged into mysql and had a poke around:

mysql -u XXX -p
mysql> show databases;
mysql> use zm;
mysql> show tables;
+----------------+
| Tables_in_zm   |
+----------------+
| Config         |
| ControlPresets |
| Controls       |
| Devices        |
| Events         |
| Filters        |
| Frames         |
| Groups         |
| Logs           |
| MonitorPresets |
| Monitors       |
| States         |
| Stats          |
| TriggersX10    |
| Users          |
| ZonePresets    |
| Zones          |
+----------------+
17 rows in set (0.00 sec)

mysql> select * from Config;

0 rows in set (0.00 sec)

Like in iPhone adverts, the above sequence is shortened. But the surprising result appears at the end: there are no lines in the Config table! This must be the culprit preventing ZoneMinder from starting.

Its not clear how this config table has been reset, as I don't recall updating the ZoneMinder packages recently, so I don't think its a botched database upgrade. I have restarted the machine that it runs on a couple of times over the weekend so perhaps the database got corrupted at shutdown, though I can't find any mysql logs complaining about this. In conclusion, I don't know how it happened! But if it happens again all the info is here.

To resolve this, I download the ubuntu package for zoneminder and had a look in the postinst install script to see how it initialised the database. It turns out there is an sql file at /usr/share/zoneminder/db/zm_create.sql which is applied at package installation. I edited this file and removed all lines that didn't affect the Config table and applied it manually.

Finally zoneminder started up (albeit without my configurations)! After reconfiguring zoneminder, I noticed in ZoneMinder's log database the following entry:

Config mismatch, expected 218 items, read 0. Try running 'zmupdate.pl -f' to reload config.

If this happens again, perhaps 'zmupdate.pl -f' is sufficient to fix it, instead of error-prone sql hacking. (update: according to commenters this does not work!)

And the moral of the story is: always backup your databases!

Categories
Internet Linux

BT Infinity and OpenWRT

So my girlfriend can't get reliable wifi upstairs on her iphone, maybe the bed's metal frame is acting as a faraday cage, maybe the BT HomeHub 3 router is not very good.

Regardless of who's to blame for the wifi issues, the HomeHub's interface doesn't let you change DNS servers - ostensibly for security reasons but as likely to be related to BT's commercial decision to redirect failed DNS queries to advertising web pages. This is hugely frustrating when you are trying to find out if a host is up by pinging it, and the ping succeeds while the host is down, because you mistyped the hostname and were redirected to BT's "spoof" response.

Anoyingly, if the broadband connection goes down, the router starts redirecting all web requests to itself at the address bthomehub.home which causes certificate errors in applications like thunderbird - generally a pain in the arse.

So its clearly time to ditch the HomeHub 3 and get a proper router. Given the ddwrt GPL violations, OpenWRT is the obvious choice of OS.

Although OpenWRT can be put on a HomeHub 3, the current procedure involves a soldering iron. Therefore I bought myself a TP-Link WR1043ND which is supported by OpenWRT and has a gigabit switch - not bad for £50. Upgrading the firmware was a doddle, simply a matter of downloading the latest firmware for my device (http://downloads.openwrt.org/backfire/10.03.1/ar71xx/openwrt-ar71xx-tl-wr1043nd-v1-squashfs-factory.bin at time of writing) and using the router's built in firmware upgrade page! Very smooth.

Its all fairly straightforward to configure via the web interface (and in fact it comes with a pretty much decent configuration out of the box). I connected the bt infinity modem via the WAN port, and set up the PPPoE connection using the password from my homehub 3 router (bthomehub@btbroadband.com). There is no password listed in the homehub 3 configuration pages but it turns out I had to set up a password of "BT" before the connection succeeded. This was the only non-obvious thing I had to do to get everything working.

Categories
Linux

Secure MythWeb with Mythbuntu 12.04

When you install the MythWeb module, the default security settings in Mythbuntu allow password-less access from anywhere. If you wish to be able to schedule (or watch) recordings when you are away from home then you may want to allow users on your local network to access the screens without a password, while requiring a password for connections from outside your network.

Tell Apache to require authentication for MythWeb

Open /etc/apache2/sites-enabled/mythweb.conf (remembering to gain root access) and find the commented out section that looks like this:

    ############################################################################
    # I *strongly* urge you to turn on authentication for MythWeb.  It is disabled
    # by default because it requires you to set up your own password file.  Please
    # see the man page for htdigest and then configure the following four directives
    # to suit your authentication needs.
    #
    #    AuthType           Digest
    #    AuthName           "MythTV"
    #    AuthUserFile       /var/www/htdigest
    #    Require            valid-user
    #    BrowserMatch       "MSIE"      AuthDigestEnableQueryStringHack=On
    #    Order              allow,deny

I am not convinced /var/www is a safe place to keep your htdigest file, so I changed that line to store it in /etc/mythtv/htdigest. I added an "Allow from 192.168.0." line to allow users with an ip address starting 192.168.0 to connect without a password, then a "Satisfy any" line to state that the page can only be served to an authenticated valid-user (from the Require line), or on the local network (from the Allow from line). This is what my final section looked like.

        AuthType           Digest
        AuthName           "MythTV"
    #    AuthUserFile       /var/www/htdigest
        AuthUserFile       /etc/mythtv/htdigest
        Require            valid-user
        BrowserMatch       "MSIE"      AuthDigestEnableQueryStringHack=On
        Order              allow,deny
        Allow from 192.168.0.
        Satisfy            any

Enable the Apache module which implements the Digest authentication method

You now must enable apache's auth_digest module using the a2enmod command.

sudo a2enmod auth_digest

If you forget to do this you will see errors like this in your apache error log when you attempt to connect from a non-local address:

[Mon Jul 09 23:27:21 2012] [crit] [client 69.163.149.163] configuration error:  couldn't check user.  Check your authn provider!: /mythweb

Choose a username and password for remote access

Assuming you used the same values for AuthUserFile and AuthName as I did) then you can add the first user to the password file:

sudo htdigest -c /etc/mythtv/htdigest MythTV username_to_add

The -c parameter creates a blank file so don't use it for any additional users you add. If you don't have htdigest installed, you may need to install the apache2-utils package (sudo apt-get install apache2-utils).

Ensure that only the apache server can read the password file:

sudo chown www-data /etc/mythtv/htdigest
sudo chmod 640 /etc/mythtv/htdigest

Tell Apache about the configuration changes

sudo service apache2 reload

It should now be safe to expose MythWeb to the outside world!

 

Categories
Linux

Shuttle XS35GS V3 and Mythbuntu 12.04

I bought the recently released Shuttle XS35GS V3 (also called XS35GTA V3) to use as a mythtv frontend. As usual, nothing works correctly first time round and there were a few things I needed to set up manually to get it working correctly.

1) I had problems with the onboard wifi - it would apparently connect then as soon as you tried to use the connection various errors messages would appear in the debug log.
Jul  5 10:37:18 bedroom kernel: [  157.712828] rtl8192c_common:rtl92c_firmware_selfreset(): 8051 reset fail.
Jul  5 10:37:23 bedroom kernel: [  162.696823] rtl8192ce:_rtl92ce_llt_write():<0-0> Failed to polling write LLT done at address 0!
Jul  5 10:37:23 bedroom kernel: [  162.696833] rtl8192ce:rtl92ce_hw_init():<0-0> Init MAC failed

So I disabled the wifi in the bios and used a USB wifi stick for the time being. I may end up installing a cable if wifi does not give adequate streaming performance for mythtv.

2) I connected the shuttle via HDMI cable to the TV, unfortunately no sound was transmitted initially. The shuttle model I chose has an ATI chipset, so I first tried installing ATI binary drivers:
sudo apt-get install fglrx-updates
After that I listed the drivers and played test sounds on each device with VLC until I found which one worked.
frankster@bedroom:~$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: STAC92xx Analog [STAC92xx Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0

VLC confirmed that the final device "HD-Audio Generic" is the correct one so the next step is to apply that setting inside mythtv. Unforunately the list inside mythtv is different to what I saw in the output of "aplay -l", but I worked out that mythtv describes it thus:
hdmi:CARD=Generic,DEV=0

3) Using the latest version of fglrx-updates (2:8.960-0ubuntu1.1) I found that switching the TV (connected via HDMI) off then on again caused the sound to stop working, requiring a system reboot. I downloaded the drivers from the ATI website and the issue was solved. The latest version at the time I downloaded was catalyst 12.6, which generated packages with a version of 8.980 (in contrast to the Ubuntu packages which are version 8.960).

4) The bios version that came with my device (1.00) had two problems. When requesting a restart, the machine would instead shutdown. Secondly the Ubuntu 64-bit installer didn't believe that 64-bit could be installed so I had to install 32-bit. (I'm about 90% certain that you should be able to install 64-bit on the Atom D2700).

I installed the latest bios driver (1.05) and this resolved the reboot issue. I have not attempted to reinstall since, so I don't know about the 64-bit installer issue.

Updated 19th August 2012

Categories
Linux

Kworld PC160-2T remote control on Ubuntu Linux 11.10

I recently bought a dual tuner card for my Mythtv box (and I discussed getting it working with mythtv here). The good news is that the IR receiver on the card is detected by the driver, however the bad news is that the remote does not work out of the box with Ubuntu 11.10 because Ubuntu doesn't have a keymap for it. You can see in the dmesg output that it loads the default rc-empty keymap:

[ 31.058541] Registered IR keymap rc-empty
[ 31.058604] input: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:1e.0/0000:05:01.2/usb3/3-1/rc/rc0/input4
[ 31.058713] rc0: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:1e.0/0000:05:01.2/usb3/3-1/rc/rc0
[ 31.058716] dvb-usb: schedule remote query interval to 500 msecs.

So I sorted it out by creating my own keymap - its still a bit of a work in progress as I have no idea what functions some of the pictures on the buttons represent! To create the keymap, I used the programme evtest to capture the scancodes generated by the remote. I then added the scancode to a file and mapped it to a sensible looking event which I chose from this list (see also this one). I saved my keymap in the /etc/rc_keymaps directory and inserted it (I first closed mythtv and switched out of X to a terminal with ctrl-alt-F2 to ensure that no application had the event device open).

frankster@mythtv:/etc/rc_keymaps$ sudo ir-keytable -c -p NEC -w kworld_pc160-2t
Read kworld_pc160-2t table
Old keytable cleared
Wrote 30 keycode(s) to driver
Protocols changed to NEC

I then verified my keymap was working with ir-keytable. Now we receive as well as the scancode, a key up and down event every time a button is pressed.

frankster@mythtv:/etc/rc_keymaps$ sudo ir-keytable -t
Testing events. Please, press CTRL-C to abort.
1329667198.608627: event MSC: scancode = 866b00
1329667198.608631: event key down: KEY_NUMERIC_1 (0x0201)
1329667198.608632: event sync
1329667198.859974: event key up: KEY_NUMERIC_1 (0x0201)
1329667198.859975: event sync

Its all very well being able to manually install the keymap, but we need to make this a bit more permanent. I am currently preparing a kernel patch so that this remote control can be handled automatically, but for now we can achieve the same effect in userspace. I added to /etc/rc_maps.cfg the following line:

af9015 * /etc/rc_keymaps/kworld_pc160-2t

ir-keytable could then load the appropriate keytable.

sudo ir-keytable -a /etc/rc_maps.cfg 

This is the keymap I am currently using, I expect I will do some more tweaking as time goes on.

# table kworld_pc160-2t, type: NEC

0x866b1d KEY_POWER
#0x866b0x kworld log button - not sure what this does
#0x866b16 button between kworld button and power button

0x866b0a KEY_NUMERIC_0
0x866b00 KEY_NUMERIC_1
0x866b01 KEY_NUMERIC_2
0x866b02 KEY_NUMERIC_3
0x866b03 KEY_NUMERIC_4
0x866b04 KEY_NUMERIC_5
0x866b05 KEY_NUMERIC_6
0x866b06 KEY_NUMERIC_7
0x866b07 KEY_NUMERIC_8
0x866b08 KEY_NUMERIC_9

#0x866b09 some kind of reload symbol
0x866b14 KEY_MUTE

#0x866b1e small rectangle and big rectangle
#0x866b17 fullscreen?
0x866b1f KEY_HOME
0x866b0e KEY_BACK

0x866b20 KEY_UP
0x866b21 KEY_DOWN
0x866b42 KEY_LEFT
0x866b43 KEY_RIGHT
0x866b0b KEY_ENTER

0x866b10 KEY_CHANNELUP
0x866b11 KEY_CHANNELDOWN
0x866b12 KEY_VOLUMEDOWN
0x866b13 KEY_VOLUMEUP

#0x866b19 scheduled recording?
0x866b1b KEY_RECORD
0x866b4b KEY_EPG

0x866b1a KEY_STOP
0x866b44 KEY_PLAYPAUSE
0x866b40 KEY_BACK
0x866b41 KEY_FORWARD

#0x866b22 Tx button

#0x866b15 looks like some kind of transmit or infrared symbol
#0x866b0f widescreen?
#0x866b1c screenshot?
0x866b4a KEY_SLEEP
Categories
Linux

Using the KWorld PC160-2T with Mythtv on Ubuntu Linux 11.10

The PCI card is internally implemented as a USB interface connected to the two tuners over USB which is interesting to say the least. Presumably its cheaper to put an extra USB chip on a PCI card than to make a new design specifically for PCI.

The first problem I had was that there was no firmware. I spotted this in the output from dmesg:

[ 13.980942] dvb-usb: found a 'KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T)' in cold state, will try to load a firmware
[ 15.147767] dvb-usb: did not find the firmware file. (dvb-usb-af9015.fw) Please see linux/Documentation/dvb/ for more details on firmware-problems. (-2)
[ 15.147781] dvb_usb_af9015: probe of 3-1:1.0 failed with error -2

Although the documentation describes a method to obtain the firmware by running a script, it turns out that Ubuntu already has the firmware packaged. So I just needed to install linux-firmware-nonfree.

sudo apt-get install linux-firmware-nonfree

Then I needed reinsert the modules so that the firmware could get downloaded:

sudo rmmod dvb_usb_af9015
sudo rmmod dvb-usb
modprobe
modprobe dvb-usb
sudo modprobe dvb-usb
sudo modprobe dvb_usb_af9015

Next time I ran dmesg, there were some much more promising lines:

[   29.822162] dvb-usb: found a 'KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T)' in cold state, will try to load a firmware
[   29.967469] dvb-usb: downloading firmware from file 'dvb-usb-af9015.fw'
[   30.037577] dvb-usb: found a 'KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T)' in warm state.
[   30.037783] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
[   30.038103] DVB: registering new adapter (KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T))
[   30.042065] af9013: firmware version:4.95.0.0
[   30.046814] DVB: registering adapter 0 frontend 0 (Afatech AF9013 DVB-T)...
[   30.048791] tda18271 0-00c0: creating new instance
[   30.054815] TDA18271HD/C2 detected @ 0-00c0
[   30.324093] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
[   30.324505] DVB: registering new adapter (KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T))
[   30.596052] ADDRCONF(NETDEV_UP): wlan0: link is not ready
[   31.040928] af9013: found a 'Afatech AF9013 DVB-T' in warm state.
[   31.044418] af9013: firmware version:4.95.0.0
[   31.058424] DVB: registering adapter 1 frontend 0 (Afatech AF9013 DVB-T)...
[   31.058533] tda18271 0-00c0: attaching existing instance
[   31.058541] Registered IR keymap rc-empty
[   31.058604] input: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:1e.0/0000:05:01.2/usb3/3-1/rc/rc0/input4
[   31.058713] rc0: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:1e.0/0000:05:01.2/usb3/3-1/rc/rc0
[   31.058716] dvb-usb: schedule remote query interval to 500 msecs.
[   31.058720] dvb-usb: KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T) successfully initialized and connected.
[   31.076254] usbcore: registered new interface driver dvb_usb_af9015

I found http://parker1.co.uk/mythtv_dvb.php to have some useful information - it shows a method of verifying that the card is working by taking mythtv out of the equation.

Now that I knew that the card was working, I configured it in mythtv. As there are two tuners I configured both in mythtv, making sure to increase the setting allowing multiple streams to be recorded from the same multiplex. (This is due to the way dvb-t/freeview works - several stations are transmitted on the same channel). My biggest worry when I ordered the card was that it would not have this funtionality and that I would never be able to watch or record more than 2 channels simultaneously, but the following line in the output of dmesg reassured me:

[   30.324093] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.

I was able to watch some TV on mythtv and caught the end of Gypsy Wedding...probably the only reality TV show that I can tolerate! I then set up some recordings to take place over the next few days unfortunately none of these worked. It turns out that there is currently a bug in the 3.0 and 3.2 kernels' drivers that handles the chip - the driver doesn't like switching between the two tuners. A symptom of the bug is i2c read errors such as this:

[   38.379309] af9013: I2C read failed reg:d417

This bug causes both tuners to eventually stop working. I worked around this by disabling the second tuner in mythtv, and mythtv has been stable since. I will solve this later, but for now I need to get the remote working!

Categories
Linux

undefined reference to `ceil' (or pow or floor or ...) in ubuntu 11.10

There has been a change to the build tools in ubuntu 11.10 - The "--as-needed" flag is now passed to the linker. This primarily has implications for dynamic library linking but it also affects the order that libraries appear on the command line even for static linking.

A simple example of the problem:

frankster@frankie-laptop:~> cat testm.c
#include <math.h>

int main(int argc, char*argv[]){
double x;
double return_val = ceil(x);
return 0;
}
frankster@frankie-laptop:~> gcc -lm testm.c
/tmp/ccNkQLo6.o: In function `main':
testm.c:(.text+0x15): undefined reference to `ceil'
collect2: ld returned 1 exit status>

A quick fix solution could be to pass the "-Wl,--no-as-needed" option to gcc which turns off the option in ld. However the real problem in the example I provided is the order of -lm and testm.c. The following builds successfully:

gcc testm.c -lm

More info at http://www.gentoo.org/proj/en/qa/asneeded.xml and https://wiki.ubuntu.com/OneiricOcelot/ReleaseNotes?action=show&redirect=OneiricOcelot%2FTechnicalOverview#GCC_4.6_Toolchain

Categories
Linux

Running a python script that requires libgsf on Ubuntu 11.04

I was exploring a project concerned with reverse engineering some file formats (https://gitorious.org/re-lab/tools) and I needed to run a python script. This python script requires libgsf (the gnome structured file library: http://projects.gnome.org/libgsf/ ), however the debian/ubuntu packages for this aren't built with python support!

This led to errors such as:

frankster@linux-virtualbox:~/relab/tools/oletoy$ ./view.py
Traceback (most recent call last):
  File "./view.py", line 23, in <module>
    import Doc, cmd
  File "/home/frankster/relab/tools/oletoy/Doc.py", line 19, in <module>
    import ole,mf,svm,cdr,clp,rx2
  File "/home/frankster/relab/tools/oletoy/ole.py", line 23, in <module>
    import vsd, xls, ppt, vba, doc
  File "/home/frankster/relab/tools/oletoy/vsd.py", line 19, in <module>
    import gtk,gsf
ImportError: No module named gsf

Getting libgsf compiled was a bit of a pain so here are some tips that may be helpful. I initially attempted to modify the ubuntu package and simply enable the configuration switch for python support. However there are some problems with the paths for python includes in the debian build scripts that I didn't get to the bottom of. So instead of building a custom ubuntu package, I uninstalled the official libraries and built my own version. I was still able to use the debian package build infrastructure to automatically fetch the source code and the build-dependencies which made things a little easier!

sudo apt-get source libgsf
sudo apt-get install python-dev
sudo apt-get build-dep libgsf
cd libgsf-1.14.21
./configure --with-python
make
sudo make install

Check that you had all required python development libraries installed during the configure stage by looking for the following lines towards the end:

checking for python... /usr/bin/python
checking for python version... 2.7
checking for python platform... linux2
checking for python script directory... ${prefix}/lib/python2.7/dist-packages
checking for python extension module directory... ${exec_prefix}/lib/python2.7/dist-packages
checking for headers required to compile python extensions... found
checking for PYGTK... yes
checking for pygtk-codegen-2.0... /usr/bin/pygtk-codegen-2.0
yes

If you only saw some of these lines, then the python component won't get built!

Once you have got this far, your python script should now detect the gsf module. As your manual install of libgsf will have gone into the /usr/local/ tree, your python script may not be able to locate the library it needs to link to. If this happens you will see an error like the following:

Traceback (most recent call last):
  File "./view.py", line 23, in <module>
    import Doc, cmd
  File "/home/frankster/relab/tools/oletoy/Doc.py", line 19, in <module>
    import ole,mf,svm,cdr,clp,rx2
  File "/home/frankster/relab/tools/oletoy/ole.py", line 23, in <module>
    import vsd, xls, ppt, vba, doc
  File "/home/frankster/relab/tools/oletoy/vsd.py", line 19, in <module>
    import gtk,gsf
  File "/usr/local/lib/python2.7/dist-packages/gsf/__init__.py", line 8, in <module>
    from _gsf import *
ImportError: libgsf-1.so.114: cannot open shared object file: No such file or directory

If this happens you can solve it by telling the linker where it needs to look to find the library:

$ LD_LIBRARY_PATH=/usr/local/lib ./view.py

You can of course make this permanent in your .profile or .bashrc or whatever.

Categories
Linux

Increasing the size of the main linux partition (Ubuntu 11.04)

I have an installation of Ubuntu 11.04 running as a virtual machine under VirtualBox. It recently ran out of space, so I needed to expand the partition.

First I made a new partition that was larger than my existing partition (i.e. I created a new disc image in VirtualBox).

I then added the Ubuntu 11.04 DVD image to my VM as a new DVD device. I also needed to remove the VBoxGuestAdditions.iso, as it turns out that the VirtualBox bios only lets you boot off the first CD/DVD it finds.

That done, I fired up my VM and pressed F12 to get into the boot device menu, then chose to boot from CD. When this booted up I chose the option to run the live cd rather than install Ubuntu.

Once I hit the gnome2 desktop, I fired up a terminal and ran

$ sudo gparted

gparted showed two discs - sda and sdb. sda1 was my linux partition, and there was an extended partition containing a swap partition on sda5. sdb was empty as expected. I performed the following actions:

  • select and copy the sda1 partition.
  • switch to sdb and create a partition table.
  • paste the sda1 partition into sdb, and change its size so it fills the entire disc minus 500MB or whatever you want for the swap partition.
  • create an extended partition on sdb
  • create a new swap partition inside the extended partition.
  • I set the partition flag bootable on sdb1 although I don't think this was necessary.

Having done this I now needed to install grub. To get grub to work, I had to chroot into the new partition before installing it.

$ sudo mkdir /mnt/sdb1
$ sudo mount /dev/sdb1 /mnt/sdb1 -t ext2
$ sudo mount --bind /dev /mnt/sdb1/dev
$ sudo mount --bind /proc /mnt/sdb1/proc
$ sudo mount --bind /sys /mnt/sdb1/sys
$ sudo chroot /mnt/sdb1
$ sudo grub-install
$ sudo update-grub

At this stage I shutdown, and removed the old linux partition from my VM. When I started up again, it succesfully booted into my VM, from where I am writing this article!

Categories
Linux

Broken onboard wifi on a Lenovo G530 (4446) and Ubuntu 11.04

I have a Lenovo laptop which has for a while had problems with the onboard wireless card, so I have been using a usb wireless device instead. I don't use wifi very often as I mostly have it connected to an ethernet cable, so although a bit annoying its not too much hardship having to use the usb device.

I recently put Ubuntu 11.04 on the laptop because the performance I was getting from Windows XP was deteriorating rapidly. I don't like the new Unity interface, chiefly because it forces you to have the panel on the left hand side, which is fine unless you use two monitors and you want your default monitor on the right, then you get the panel in the middle of your two screens instead of on one side. Unfortunately Mark Shuttleworth has insisted that It Must Be This Way so I can't see it changing any time soon, thus I'm sticking with the traditional Gnome2 interface.

Anyway, for whatever reason the network manager applet gets confused by the two network adaptors I have, and won't let me connect to a network on the usb adaptor, stating that its disabled in hardware. This is incorrect, its only the onboard network adaptor that has its wifi switch disabled (and in fact changing the switch doesn't make any difference to whether or not network manager thinks its disabled or not).

Running "rfkill list" confirms that the onboard adaptor is disabled in hardware, but the usb adaptor is not. The solution I found was to blacklist the modules used by the onboard adaptor. So I ran:

$ sudo vim /etc/modprobe.d/blacklist.conf

and I added the following lines:

blacklist iwlcore
blacklist iwlagn

I was finally able to connect to wifi using the usb adaptor after also running:

$ sudo rmmod iwlcore iwlagn
Categories
Linux

ubuntu 10.10 upgrade nvidia driver stops working

I recently updated a machine from ubuntu 10.04 to ubuntu 10.10. After reboot the nvidia driver wouldn't load and /var/log/Xorg.0.log contains:

[    25.820] (EE) NVIDIA: Failed to load the NVIDIA kernel module. Please check your
[    25.820] (EE) NVIDIA:     system's kernel log for additional error messages.
[    25.820] (II) UnloadModule: "nvidia"
[    25.820] (II) Unloading /usr/lib/xorg/extra-modules/nvidia_drv.so
[    25.820] (EE) Failed to load module "nvidia" (module-specific error, 0)
[    25.820] (EE) No drivers available.
The solution was to run
$ sudo dpkg-reconfigure nvidia-current
which caused nvidia modules to be rebuilt. This showed me I was missing source for the running kernel version, so I then installed nvidia-185-kernel-source which was enough to get it back on its feet.