Monday 10 December 2012

Fitting a Ford Focus Estate with ISOFIX child seat attachment

I recently bought a second-hand Ford Focus Estate 1.8 TDCi Ghia, 2007. I assumed it would have ISOFIX as standard, as all the information I'd found online, and the owners' manual, suggested this. It turns out however that it's an optional free extra, and my particular car didn't have it fitted. After some googling around I found this thread on on focusowners.com: Ford Focus ISOFIX installation So it's simple.

Amazon actually stock this part (Ford part number 1357238) with (currently) free delivery:

Ford 1357238 Britax ISOfix Mounting Kit for Childseats 2004 Onwards for Focus
Delivery was very quick.

Installation took about 20 minutes. I needed a T45 driver bit and a flat head screwdriver. Following the instructions from the focusowners.com thread, I used the screwdriver to push the seat-back hinge (nearest the door) over and lifted the seat-back up from the hinge. With a bit of wiggling the seat-back could be completely removed from the centre attachment. Under the seat-back in the metal floor were two bolt holes plugged with grey rubber bungs which were easily removed.

I bolted the fitting with the square brackets (the actual ISOFIX attachments) oriented to the bottom edge (the Ford logo stamped on the bar was upside-down). The seat went back into place (a firm bang down gets the hinge back in place) and the fitting was ready to be used. Easy! I don't know why this isn't done as standard, but at least it's not a great deal of hassle to sort.

Photos to come, when I remember.

Friday 5 October 2012

Auto-rip CDs on headless server using udev and abcde

I have a lot of CDs, at least 500. Some of them have over the last few years made their way in FLAC form to the hard disk of my main PC, but now this collection is on the server, I'd like to add the rest of the CDs to the digital library and finally store them out of the way. I wanted a way for the server to do the work of ripping the CDs without any user intervention apart from putting a CD in the drive and taking it out again.

Linux's udev system provides a way for programs to be triggered on hardware events, such as a CD being inserted. In Fedora, udev rules files can be added to /etc/udev/rules.d/ and they will be magically picked up and used.

I wrote a rules file that looked like this:
/etc/udev/rules.d/99-autoripcd.rules

SUBSYSTEM=="block", KERNEL=="sr0", ENV{ID_CDROM_MEDIA_CD}=="1", RUN+="/usr/bin/cdautoinsert" 

Simply, this looks in sysfs's /sys/block/sr0/ for a CD (instead of a DVD) to be inserted, and runs the commmand given by RUN+. This is a shell script which runs the useful cd ripper, abcde. Here is the script:
/usr/bin/cdautoinsert

#/bin/bash

PATH=/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin /bin/abcde -NVP | tee /var/log/abcde-auto.log &

exit

The key to getting this working (and which took some googling to work out) is to pass a PATH to whatever commands you run in the script. This is because udev runs commands (as root) without much of an environment, and abcde was failing to find cdparanoia and the other tools it relies on. The other useful thing to know is to make sure commands are run with & to make the shell detach those processes, otherwise udev will hang until the job is complete, which is about 5 minutes for a typical cd.

I edited /etc/abcde.conf to give abcde defaults that work for me, including:
INTERACTIVE=n     (the -N switch on abcde's command line also does this)
ACTIONS=cddb,read,encode,tag,move,clean
OUTPUTTYPE=flac
OUTPUTFORMAT='${ARTISTFILE}/${ALBUMFILE}/${ARTISTFILE}-${ALBUMFILE}-${TRACKNUM}.${TRACKFILE}' (this fits with the directory structure of my music collection)
EJECTCD=y


When writing your own udev rules, the udevadm tool is handy.
udevadm monitor will show udev events as they happen (so you can see which subsystem to look at)
udevadm info --name=/dev/sr0 --query=all will list everything udev knows about the CD drive

Thursday 27 September 2012

ZFS on Linux - replacing a failed drive in a RAIDZ pool

My server was built using 4 250gb hdds which were passed on to me by a friend who didn't need them any more. One of them failed - no problem, I thought, I have a spare and ZFS will take care of resilvering etc.

Power down the server, swap out the drive, reboot.
# zpool replace tank <failed drive id> <replacement drive id>
gave a Device not in pool error.

Googling suggested exporting then reimporting the pool, but all
# zpool export -r tank
got me was "Pool busy", even though there were no processes accessing it according to fuser and lsof, and zpool iostat showed 0 reads or writes.

Eventually I hit upon this issue in the ZFSonlinux bug tracker:https://github.com/zfsonlinux/zfs/issues/976

Finally a solution to my original problem. I needed full paths to the device names.
# zpool replace tank /dev/disk/by-id/<failed drive id> /dev/disk/by-id/<replacement drive id> 
did the trick:

# zpool status
  pool: tank
 state: DEGRADED
status: One or more devices is currently being resilvered.  The pool will
 continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
 scan: resilver in progress since Fri Sep 28 00:02:04 2012
    12.3G scanned out of 205G at 24.5M/s, 2h14m to go
    3.07G resilvered, 5.98% done
config:

 NAME                                           STATE     READ WRITE CKSUM
 tank                                           DEGRADED     0     0     0
   raidz1-0                                     DEGRADED     0     0     0
     ata-VB0250EAVER_Z2ATRS75                   ONLINE       0     0     0
     ata-WDC_WD2500AAJS-22RYA0_WD-WCAR00411237  ONLINE       0     0     0
     ata-WDC_WD2500JS-75NCB3_WD-WCANK8544801    ONLINE       0     0     0
     replacing-3                                UNAVAIL      0     0     0
       ata-WDC_WD2500JS-75NCB3_WD-WCANKC570943  UNAVAIL      0     0     0
       ata-SAMSUNG_SP2504C_S09QJ1SP156094       ONLINE       0     0     0  (resilvering)

errors: No known data errors
 
Success! Still don't know what was causing the "pool busy" error when trying to export.

I expect this should work in ZFS on Linux for all zpool operations that refer to individual vdevs or disks, like zpool add, zpool remove, etc.

Tuesday 25 September 2012

Automatically share on boot ZFS filesystems via NFS in Fedora Linux using systemd

My media server project had a minor stumble when I found that after rebooting my server the ZFS shares were not showing on NFS clients, even though nfs-server.service was active.

I realised that the zfs shares were not being exported to NFS - I had assumed that ZFS on linux did this automatically on boot.

I wrote a simple systemd unit file to get this working on startup. This is what the file looks like:

/etc/systemd/system/zfs-share.service

[Unit]
Description=Start ZFS share-nfs sharing

[Service]
Type=oneshot
ExecStartPre=/bin/sleep 30
ExecStart=/usr/sbin/zfs share -a
ExecStop=/usr/sbin/zfs unshare -a
RemainAfterExit=yes

[Install]
WantedBy=default.target
After=nfs-server.service, zfs.service
Requires=nfs-server.service, zfs.service
 

This oneshot service simply runs the command
zfs share -a
after the NFS server and its dependencies have started.

systemctl stop zfs-share.service
should unshare the ZFS exports. In a another post I'll jot down how I got native ZFS working under Fedora 17, but it really was a case of following the simple instructions at http://zfsonlinux.org/

Edited 29/9/2012: Added 30-second sleep as ExecStartPre line to give time for ZFS to mount filesystems properly as I was getting errors due to a race condition.