Technical stuff, mostly to remind myself when I forget in a couple of months' time.

Sunday, 2 March 2014

Partitioning and formatting a 4TB disk

Amazing what just over a ton will get you these days - 4 TB of disk. I know it makes me sound old but I remember having a 10 MB disk and being pleased ...

Anyway, setting it up wasn't difficult but I didn't find a single consolidated guide to do what I wanted, which was to create two ext4 partitions, one normal and one encrypted with LUKS, for personal information. So here's what I did.

Partition the disk
Anything over 2TB is not supported by the venerable MBR, so the newer GPT partitioning scheme is needed, which in turn requires the use of a partitioning tool that supports GPT. I used parted (which I had to install first), like so:

# parted /dev/sdc
> unit %
> mklabel gpt
> mkpart primary 0 50
> mkpart primary 50 100
> print
> quit

Create file systems
1) The normal partition
# mkfs.ext4 /dev/sdc1

2) the LUKS parition
# cryptsetup -y -v luksFormat /dev/sdc2
# cryptsetup luksOpen /dev/sdc2 d2
# mkfs.ext4 /dev/mapper/d2

Reduce amount of system space
ext4 reserves 5% of the disk for system space by default, which on a 2TB volume is 100GB. This is excessive for volumes that just contain data and not any OS files. The following commands reduce this allocation to 1% and free up about 80GB of space.

# tune2fs -m 1 /dev/sdc1
# tune2fs -m 1 /dev/mapper/h2


Then mount in your preferred location and away you go!

Friday, 31 May 2013

Copying music files

My music files are stored on a server; sometimes I want to copy a selection onto sn SD card for playing in the car. The steps are:

  1. Make a playlist on the Squeezebox.
  2. Grab the playlist m3u file.
  3. Remove all the lines that start with the # character: sed '/#/d' playlist.m3u > music.txt
  4. Mount the Samba music share on my server: sudo mount -t cifs -o username=me //192.168.1.2/music /media/music
  5. Do a search and replace in a text editor on the text file so that the paths all reference /media/music
  6. Copy the files: first set IFS to a new line, then: for file in $(<music.txt); do cp -v "$file" music/; done
Then I run the files through Sound Converter because the player in my car can only deal with mp3 files.

Wednesday, 6 March 2013

"Editing" symlinks on Linux

Firstly, let's be clear. There *is* no way of editing symlinks. All you can do is delete them and recreate them. However, there is a way of automating this process.

I had lots of photos on one disk and then moved them. The links to the files needed changing en masse and I didn't want to have to redo it by hand. What I needed was a way of finding out where the link *used* to point to and use that to construct the new link.

The answer was readlink. Thus:
#!/bin/bash
for fn in *.jpg; do
    NEWFN=$(readlink $fn | sed 's,/media/d1,/media/d2,')
    ln -sf $NEWFN $fn
done
Pipe the data from readlink into sed, which is used to replace an occurrence of the string /media/d1 with /media/d2. Then recreate the link, using the -f flag to delete an existing link.

Easy. Full credit to this post on SuperUser.

Wednesday, 11 July 2012

Updating Debian Squeeze on PogoPlug

There's a nasty little bug in Debian Squeeze which means that if you update the kernel, IPv6 stops working.  The reason this is so annoying for me is that if the networking doesn't work, I can't get into the PogoPlug at all (there is no direct access, not even a serial console).  It's effectively bricked.

The answer is to run flash-kernel after running apt-get upgrade.  This updates the /boot/uImage and /boot/uInitrd files.  The bug is that this isn't run automatically.

The actual answer for me was to restore from a last known good backup from a couple of weeks ago. I attempted to look at the flash-kernel script and create these files by hand but it didn't work.

Friday, 22 June 2012

Check a Linux hard disk - command line

Although checking a ext2/3 disk from the command line is easy, there is surprisingly little concise info out there.  Here's what I did when faced with a disk that kept going into read-only mode (which is usually a sign that something is wrong):

sudo fsck -V -C /dev/sdc1 -- -y -f

I had originally thought that calling e2fsck was correct but fsck is a wrapper which calls the correct version for the file system.  It defaults to ext2.

The options I used are:
-V
Verbose
-C
Gives a progress bar
-y
Answers "yes" to all interactive questions
-f
Forces a check even if one has been done recently.
-c
Uses the badblocks utility to check for bad blocks (duh) and feeds this information into fsck in order to mark those blocks off. From what I read, you are better off specifying this parameter to fsck than running badblocks separately because it will work out block sizes for you this way.

Note that some of the options follow the device name.  These options are passed to the underlying program (e.g. fsck.ext2) without verification.

Tuesday, 22 November 2011

Logitech Media Server and media keys

I use squeezeslave to listen to music from my Logitech Media Server (LMS; previously known as Squeezebox Server).  The LMS has a pretty good web UI which can be used to control the player.  However, it's quicker to be able to use the media keys to do simple actions - pause/resume, previous, next.  It saves having to navigate to the browser window and move the mouse around.

Here's how I set this up on Ubuntu 11.04.

Firstly, you need a script to send commands directly to the LMS command line interface (CLI).  Luckily someone has written this.  The script is called sccmd and it's part of the squeezeslave codebase, I think.  However, I couldn't figure out how to get it from the main squeezeslave page at sourceforge and in fact I originally found it on github where someone has a mirror of the code.  Just copy the script to somewhere appropriate on your local drive (I put it in ~/bin which is automatically on the path in Ubuntu), modify it as necessary for your player and server (change the MAC address and host name) and make it executable.

Secondly, you need to map the keys.  Disable the media keys in the Keyboard Shortcuts settings panel. Then, if you're using Unity, then you can map the keys to the script using the CompizConfig Settings Manager (compizconfig-settings-manager in the Universe repository).  Go to the "Commands" plugin (enabling it if necessary) and define three command lines.  They are:

  • /home/user/bin/sscmd pause
  • /home/user/bin/sscmd "button jump_rew"
  • /home/user/bin/sscmd "button jump_fwd"

Then go to the second tab, Key Bindings, and define the keys.  This is a simple matter of clicking the "Disabled" button, clicking "Grab key combination" and pressing the appropriate key.

Finally, if you are using this remotely over ssh (as per my previous post) then you need to modify the ssh config to forward port 9090, which is the port used by the CLI (or change it in the LMS settings to a different port and forward that).  In this case, the host name in the sccmd file will be "localhost".

Update: in 12.10 I found that I needed to install the package "compiz-plugins" to get the "Commands" plugin.

Monday, 18 July 2011

Building a SqueezeBox server on PogoPlug

Quick summary for those in a hurry


That's it! Read on if you're interested in more detail and my ramblings ...

The concept

For some time I've been pondering how to solve a problem.  As I mentioned before, the machine I use to run Squeezebox Server (SBS) is old and noisy - and, unfortunately, the only place it can go at the moment is in our bedroom.  This means it can't be on all the time, which is a bit annoying sometimes.  One possible longer term solution was to move the whole kit and caboodle up into the loft, but that would require a lot of cabling and in any case I was a little worried about the temperature up there in summer.

I know people have installed SBS on NASes and the like although I'd never really looked into this. Then a few weeks ago I came across a post about setting up a SBS for under $100. That was quite interesting, but what really caught my attention was an addendum right at the end that mentioned the guy was setting up a server on a SheevaPlug - a whole computer in a (large, wall-wart type) plug! Why this should be surprising in these days of iPhones and so on I don't know, but it caught my attention.  The idea of replacing my big, old, noisy server with a small, low power, permanently on device for only a few tens of pounds was very appealing.

I started looking into the subject a bit more and found that there are a number of these "plug computers" around - albeit not literally built into a plug (even the SheevaPlug has a separate power cable in the non-US version).  The SheevaPlug is sold as a "development kit", the intention being that other manufacturers would then base their own products on it, but you can buy it as a consumer to, for about £100 in the UK.  This gives you a base computer with which to do what you will.  There is a branded consumer version too, called the TonidoPlug, which comes with some bundled apps and costs about $99 (although I can't find a UK outlet).

The SheevaPlug is now a couple of years old and there are newer versions from the same manufacturer but these start getting more expensive.  But there are other options too.  The Seagate Dockstar is a small device with a dock for Seagate disks and USB ports for other disks, plus a network connection.  It's based (I believe) on the PogoPlug (link is to v2 page), another "plug computer", which its v1 incarnation looked similar to the SheevaPlug.  Both of these allow you to attach disks to it, connect it to your home network and register it with my.pogoplug.com in order to be able to access the content on the disks from anywhere on the internet.  How these then differ from a NAS such as the LinkSys NSLU2 I don't know (apart from the external access).

What's interesting of course is that although these - the SheevaPlug apart - are sold as consumer, "plug 'n' play" devices, they are all fully fledged computers, running embedded Linux.  And there's no shortage of information on how to reconfigure them as general purpose servers - or even specifically as SqueezeBox Servers.  Having read around the subject for a few days, I decided to go for the cheapest option, the PogoPlug - only £50 on Amazon.  This seemed a reasonable amount of money to commit to an experiment - since, from what I'd read, there was some chance that the process of installing a new system might not work properly, and also there was a chance that it just wouldn't be powerful enough to do what I wanted (specifically, there was a passing mention on one the SqueezeBox forums that it used a single-threaded Perl, which would be an issue for SBS).

The implementation

The PogoPlug v2 is a small, nicely styled box about the same size as a router.  It has a Marvell Kirkwood ARM processor, four USB 2.0 ports, one ethernet connector and a power socket, 256 MB of RAM and 128 MB of internal storage (for the OS). It's larger than I expected (v1 really was the size of a plug) but still very unobtrusive, and tiny compared to my current server!

There are a couple of configuration options, drawing on the sterling work of one Jeff Doozan. He's figured out how to patch the embedded OS to boot from an attached USB drive, or even install on the internal storage. From then on, you can install any OS that supports the processor I guess, although I think in reality that means Linux. I found instructions to install ArchLinux and Debian (Jeff Doozan's instructions). Since I'm very familiar with Ubuntu, I chose Debian.

Most of the instructions I found concentrated on the Dockstar, presumably since this is a more common device.  For example, the instructions on the SqueezePlug wiki, which seemed complicated and in any case specifically aimed at Linux newbies.

Instead, I found some very helpful instructions which were specifically for the PogoPlug v2.  These go as far as installing Debian.  There's no point in reproducing them, so here's a couple of additional comments:

  • A number of sources mention that you will need to register at my.pogoplug.com in order to enable ssh, which is vital if you're going to get anywhere.  In fact, I found it was open anyway.  The only precaution I took was to disconnect my router from the internet until I'd disabled the auto-updating service that runs automatically.
  • Most of the instructions implicitly assume you'll be using a flash drive as the boot source but I didn't have one lying around.  I did have a spare 80GB USB disk though, so I used that.  It worked fine.
  • The script ran fine apart from a couple of files it couldn't find - in fact, the md5 files corresponding to the main files were missing off the server.  A minor correction to the script fixed this (and mehl has since resolved this).
  • I found that installing extra packages gave a warning about non-verified packages until I re-ran apt-get update.
  • The first packages to install were apt-utils and dialog, which are both used by some packages when installing.  I also installed sudo and nano, as per the instructions.
  • I followed mehl's instructions to set up a user account with sudo access and lock out root (as Ubuntu does), which I think makes sense on a semi-public facing server.
  • Finally, I configured ssh in the same way I did when I set up my first Squeezebox server.  mehl also has some instructions for configuring ssh.

Having done this, the next step was to shut down and backup the drive before I did anything stupid!

Installing SqueezeBox Server was pretty straightforward.  The SqueezePlug wiki also has some notes about manually installing SBS, which is what I followed.
  • First, I set up a mount point for the disk drive at /media/d1.
  • Then I plugged in the drive with the music on (a separate Seagate 1TB drive) and mounted it.
  • Next, I created a symlink from the root directory to the music directory on the Seagate drive.  This means I can configure SBS to look in a given directory and change the drive without reconfiguring SBS.
  • Then I installed SBS using the instructions in the wiki.

Having done this, I pointed my browser to the SBS web ui, did the minimal config necessary and let the music scan run.  It took a little under two hours - but I do have a reasonably large collection (over 28,000 tracks).

And that's it!  The performance when playing music is indistinguishable from that of the big old server.  The SBS web ui is a little slower perhaps, but not much.  The PogoPlug itself makes no noise at all; the disks are very quiet, albeit just about discernible in a quiet room.

Your Host

Husband, father, pop music anorak, guitarist