linux ubuntu

Solved: No Files In MPD (eg mpc ls)

I was doing my initial “is it working?” tests after reinstalling mpc, and mpc ls was not giving me any output. ncmpc was also showing no files. What I didn’t appreciate was that the music database is no populated by default- you have to issue an “update” command manually (or semi-manually by running a client that issues the command for you).

mpc update

and your directories should be searched!

all posts life linux tech ubuntu

Show Progress Bar During dd Copy

There are a number of ways of showing the progress of a dd copy. The easiest is sending the USER1 signal to the dd process, like:

dd if=FILE1 of=FILE2
pkill -USER1 dd

But that only gives a current status – eg 12345678 bytes transferred (11.77MB) … [8.56MB/s]. Not that helpful if you want an ongoing update. You can make it periodic by using the watch command:

watch -n 10 pkill -USR1 dd

Still not perfect. If you want a progress bar, ETA and so forth, you’re best off using pv, a utility that measures the speed of a file through a pipe. If you don’t know what that means, I’d recommend reading up on the UNIX philosophy and pipes, but basically it means you can tell what dd is doing. Use it like so:

pv FILE1 | dd of=FILE2

For my use, backing up a 500GB hard drive that I use with a NAS (an NSLU2 I’ve probably mentioned before), I used the following command:

sudo pv /dev/sde3 |dd of=~/tera/nslu2.img

/dev/de3 is the data partition on the drive
~/tera/nslu2.img is the image file I want written to a terabyte-sized hard drive, mounted at ~/tera/.

As a post-script, the reason I’m backing this drive up is my nslu2 is failing weirdly. It was running without a hitch for years, then it without apparent warning dismounted the drive in slot1 and reverted to running from flash. I only figured that out as I had to log in with an old password. Trying to start it up results in it beeping once every minute or so, with the ready status lamp flashing orange. It seems to go through a loop. I thought it was a temporary glitch, as when I plugged the drive into my desktop to check the thing was intact the partitions showed up, then when I plugged it back into the nslu2 and turned it on it worked fine.

That was 3 nights ago. This evening it’s done the same thing, except repeating the steps didn’t sort it out. Running the drive through some brief SMART diagnostics and a partition check shows up no problems, so I’m inclined to believe the problem lies in the nslu2. I’ll post again if I can sort it, but at this stage I think a re-flashing is in order. Only problem is I can’t remember what firmware I flashed onto the nslu2 in the first place. D’oh!

all posts life linux ubuntu

Connect to a WPA/WPA2 Secured Network In Linux

This turned out to be dead easy, although it took a bit of futzing around due to my own slowness. The situation arose during an a failed upgrade of my dad’s machine to Ubuntu 10.04 (aka Lucid Lynx). I’m sensing a pattern here; I don’t think there has been an upgrade that has gone smoothly on that machine. To be fair I think there may be problems with just about every component apart from the hard drive, but you think I would realise that upgrading that machine is a Bad Idea. Anyway, the solution:

A combination of wpa_supplicant and wpa_passphrase will do the trick.

  1. Get a root prompt. Either sudo su, or boot to single user (recovery) mode. Just don’t do that, select netroot, then get bored and hit Alt-F1 for a console 1. For some reason, that makes the machine very unhappy and so your wireless hardware probably will complain about device busy in step 2. So don’t do that.
  2. Run iwlist scanning, and check your card can see the wireless network in question
  3. If it can, run wpa_passphrase [your-wireless-network-name] > wpa.conf
    (eg wpa_passphrase pegasus > wpa.conf). The prompt will wait for you to enter a passphrase. Do this and hit enter.
  4. Run wpa_supplicant. Replace wext with the correct wireless driver (which is probably wext, but run wpa_supplicant --help to check) and wlan0 with your wireless interface
  5. wpa_supplicant -Dwext -iwlan0 -c/root/wpa.conf
  6. If that works, you should see text to the effect of “successfully associated”. If not, try again with a different driver, make sure your passphrase is correct, and make sure your wireless interface is working properly.
  7. Hit Ctrl+c, then the up arrow, then add a -B (for background) onto the end of the last command, thus: wpa_supplicant -Dwext -iwlan0 -c/root/wpa.conf -B
  8. Run dhclient -r to release any DHCP leases you have.
  9. Run dhclient wlan0 to get a new IP address. Substitute wlan0 for your wireless interface, of course.

You should now be connected. This is a handy trick for any Linux user unaccustomed to connecting to wireless networks from the command line – let’s face it, network-manager has spoiled us rotten. But when an upgrade fails and won’t leave you with a functioning graphics driver (grr) and you need some packages, this is the way to do it.

all posts linux software ubuntu

Ubuntu 9.10 Karmic Upgrade Problem Fixed (mountall/init)

(Jump to the bonus section on sorting a removed Gnome panel)

I finally got round to doing the Jaunty->Karmic upgrade on a troublesome machine. Well, re-doing. I made an abortive attempt to install it on this particular exhibit of electronic arthritis back before I left for Barcelona, which ended in me reinstalling 9.04.

Anyway, for one reason or another the upgrade failed or was interrupted and so I was left with a machine that would not boot. Well, it would do a good chunk of the boot process, but fail at an init item (init_bottom, I think). mountall was exiting with code 127, complaining:

process mountall (787) exited with code 127:
undefined symbol: udev_monitor_filter_add_match_subsystem_devtype

Quite a mouthful, in other words. Even booting into “recovery mode” didn’t give me a working console. Next step: try a liveCD. The same problem was reported by niroht of the ubutuforums here. However, his explanation is a bit brief, and misses out a couple gotchas.

So, you’ve got a problem with mountall, and you’ve also got a 9.10 liveCD. Here’s how to sort it:

  1. Boot from the livecd
  2. Call up a terminal (gnome-terminal or xterm).
  3. Chroot your usual install partition. GParted, under “Administration” can help you determine what this is. Mine was /dev/sda3. What I did was:
    • sudo su
    • mkdir /newroot
    • mount /newroot /dev/sda3
    • chroot /newroot <- chrooting my install parition
    • mount /proc <- important! not mounting /proc causes all sorts of problems.

    Now you’re chrooted and ready to continue. I have a separate /boot partition as well, but I updated this later to save faffing at this stage.

  4. Sort the botched upgrade! I ran first dpkg --configure -a, then to be sure, apt-get -f install. Finally, I ran apt-get dist-upgrade, which upgraded a *lot* of packages (~700 I think).

Now, if your /boot prtition resides on the same partition, you’re done here. If not, you have to mount it and copy the new kernel images and updated menu.lst. Strictly speaking, this should be possible to set up when doing the chroot above, but I couldn’t remember how to do it at the time. Make sure if you are merging the menu.lst that the contents are correct – check the UUIDs or partition references are correct!

Bonus! Restore the default gnome-panel if you accidentally delete

So once I was done with the fixed upgrade I booted, and got a slightly messed up top Gnome panel. Two volume icons, and no network icon. In my attempt to sort it, I clicked cack-handedly and removed the entire panel. Rather than repopulate it manually, I followed the advice of another ubuntuforums thread:

gconftool-2 --shutdown
rm -rf ~/.gconf/apps/panel
pkill gnome-panel

And that was the panel restored to default!

* (Previously listed as “undev_mknitor_filter_add_match_sebsystem_devtype”, as it appeared on the screen. Part of the electronic arthritis is (I think) in the graphics card, which causes all sorts of odd things to happen to the pre-boot text. Must photo it sometime.)

all posts linux ubuntu

Count Arguments In A Bash Script

Another useful tip I’m sure most people will be familiar with, but in bash scripts $# stores the number of arguments passed to the script. Eg, combine with $@ (all arguments) for batch processing (what I used it for):

foreach $arg in $@; do
[compare with $# to tell remaining items]

Very basic stuff, but it was new to me yesterday, and it might save someone a bit of time searching.

linux ubuntu

Batch Rename or Move An Extension In Linux (Eg .JPG to .jpg)

A short and easy trick, but one that is either not referred to or more complex examples given. I wanted to change a bunch of upper case .JPG images to lower case. Rather than writing a bash script or some such, I just used the ‘rename’ command:

rename 's/\.JPG$/\.jpg/' *.JPG

It may depend on perl being installed though. I don’t have a Linux machine to hand that doesn’t have perl present, so I cannot verify this. If this command doens’t work for you, please leave a comment to that effect below.

Another useful one from the manpage:

rename 'y/A-Z/a-z/' *

To translate upper case filenames (and extensions by the looks of it) to lower case.

all posts linux ubuntu

Back to Ubuntu

So I’m suppose to be revising for the Big Testâ„¢ that I’ve got tomorrow, but instead I decided to reboot in Ubuntu. And by gosh, I’d forgotten how nice it looks. And this is still the 7.04 version! Sounds are nice too – it’s probably just subjective perception, but playing music sounds nicer too, although I’d still like to get my hands on an equaliser and turn the bass down a bit. Yes, I could see myself using this for a while, especially as there aren’t as many game distractions on here…

Why did I ever leave?