Friday, May 24, 2013

Zapping stale kernel images on Ubuntu

Spring cleaning time, I wanted to keep my current kernel and the one just installed by a recent upgrade. That argument could have been simplified by using $(uname -r)
dpkg -l | grep linux-image | egrep -v '3.2.0-4(3|4)-generic' | grep -v linux-image-generic | awk '{print $2}' | xargs apt-get remove -y

and the results

...
0 upgraded, 0 newly installed, 25 to remove and 0 not upgraded.
After this operation, 7,807 MB disk space will be freed.

Thursday, May 16, 2013

Introduction to bash coprocess

A complicated way to do something very simple. I suppose I need to brush up more on my bash file descriptor chops.
$ coproc virsh
[1] 14358
$ cat > flywheel.xml <&${COPROC[0]}
^Z
[2]+  Stopped                 cat > flywheel.xml 0<&${COPROC[0]}
$ bg
$ echo 'dumpxml flywheel' >&${COPROC[1]}
$ echo 'exit' >&${COPROC[1]}
$ 
[1]-  Done                    coproc COPROC virsh
[2]+  Done                    cat > flywheel.xml 0<&${COPROC[0]}
It may not be as efficient as this for small jobs:
echo "dumpxml $d" | virsh > $dest
But for driving longer running processes, this might be kinda cool.

Monday, May 13, 2013

scripting mdadm raid creation starting from a bare disk

I learned today that you can drive fdisk by just using echo. echo commands with no arguments serve as '/n' so you can take the defaults for starting and ending cylinder etc. Using fd "Linux raid auto" for the partition type.
for disk in $(ls /dev/disk/by-path/pci-0000:03:00.0-sas*lun-0);
do
  echo "zeroing $disk"
  dd if=/dev/zero of=$disk bs=1M count=10
  sync

  echo "creating RAID paritions on SAS disks"
  (echo n; echo p; echo 1; echo ; echo; echo t; echo fd; echo w) | fdisk $disk

  echo "verifying..."
  (echo p; echo q) | fdisk $disk
done
This is just a sample of the script found here:

https://github.com/ppetraki/storage-tools/blob/master/create-mdraid-from-scratch.sh

Which will take your disks from bare block devices all the way to running md and create the config.