Procrastiblog

April 5, 2010

QEMU on Ubuntu

Filed under: Linux, Tech — Chris @ 9:22 pm

It was a lot easier to set up QEMU than I expected it would be. Easier even than the online tutorials make it seem.

  1. apt-get install qemu-kvm qemu-kvm-extras
  2. Download a prebuild image for the guest system you want to run. In my case, I wanted armel, which meant I also had to download initrd and vmlinuz images.
  3. If you want to copy files from the host system (i.e., your computer) into the guest, you need to make a “raw” image that you can mount from both sides:
    $ qemu-img create data.img <SIZE>
    Formatting 'data.img', fmt=raw size=...
    
    $ mke3fs -j data.img
    mke2fs 1.41.9 (22-Aug-2009)
    data.img is not a block special device.
    Proceed anyway? (y,n) y
    ...
    
    $ sudo mount -o rw,loop data.img <MOUNT_POINT>
    

    <SIZE> is a size in kilobytes, or use suffixes M and G for megabytes/gigabytes. The image only has to be big enough to temporarily hold the data you want to copy; you can move it to the guest’s root filesystem before you start working with it.

    <MOUNT_POINT> is any existing empty directory where you want to mount the image. I just made a directory foo in the same directory as the image.

    You should copy over any data now, because apparently it would be VERY BAD to do that while QEMU is running.

  4. Now it’s time to start the sucker. An example command line will be given in the README for the image you downloaded. I use:
    qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.26-1-versatile \
        -initrd initrd.img-2.6.26-1-versatile -hda debian_lenny_armel_small.qcow2 \
        -hdb data.img -append "root=/dev/sda1"
    

    Notice the -hdb data.img argument. That sets up the data image we set up in the last step as a disk drive in the guest system. You can probably login as user with password user. The root password is probably root.

  5. Once you’re logged in, make a directory to use as a mount point, then su and do:
    mount -t ext3 /dev/sdb <MOUNT_POINT>
    
  6. Now you can copy over your data. And here’s the beautiful part: you should be able to get on the network with no problem. If you need anything that’s not installed, just apt-get update and then apt-get install the missing package. Should work, no problem.

January 3, 2010

No handlers could be found for logger “bzr”

Filed under: Linux — Chris @ 6:25 pm

This usually just means you don’t have permission to write to the log. Sometimes it ends up belonging to root (maybe because I did sudo bzr in /etc using etckeeper?). Just do:

$ sudo chown $USER ~/.bzr.log
$ chmod 644 ~/.bzr.log

June 11, 2009

Sans a iPod

Filed under: Linux, Tech — Chris @ 3:42 pm

I left my iPod Nano in the back of a cab a few weeks ago (yes, I was drunk). To punish myself, and to hopefully avoid some of the problems I’ve had using iPods with Linux (see here and here), I decided to buy a Sandisk Sansa Fuze. This is basically a generic Nano: an 8GB solid state media player with a small screen and video capabilities. It’s about $50 cheaper than the Nano and about 50% crappier in every dimension: it’s bigger and thicker than the Nano and suprisingly heavy; has a first-gen iPod-style mechanical scroll wheel and a misaligned headphone jack; the screen is noticeably low resolution; and the control is counterintuitive (the main menu items swoop diagonally from lower left to upper right—I still can’t wrap my head around which way to turn the wheel). It does have several features that the Nano lacks, e.g., a built-in FM radio and a voice recorder, which I plan to use approximately never.

My expectation that the Fuze would play nicer with Linux were met in one big way: in MSC (USB Mass Storage Device Class) mode, the Fuze looks just like a USB flash drive with some special folders set up (e.g., Music, Videos, Podcasts, etc.). Copying music onto the device is easy as pie. No need to worry about a cryptographic hash. No need to recompile Rhythmbox or Amarok. It Just Works.

My expectations were frustrated in other ways.

  1. Depending on who you ask, encoding videos for the Fuze is damn difficult or impossible on Linux. I haven’t really tried to solve this, because I can live without video (I only ever used it to stare at the pasty, inert, all-over inessential faces of various Bloggingheads), but the whole situation is absurd. You wouldn’t ship a music player that can’t play MP3s. Nor should you ship a video player that can’t play MP4s. (Yes, yes, I understand that MPEG-4 is a big, unwieldy beast that makes a mockery of the term “standard.” I even understand that video podcasts may use patent-encumbered codecs. But the answer to that is most certainly not to force me to run all my videos through a proprietary Windows-only media converter.)
  2. Connecting to the player in MTP (Media Transfer Protocol) mode required backporting libmtp 0.3.7 from the Karmic repository. This is no big deal, because the one and only reason I wanted to connect via MTP was to remove the lame music and videos that came preloaded on the player. (Media loaded in MTP mode can only be removed in MTP mode. Media loaded in MSC mode can only be unloaded in MSC mode.) The Fuze crashed when I tried to eject it in MTP mode. But I rebooted it and the files were gone, so I’m happy.
  3. Podcasts have a tendency to show up with strange, undescriptive code names. This might be Gpodder’s or the podcasts feeds’ fault, for all I know.

Overall, I’m content with the purchase. The Fuze is definitely Less Cool than the Nano. But next to an iPhone, a Nano is a pretty weak status signifier, don’t you think?

April 17, 2009

Becoming a gpodder

Filed under: Linux — Chris @ 5:40 pm

Amarok mysteriously started to have problems copying video to my Nano. It would copy .mp4s, but they would show up as audio files. It would straight-up refuse to copy .m4vs, saying the track was “not playable on media device.” None of the information I could find online was helpful.

For this reason, among others (e.g., 1.4 is “unmaintained” and won’t be included in Ubuntu 9.04 (aka Jaunty), but 2.0 doesn’t even have iPod support yet), I decided to try a new approach to managing my podcasts. Luckily, gtkpod and gpodder both have 4G Nano support in the Jaunty repo and are easily backported to Intrepid using prevu (or you can just run Jaunty, which will be officially released next week).

A few complaints: the gtkpod and gpodder documentation is thin. For example, it took me a while to figure out that gtkpod can’t handle podcasts even though it prominently features a Podcasts playlist on startup. It took me another little while to figure out that gpodder does both the “podcatching” and iPod synchronizing itself (I thought I needed to set up some kind of handshake between gpodder and gtkpod, probably involving the gtkpod Podcasts playlist). Then it took me another little while to get the gpodder synchronization working correctly. It turns out that gpodder wants to have total control over the Podcasts playlist and will fail silently if you try to synchronize with a playlist created by another tool (say Amarok). It’s easy enough to clear out the playlist using gtkpod (though some episodes of This American Life had to be sacrificed) after which gpodder works fine.

But all that aside (though all that is actually a lot), gpodder has a much nicer podcast management interface than Amarok (which treated podcast feeds as a special kind of playlist, a very leaky abstraction). I’m in the market for a new Linux media player. From what I’ve seen, Songbird is not it (unless you like programs that start up, never create a window, then won’t die).

March 11, 2009

LD_LIBRARY_PATH and the dangers of .bash_env

Filed under: Linux — Chris @ 3:48 pm

So, I have two versions of a shared library: the stable version, which is installed under ~/builds/libfoo and a development version, which lives in the source tree ~/src/libfoo. I have just compiled a new version of the source and I want to test it, so I run make test.

Crash. Uh oh.

Let’s try the static version of the library.

OK. That works.

Maybe it’s picking up the wrong version of the shared library. I set LD_LIBRARY_PATH=~/src/libfoo and run make test.

Crash. Damn.

make test is, after a fashion, running ./bin/test. Let’s try that ourselves.

That works. Huh?!

$ export LD_LIBRARY_PATH=/home/chris/src/libfoo/lib
$ ldd ./bin/test
...
	libfoo.so.1 => /home/chris/builds/libfoo/lib/libfoo.so.1.0
...

Do you trust export?

$ LD_LIBRARY_PATH=/home/chris/src/libfoo/lib ldd ./bin/test
...
	libfoo.so.1 => /home/chris/builds/libfoo/lib/libfoo.so.1.0
...

Do you trust ldd?

$ /lib/ld-linux.so.2 --list ./bin/test
...
	libfoo.so.1 => /home/chris/src/libfoo/lib/libfoo.so.1.1
...

Damn you ldd. I knew it was you all along.

So, what happened? Some time ago, in the pursuit of a PATH-related bug, I moved all my shell path-munging preferences—including adding ~/builds/libfoo/lib to LD_LIBRARY_PATH—to .bash_env. .bash_env gets read every time that a new shell is created, including—wait for it—when running shell scripts or make. (ldd is a shell script. ld-linux.so.2 isn’t.) In other words, the line

export LD_LIBRARY_PATH=~/builds/libfoo/lib:$LD_LIBRARY_PATH

in my .bash_env was clobbering all of my attempts to set LD_LIBRARY_PATH at the command line.

The moral of the story? Munge LD_LIBRARY_PATH in your .bash_profile. And never trust ldd.

February 16, 2009

Using an iPod Nano on Linux

Filed under: Linux — Chris @ 6:43 pm

I recently bought an iPod Nano and I’m pleased to report it works just fine with Ubuntu 8.10 (aka Intrepid) and Amarok. I’m able to sync MP3s and podcasts (including video podcasts). I’m even able to transcode videos to MP4 and copy them over by hand. The only hitch is certain special menu entries like “Videos -> TV Shows” that seem to be controlled by iTunes and are, in my case, sadly depopulated. (This isn’t a Linux-specific issue. I was never able to get Audible audiobooks into the top-level “Audiobooks” menu on my old iPod. That was on a Mac, using iTunes. I’m thinking Apple wants to nudge you towards the iTunes Store.)

The instructions here and here are for the most part sufficient, but I thought I’d try to update and boil them down to a few easy steps, if only to increase the overall quality of Google searches for “ipod linux”. The instructions below are for Amarok, but should be easily adapted to Rhythmbox or gtkpod.

[UPDATE] These instructions are for a FAT32-formatted iPod, which includes any brand-new iPod which has not previously been connected to a Mac. I don’t recommend trying to use an HFS+-formatted iPod on Linux. The support for HFS+ is flaky and the filesystem tends to get corrupted frequently. (This may mainly be a problem with going back and forth between Mac and Linux, but there’s no good reason to use HFS+ unless you are going back and forth.) [/UPDATE]

  1. You will need to install libgpod and Amarok. Unfortunately, the version of libgpod in the stable repositories of Ubuntu, Debian, and Red Hat (v0.6.0) doesn’t support the newer (4G) Nanos. The only real consequence of this is a lack of per-track cover art (“Cover Flow” works fine), so you may be tempted to ignore it. Fortunately, it’s relatively easy to backport v0.7.0 to Intrepid. Unfortunately, you also need to rebuild Amarok/Rhythmbox/gtkpod/whatever against the new library (the Jaunty repo has the right version of libgpod, but not the rebuilt version of Amarok). Fortunately, I did this all for you, and you can grab a versions of libgpod and Amarok that support 4G Nanos on Intrepid from my PPA (click on “Follow these instructions” to add the PPA as an APT repository, or just download the .debs and use gdbi or dpkg).[UPDATE] Hardy packages are available here. Jaunty packages are here (Note: you have to use an unofficial Amarok 1.4 package, because Amarok 2.0 doesn’t support iPods at all (don’t ask)). The official Jaunty repos now have an updated version of gtkpod, but  not Rhythmbox AFAICT.  [/UPDATE]
  2. The iPod’s track database is encrypted, so you’ll have to help your computer decode it. Find its serial number using
    sudo lsusb -v | grep -i 'Serial.*[0-9A-Z]\{16\}'

    This will output something like

      iSerial                 3 000A27001DE47C90

    Copy-and-paste the 16 hex digits into /media/IPOD/iPod_Control/Device/SysInfo like so:

    FirewireGuid: 000A27001DE47C90

    (If your iPod isn’t mounted at /media/IPOD, use mount and look for an entry for /dev/sdb1, sdb2, or sdc1.)

  3. Now, you can go into “Settings -> Configure Amarok… -> Media Devices” and add your iPod. It should be automatically detected.
  4. If you click on “Devices” on the left-hand side of the Amarok window, you should see your iPod. Click on the iPod button and set your iPod model. Wikipedia has a handy illustrated table if you don’t happen to know which G your model belongs to (current on-sale models are the 6G Classic, 4G Nano, and 3G Shuffle).
  5. You can connect, you can sync (“Transfer”), and you can disconnect. You may have to fiddle with the “Post-disconnect command” in the “Media Device Configuration.” This one works for me:
    gnome-eject -n -p /media/IPOD

    If the iPod is still mounted after disconnection (i.e., the iPod screen still says “Connected”), you can use

    sudo eject /dev/sdb1

    (or sdc1, or whatever. You may accidentally eject a different USB device.)

[UPDATE 4/17/2009] I’m giving up on Amarok for managing my Nano: it stopped working with videos and I can’t figure out why.

November 22, 2008

An Intrepid Upgrade

Filed under: Linux — Chris @ 3:45 pm

Intrepid Ibex

Every Ubuntu upgrade gets a little bit better, but they are never painless. Why is that?

  • Wifi didn’t work at first, or after a reboot, or after the next one. But then it started working—I don’t know why—and it’s fine. The blinking light is annoying, though.
  • Sound completely died: any attempt to play a sound would yield a quiet crackling noise from the speakers. The semi-official PulseAudio HOWTO didn’t help (though it didn’t hurt). It turns out the PCM setting in alsamixer was at 0. Jacking that up fixed the problem. (Thanks to psyke83 on the Ubuntu forums.)
  • Boot-up doesn’t drop down to the console for interminable fsck runs, which is nice.
  • Ibexes are cool, but the old logo was better.

September 2, 2008

WINE Paths

Filed under: Linux — Chris @ 11:02 pm

If you try to run a Windows command-line app on Linux under WINE, you may find that filename arguments yield errors like the following:

$ wine z3.exe -smt /tmp/smtlib2b129a.smt

Error: invalid command line option: /tmp/smtlib2b129a.smt
For usage information: z3 /h

The problem here is that the ‘/’ at the beginning of an absolute path can be interpreted as the beginning of a Windows-style command-line argument. The following script takes a Windows command-line and Windows-ifies Unix path arguments.

#! /bin/bash

if [ "${1+set}" != "set" ]
then
  echo "Usage; winewrap EXEC [ARGS...]"
  exit 1
fi

EXEC="$1"
shift

for p in "$@";
do
  if [ -e "$p" ];
  then
    p=$(winepath -w "$p")
  fi
  ARGS="$ARGS $p"
done

wine "$EXEC" $ARGS

The script can be used thus:

$ winewrap z3.exe -smt /tmp/smtlib2b129a.smt

Which will execute

wine z3.exe -smt Z:\tmp\smtlib2b129a.smt

P.S. You can also just use the WINE drive mapping (in this case / == Z:\), but I’d rather keep my Unix mindset and let the script do the work.

August 29, 2008

Using lp/lpr with CUPS

Filed under: Linux — Chris @ 4:12 pm

Ubuntu provides the traditional Unix lp/lpr commands via the cupsys-bsd package, but they annoyingly don’t pick up the CUPS default printer.
How do you identify your current default printer from the command line?

lpstat -d

How do you set your preferred default printer?

lpoptions -d PRINTER_NAME

Ah, yes. But how do you find the names of your installed printers?

lpstat -a

What’s all this good for anyway?

lpr [-P PRINTER_NAME] PS_OR_TXT_FILE
-OR-
enscript [-P PRINTER_NAME] TXT_FILE

August 27, 2008

Finding the Trash in GNOME

Filed under: Linux, Tech — Chris @ 12:56 pm
GNOME Disk Usage Analyzer

GNOME Disk Usage Analyzer

I somehow moved a file owned by root into the Trash, then I couldn’t make it go away: “Empty Trash” failed with permission problems. Thanks to the Ubuntu Geek blog—and especially commenter Ayenack—I found the secret location of the trash:

~/.local/share/Trash

The files in this folder can be chmod‘d and rm‘d just like any others (e.g.,

rm -rf ~/.local/share/Trash/*

is observationally equivalent to “Empty Trash”).

NOTE: The (otherwise very cool) GNOME Disk Usage Analyzer (aka Baobab) moves files to ~/.Trash—which is not the Trash—on “Move to Trash.” This is annoying.

[UPDATE 9/8/2008] If you do gksudo nautilus and delete files, then click on the trash icon in Nautilus it says, “The folder contents could not be displayed…” and “Empty Trash” is grayed out. But the files are in /root/.local/share/Trash, as you might expect. Just do

sudo rm -rf /root/.local/share/Trash/*

Older Posts »

Create a free website or blog at WordPress.com.