2013/01/29

Booting from a ghost partition

The most insane things can happen. Booting a new kernel, you see it in /boot/grub/grub.conf, but you don't see it in the GRUB menu at boot time. This has happened to me twice recently. First time, I lost 2 hours and thought I was going mad before I figured it out.

The cause is that I have /boot as a software RAID (/dev/md0, raid1 of sda1, sdb1, sdc1). While GRUB supports Linux software RAID1, it only does so partially; it assumes that the first drive of the array is the same as the others and uses it as an ext3 (or other) partition. What had happened a few weeks back was that sda1 had become the spare drive. This was caused by a mislabeled ICY DOCK; what I thought was sda became sdc, and sdc, sda. This first time I gave up before figuring it out, copied /boot into a temp directory, reformatted sda1 as a straight ext3 and copied /boot back into it.

This second time, I had already seen it and new where to look. That is /proc/mdstat. And to make sure that sda1 was an active part of the array. Sure enough, sda1 wasn't even in the array! So

mdadm /dev/md0 --add /dev/sda1
Then wait a minute for the RAID to rebuild, reboot and everything was fine.

This particular array had 3 active drives, no spares. I had replaced sda at some point and while I had added it to the main array (md1, raid5) I hadn't done so for md0. Why does md0 have no spares? It seemed like a good idea at the time. Repairing a computer that won't boot is annoying. Having all active, no spares means you never (in theory) end up with a disk that won't, should the first one give up the disk. And given that /boot is only written to once every blue moon, so it's not like I'm stressing the spare at all.

In the second case all 3 partitions of md0 are active; there are no spare drives. Had it been a case like first one, I would have forced sda1 to be an active partition in the array. Something like

mdadm /dev/md0 --fail /dev/sdc1 # cause the array to rebuild to sda1+sdb1
# now get sdc1 as the spare
mdadm /dev/md0 --remove /dev/sdc1 
mdadm /dev/md0 --add /dev/sdc1

2013/01/25

And now for something silly

I've mentioned Gunilla before. Here is a small Perl program, based on code by Yaakov.

Usage :

set-message
Sets the message on default printer to "Insert Coin"
set-message something
Sets the message on default printer to "something"
set-message 10.0.0.12 "Hello World"
Sets the message on printer at 10.0.0.12 to "Hello World"

I made my life harder (of course) by supporting \n. To do this, the program needs to know the width of your display ($WIDTH). Adding something like ~/bin/gunilla $(date +%A\\n%Y/%m/%d) to a crontab might be useful.

#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket;

# Configuration:
my $WIDTH = 16;
my $peeraddr = 'gunilla';

my $rdymsg;
if( @ARGV == 0 ) {
    $rdymsg = 'Insert Coin';
}
elsif( @ARGV == 1 ) {
    $rdymsg = $ARGV[0];
}
elsif( @ARGV == 2 ) {
    ( $peeraddr, $rdymsg ) = @ARGV;
}
else {
    die "usage: $0 [] [\"\"]\n";
}
 
$rdymsg =~ s{^(.*)(\n|\\n)}{newline($1)}e;

my $socket = IO::Socket::INET->new(
        PeerAddr  => $peeraddr,
        PeerPort  => "9100",   
        Proto     => "tcp",    
        Type      => SOCK_STREAM
    ) or die "Could not create socket: $!";

my $data = <<EOJ;
\e%-12345X\@PJL JOB
\@PJL RDYMSG DISPLAY="$rdymsg"
\@PJL EOJ
\e%-12345X
EOJ
   
print $socket $data;

sub newline
{
    my( $text ) = @_;
    my $l = $WIDTH - length $text;
    $l = 1 if $l < 1;
    return $text. ( ' ' x $l );   
}

2012/12/19

Z8NA and lm_sensors, again

So I was setting up another Z8NA and wanted to get sensors working. After running around in circles, I simply installed from source and now it Just Works. Which is so much better, compared to last times results. BTW, I also install lm-sensors 3.3.4 by hand from source and got a z8na.conf from here.

cd ~/work/sys
wget http://khali.linux-fr.org/devel/lm-sensors/config/sensors3-Asus-Z8NA-D6.conf 
sudo cp sensors3-Asus-Z8NA-D6.conf /etc/sensors.d/z8na.conf
wget http://dl.lm-sensors.org/lm-sensors/releases/lm_sensors-3.3.4.tar.bz2
tar jxvf lm_sensors-3.3.4.tar.bz2
cd lm_sensors-3.3.4
make
sudo make install
sudo sensors-detect
sudo sensors -s
sudo sensors

For what its worth, kmod-w83795 RPMs are available in my repo.

2012/12/02

Don't write a program that does $X

A much better idea is to write a library that does $X, then write a front end program that uses that library. Your design will be better. Your program will be more flexible. Code reuse is much easier.

2012/11/29

Introverts

So I just stumbled across a video about introverts and thought I'd share it.

2012/11/18

Creating a DVD

Creating a DVD is easy but also harder then it needs to be. I wish I could just say "I have an NTSC TV. I have an .avi over there. Make it so." But alas there are all sorts of fiddly bits that need dealing with. So I need a GUI front end that understands the fiddly bits. But installing on CentOS one can get complicated.

First you need CentOS 6.

Then you need ffmpeg 0.7, available from the NauLinux school repo. You might already have ffmpeg 0.6.5 installed, in which case you'll need rpm -e ffmpeg-libpostproc --nodeps before doing yum --enablerepo=naulinux-school install ffmpeg. (If you skip this step, you end up with an error that looks like Unrecognized option 'vf'. Or at least you will if can find stderr, which might be in ~/.xsession-errors).

Finally you install devede, which is written in Python but is surprisingly non-fail. Linux tech has a repo. Set up that repo, then run yum --enablerepo=linuxtech-testing --enablerepo=rpmforge install devede.

2012/11/12

Vixie is a smart guy

I found out something interesting the other day. A crontab entry has a DOW (day of week) column and a day of month (DOM) column. Because I'm a bad sysadmin, I'd never read the full manpage and assumed that if you specified both your entry would be run once every 7 or 14 years. I also suffer from NIH, so I'm writing a cron replacement in pure-perl that includes all the stuff I think a cron should have, like watching a directory for new files. So I finally read the full man page. And it turns out that Vixie was a smart guy. Having an cron job that runs every 7 or 14 years isn't useful so the DOW and DOM columns don't affect each other.

I other words

0 0 1 * 0 do-something
is in fact the equivalent of
0 0 1 * * do-something
0 0 * * 0 do-something
which is so much more useful.

This is another formulation of the "don't allow the user to do stupid things" principle I talked about a while back.