Archive for the ‘gotcha’ Category

LVM Anomalie

Saturday, March 25th, 2006

I walk in the office on a fine Sunday morning to find out electricity has gone down restarting all boxes. One of my Debians wouldn’t leave runlevel 1 because of a logical volume not being mapped. I started the a typical bottom up troubleshooting procedure and at the first step (forget the vgscan and lvm libraries loading) :

timon:~# pvdisplay
Couldn’t find device with uuid ‘CMXpz2-HQQw-RO4k-5K2J-0mO4-oxTY-WvkY7W’.

— Physical volume —
PV Name unknown device
VG Name data_vol_grp
PV Size 74.53 GB / not usable 0
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 19079
Free PE 0
Allocated PE 19079
PV UUID CMXpz2-HQQw-RO4k-5K2J-0mO4-oxTY-WvkY7W

— Physical volume —
PV Name /dev/hdd
VG Name data_vol_grp
PV Size 37.27 GB / not usable 0
Allocatable yes (but full)

….
This was – of course – creepy, knowing the drive was brand new, seen by the BIOS and detectable with a simple `fdisk -l`! Also check out the contradiction in italic.

After an hour of playing around … given I know the device path all I had to do is a `pvdisplay /dev/hdc` to get a healthy listing right there :O

I carried on with a `vgchange -a y data_vol_grp` followed by a `fsck.reiserfs` and finally mounted the volume and all was good!

Just thought I’d save some time and ATP burning surprise fellow admins should you ever experience this, especially that (as sledomly as it happens) google wasn’t that helpful.

Happy Hacking

Gotcha – Filenames with spaces and the Shell

Thursday, February 23rd, 2006

I had to write to a shell script that parses a bunch of files. The
problem was some of the file names contained spaces. Here is a sample
scenario and the resolution.

Let’s say you had files: “test 1″ and “test 2″ and you tried to do
something as trivial as:

#!/bin/bash

for f in `ls test*`
do

cat $f

done

the result would be:

cat: test: No such file or directory
cat: 1: No such file or directory
cat: test: No such file or directory
cat: 2: No such file or directory

The resolution would be:

#!/bin/bash

IFS=”

for f in `ls test*`
do

cat $f

done

The explanations is that the IFS (interfield seperator) in the shell
defaults to space tab or newline. The space is part of the filename in
our case which will result in two seperate files.
So what we do at the begining of the script is set the IFS variable to
newline only.