December 2002 Archives

Linux, a UPS, and a cellphone

| | Comments (1)
I have a Back UPS 500 CS using a usb cable (model 940-0127A). It provides about 10 minutes of battery power to my router, switch, wap, cable modem, and server. It's connected via usb to the server.

I used apcupsd version apcupsd 3.10.3. Actually I installed the debian package which is old enough to not support usb. Then I hand copied my compiled apctest, apcaccess, apcupsd, man pages, and created a new /etc/apcdupsd/apcupsd.conf over writing the debian ones. The debian/apcupsd frame work works fine with the new binaries and they now support usb. You'll need the usb-core, usb-[ohci/uhci], hid, and input modules available to the kernel. There's a page on the apcupsd site that describes compiling for usb.

Like I said the framework pretty much works out of the box. Here's a copy of my /etc/apcupsd/apcupsd.conf file


UPSCABLE usb
UPSTYPE usb
DEVICE /dev/usb/hid/hiddev[0-9]
LOCKFILE /var/lock
BATTERYLEVEL 5
MINUTES 5
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 0.0.0.0
NISPORT 6543
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0

I also edited the /etc/apcupsd/onbattery /etc/apcupsd/mainsback files to change the email from root to my cellphone.


#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
#
SYSADMIN=cell@provider.com
MAIL="/usr/bin/mail"

HOSTNAME=`hostname`
MSG="$HOSTNAME Power Failure !!!"
#
(
   echo "$MSG"
   echo " "
   /sbin/apcaccess status
) | $MAIL -s "$MSG" $SYSADMIN
exit 0

#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the
# UPS goes back on to the mains after a power failure.
# We send an email message to root to notify him.
#
SYSADMIN=cell@provider.com
MAIL="/usr/bin/mail"

HOSTNAME=`hostname`
MSG="$HOSTNAME Power has returned"
#
(
   echo "$MSG"
   echo " "
   /sbin/apcaccess status
) | $MAIL -s "$MSG" $SYSADMIN
exit 0

So basically if the power goes out. I get a page on my cellphone. The system will shutdown if the battery gets to 5% or the ups' projected time remaining is 5 minutes (whichever comes first). If the power returns before either of those conditions then I get a page on my cellphone.

Normally the last thing the system should do when shutting down becuase of low battery power is turn off the UPS! This cuts power to the computer. This way the "Always On" setting in your CMOS will return the computer turn on your computer when the power's back. But the usb code for shuting down the ups is broken in apcupsd. They are working on it.

Consequently there is a short window of time that if the power were to return my computer would still be powered on but shutdown. It would then require reboot by hand.

But if the power stays off long enough for the battery in the ups to run out then the ups will turn off. Cutting power to my equipment. When the power returns the equipment and server will turn on.

my ups' battery lasts a lot longer without a server on it. So I either want a short power outage (less than 10 minutes) or a long one (more than 5 minutes). Becuase if the power returns during last 5 minutes of battery life then my computer stays shutdown

Also, the UPS only polls the usb every so often. So after module load at boot time a fast computer can start apcupsd before the ups has polled and an hid device is registered with the kernel. This will cause your computer startup and hardlock (use alt-prtscr tricks to reboot). I added a 10 second pause right before apcupsd in its init script to get around this.

IDE Raid, ServerWorks OSB4 chip: Stable and Fast?

| | Comments (7)
Update: 02.12.27: DON'T DO IT!. I was getting data corruption when copying mp3's. I tried it without raid and lvm. The only thing that fixed it was to skip the hdparm that changed the hardrive modes. I'm now back to a non-dma mode. It's slow as hell, but *very* stable. The main goal here is a large safe storage area. So, the slow down is not a big deal, but disappointing.

My new raid setup is still shaking out gremlins for me to thonk with a stick. The raid & lvm components of the 2.4 kernel seem pretty reliable, the serverworks OSB4 chipset drivers are just plain scary. Whether bugs in the chip or the driver, I don't know, but UDMA doesn't work right, but without it performance suffers. Here are my notes and work arounds to getting good dma performance on IDE raid using ServerWorks ide controllers.

Init script

I can't figure out how to set the drives to MDMA2(multiword DMA mode2) from boot. hdparm -K1 doesn't work, nor does idebus=34, and antyhing else i've tried results in UDMA33mode which leads to hard locks. So, I'm using a startup script. The kernel enables the raid arrays automagically (before init). So we have to bring them down before changing hdparms. It runs in rcS.d right after modules, but before the lvm. So here's my boot script.


---------------------------------------------------------------------
#!/bin/bash

# this script is an unfortunate necessity becuase of problem with the
# osb4 chipset and linux. UDMA33 locks the computer. The best transfer
# mode that isn't UDMA33 is MDM2. Still very fast. I can't figure out
# how to set it at the lilo prompt and the -K1 switch to hdparm doesn't
# remember settings across reboot. So here is a custom hand job.
# -X34 is MDMA2 (32 plus the mode)
# -d1 DMA on

# if the raid1 arrays are up then and syncing then hdparms can be
destructive
# bring them down first
echo "JIM: stopping ide raid arrays"
/sbin/raidstop /dev/md1
/sbin/raidstop /dev/md2

# do the hdparm magic. I love this tool!
echo "JIM: setting ide drives to MDMA2"
/sbin/hdparm -X34 -d1 /dev/hd{a,b,c,d}

# bring the arrays back up. They'll sync faster and be ready for lvm
echo "JIM: restarting ide raid arrays"
/sbin/raidstart /dev/md1
/sbin/raidstart /dev/md2
---------------------------------------------------------------------

Performance for raid syncing

"Normal Mode" (not sure what to call it, PIO4?). I get pitiful performance about 1000K/sec with 50-70% CPU(s) utilization. I/O starvation, but raidsyncing very reliable.

UDMA33 (UDMA2) Mode I got about 8000K/sec(!) at 30% cpu. But who cares if the system locks in 30 seconds.

MWDMA2 (MDMA2) Mode I get about 5000K/sec. But only like 5% cpu utilized! Very reliable! The cost to benefit winner!


styx:~# hdparm -tT /dev/hd{a,b,c,d}

/dev/hda:
 Timing buffer-cache reads:   128 MB in  0.58 seconds =220.69 MB/sec
 Timing buffered disk reads:  64 MB in  5.45 seconds = 11.74 MB/sec

/dev/hdb:
 Timing buffer-cache reads:   128 MB in  0.59 seconds =216.95 MB/sec
 Timing buffered disk reads:  64 MB in  4.36 seconds = 14.68 MB/sec

/dev/hdc:
 Timing buffer-cache reads:   128 MB in  0.59 seconds =216.95 MB/sec
 Timing buffered disk reads:  64 MB in  5.48 seconds = 11.68 MB/sec

/dev/hdd:
 Timing buffer-cache reads:   128 MB in  0.58 seconds =220.69 MB/sec
 Timing buffered disk reads:  64 MB in  4.55 seconds = 14.07 MB/sec

styx:~# hdparm -i /dev/hd{a,b,c,d}

/dev/hda:

 Model=SAMSUNG SV1204H, FwRev=RK100-12, SerialNo=0504J1ETB06345
 Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
 RawCHS=16383/16/63, TrkSize=34902, SectSize=554, ECCbytes=4
 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=234493056
 IORDY=yes, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes: pio0 pio1 pio2 pio3 pio4 
 DMA modes: mdma0 mdma1 *mdma2 udma0 udma1 udma2 udma3 udma4 udma5 
 AdvancedPM=no WriteCache=enabled
 Drive Supports : fastATA-1 ATA-2 ATA-3 ATA-4 ATA-5 ATA-6 


/dev/hdb:

 Model=Maxtor 4W100H6, FwRev=AAH01310, SerialNo=W6H265ZC
 Config={ Fixed }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=57
 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=195711264
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes: pio0 pio1 pio2 pio3 pio4 
 DMA modes: mdma0 mdma1 *mdma2 udma0 udma1 udma2 udma3 udma4 udma5 
 AdvancedPM=yes: disabled (255) WriteCache=enabled
 Drive Supports : ATA/ATAPI-6 T13 1410D revision 0 : ATA-1 ATA-2 ATA-3 ATA-4 ATA-5 ATA-6 


/dev/hdc:

 Model=SAMSUNG SV1204H, FwRev=RK100-12, SerialNo=0504J1ETB01647
 Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
 RawCHS=16383/16/63, TrkSize=34902, SectSize=554, ECCbytes=4
 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=234493056
 IORDY=yes, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes: pio0 pio1 pio2 pio3 pio4 
 DMA modes: mdma0 mdma1 *mdma2 udma0 udma1 udma2 
 AdvancedPM=no WriteCache=enabled
 Drive Supports : fastATA-1 ATA-2 ATA-3 ATA-4 ATA-5 ATA-6 


/dev/hdd:

 Model=WDC WD1000BB-00CCB0, FwRev=22.04A22, SerialNo=WD-WMA9P1031305
 Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq }
 RawCHS=16383/16/63, TrkSize=57600, SectSize=600, ECCbytes=40
 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=195371568
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes: pio0 pio1 pio2 pio3 pio4 
 DMA modes: mdma0 mdma1 *mdma2 udma0 udma1 udma2 udma3 udma4 udma5 
 AdvancedPM=no WriteCache=enabled
 Drive Supports : Reserved : ATA-1 ATA-2 ATA-3 ATA-4 ATA-5 

Notes

I was getting this error with UDMA33. The system hardlocked
"Serverwrosk osb4 in impossible state. disable udma or if you are using seagate then try switching disk types on this controller. Please report this event to osb4-bug@ide.cabal.tm."

alan cox says to go to (MWDMA2) because of these hardlocks

people bitching and disussing 4 bit shift problem

look under dma mode for bios setting MWDMA2. I can't use b/c bios ide disabled to facilitate scsi boot

from the hdparm man page
"[...]where -X34 is used to select multiword DMA mode2 transfers[...]"
hdparm -X34 -d1 /dev/hd{a,b,c,d}

The Dancing Wu Li Masters: An Overview of the New Physics

|
Book Review of "The Dancing Wu Li Masters" by Gary Zukav: Trip Hippie studies particle physics on acid, applies eastern philosophy, and writes about it while stoned in 1979. Well maybe a little better than that. There are some cosmic plilosophical statements and some interesting diagrams of 1970's neanderthals dealing with 4-d math. People compare it to Zen and the Art of Motorcycle Maintenance, but I think this one is a lot lonelier and less useful. It's a decent survey of the last 200 years of physics.

Weblift

|
New web face! The other one was hot looking. You have to admit it, but it was slow to download over my slow link and even slower to render. Even in not-so-modest computers. So I've gone full circle and brought the theme down a notch. This is my 'reallysimple' theme. That I'll post to geeklog later. I also made some changes to the backend.

Notice the inthemix, definitive, onthepress, and ephemera boxes on the right? Those used to be static HTML blocks that I edited via geeklog's admin panel. Now I just have data tables for those items and some custom PHP functions in lib-custom.php (why doesn lib-common-local.php work?).

I took out all the fixed size fonts in the style sheet. This makes the page more flexible for different display types and makes it obey the zoom rules most browsers seem to support now.

So now to enter new data.

  1. No html just type the data into a form
  2. No static page updates
  3. motion on the web page

It all took about 8 hours, but was worth the change.

Titrax Conduit

|
I spent the weeking building a Palm conduit (for windows) that can synchronize the popular palm program titrax. Once I remembered how to write c-code, undertood the sync manager api, and figured out how the compiler stored enums on the palm I was off and running. It took about three days. At this point the conduit will take the data from the palm and put it in a CSV file for use in excel. I'll clean this up a bit later, but for now you can browse the code in my cvs.

220gigs of RAID1 mp3 storage

|
I've gotten some time recently to spend on working on my home linux box. It rarely happens and is usually some very new concepts for me. One of the things that's been plagueing me recently is safe storage. I mean I have 11,000 mp3's it's about 77 gigs of data. Where does one put all that, and how does one keep it safe?

By using reduntant array of inexpensive disks (RAID). There are 6 different levels of raid. I'm only interested in RAID1 which is mirroring. That means that each disk has an identically sized disk whose data is kept in sync. So there are redundant copies of all your data.

I've spent a good amount of time crafting a linux filesystem. It's debian woody tailored to a linux-from-scratch style but with the tangential focus of a child-of-slackware. It's a good system, but it took a while to setup. It took me a long time (days) to setup and losing it would cost me more days.

So, I'm running from SCSI raid. I ordered two IBM 10,000rpm scsi drives from some pakistanny hardware shop. I decided to use LVD/SCSI3 for speed and reliability. Supposedly scsi disks are made to a higher snuff, and the bus is more tolerant and verbose about hardware failures. So, they are acting as my root partition. Both disks have the linux kernel on their MBR to facilitate easy reboot on disk failure. See my lilo.conf later.

Next is storage. Like I said. I have 77 gigs of MP3's and local household data. I also had about 70 more gigs of other people's mp3s sitting on smaller ide harddisks. The best hard drives you can get reasonably now are about 120gigs. That is to small. So I'm going to combine some disks.

A side note IDE DMA with linux and the supermicro 370de6 seems to be broken. I was getting horrible read errors and geometry miscalculations when I attached devices to my second IDE chain. I farked up bad when I changed the geometry on my drive because of the reports from the second IDE controller that I misinterpreted. I lost all my household data. Thankfully most of the tunage has been duped by other people and is on me and Olivia's laptops. Otherwise I'd be crying at the loss of many hours of work.

But after surmounting all the idiosyncracies of ide/scsi on my mother board, booting off raid, and LVM. I've got a system all worked out.

I'm using two samsung 120gig drives as one raid1 storage array. Then I have some old maxtor 100gig drives that I'm using as a second raid1 array. Then I used the 2.4 kernel's built in logical volume management support to combine the two raid1 volumes into one logical volume. That's a total of 220gigs of raid1 space!

To maximize performance, I've put a drive from each raid1 array on an IDE controller. See the diagram. I'll include some of my files below for safe keeping and reference.

/etc/lilo.conf for booting from raid1


lba32
boot = /dev/md0
append="md=0,/dev/sda1,/dev/sdb1"
raid-extra-boot="/dev/sda,/dev/sdb"

disk=/dev/sda bios=0x80
disk=/dev/sdb bios=0x80

image = /2.4.19-raid
  label = linux
  root = /dev/md0

/etc/raidtab sets up the three raid1 disks


# root filesystem
# 9 gig ibm's
raiddev /dev/md0
        raid-level 1
        chunk-size 8
        nr-raid-disks 2
        nr-spare-disks 0
        persistent-superblock 1
        device  /dev/sda1
        raid-disk 0
        device /dev/sdb1
        raid-disk 1

# first raid1 pair
# 120 gig samsungs
raiddev /dev/md1
        raid-level 1
        chunk-size 8
        nr-raid-disks 1
        nr-spare-disks 0
        persistent-superblock 1
        device  /dev/hda1
        raid-disk 0
        device /dev/hdc1
        raid-disk 1

# second raid1 pair
# 100gig maxtors
raiddev /dev/md2
        raid-level 1
        chunk-size 8
        nr-raid-disks 2
        nr-spare-disks 0
        persistent-superblock 1
        device  /dev/hdb1
        raid-disk 0
        device /dev/hdd1
        raid-disk 1

/etc/fstab shows my VG & LV names


# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>               <dump>  <pass>
/dev/md0  /       reiserfs      defaults        0       1
#/dev/vg0/lv0       /mnt/family      reiserfs        defaults        0       0
proc      /proc   proc  defaults                0       0
/dev/fd0  /floppy    auto       user,noauto             0       0
/dev/cdrom      /cdrom          iso9660 ro,user,noauto          0 0
/tmp/swap  swap  swap  defaults  0  0

Anyway. That's how I'm doing it. The samsung disks are only $120 dollars. SO for $480 you could have 240 gigs of reduntant IDE storage. I know that scsi is better, but I don't have the $2k that it would take to build comparable space in scsi.