Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, August 20, 2012

Debian Squeeze Installation on HP Gen8 Servers

Update: Thanks to an anonymous commenter I can confirm that with the release of Debian Squeeze 6.0.7, released 2013-02-27, the Debian Installer package uses a back ported version of hpsa to detect controllers not supported by cciss.  The remainder of this post is left for historical reference.

TL;DR Build the hpsa Driver From Source and Deploy in D-I

Symptom:
Can't Detect CD-ROM and/or RAID Disks on HP Gen8 Hardware

My team was attempting to install Debian GNU/Linux 6.0.5 (squeeze) on a brand new HP DL360 Gen8 server with a P420 RAID controller and much to our chagrin it couldn't even detect the CD-ROM drive let alone the RAID sets.

Solution:
Build hpsa.ko From Source

Point your favorite browser over here and grab the 3.0.0-8 (or newer YMMV) release and make sure you have bzip2 installed with ye olde apt-get install bzip2.  You'll need that for the next step.  I've assumed you downloaded the driver into the ~/Downloads directory.

I prepare the directory:
 $ mkdir ~/src
 $ cd ~/src
 $ tar -xjf ~/Downloads/hpsa-3.0.0-8.tar.bz2
 $ cd hpsa/drivers/scsi

To build the hpsa driver you need to edit the hpsa_kernel_compat.h file and remove the comment block corresponding to the OS you wish to build the driver for.  There's just one little problem; there's no block for Debian GNU/Linux.  Fear NOT!  The kernel that ships with Debian 6 is a 2.6.32 kernel.  This is the same basic kernel as shipped with SUSE Linux Enterprise Server 11 SP1.  So just uncomment the following line:
 #define SLES11sp1

If you've got gcc installed and the linux-headers package you can just save the hpsa_kernel_compat.h file and type make.  This will build the hpsa.ko file that you so desperately need.  Now copy that file onto some removable media and go attach it to your Gen8 server.

Installing hpsa.ko During Installation

Now go ahead and boot any of the Debian 6 installation media(netinst.iso, businesscard.iso, cd1.iso or dvd1.iso).  Once d-i is loaded you will be greeted by the message that the CD-ROM device couldn't be detected.  This is where the new driver comes into play.

Switch over to the second console with ALT+F2, press enter and now insert your removable media if you haven't already.  I'm going to use the device name of usbdevice in place of the likely /dev/sda1 or /dev/sdb1 that your removable disk will be recognized as.

Perform the following incantation:

 $ mkdir /mnt/usb
 $ mount /dev/usbdevice /mnt/usb
 $ cp /mnt/usb/hpsa.ko /lib/modules/$(uname -r)/kernel/drivers/scsi
 $ depmod -a
 $ modprobe hpsa

To confirm you see the disks, simply use the dmesg command.  You should now have access to all the devices connected to your HP Gen8 server.  This has only been tested with the P420 controller.  It's possible that your Gen8 may have a different controller.  If so these instructions are worth a shot if you need to access the controller using the hpsa driver.


Switch back over to the d-i terminal, ALT+F1, and detect the CD-ROM drive again.  If all went well you can begin installing Debian GNU/Linux 6.0.X (squeeze) on your shiny new server.

Happy Hacking!

Sunday, January 1, 2012

Haskell Platform in OpenSUSE 12.1

OpenSUSE does not ship with any support for Haskell in it's main package repositories. You can however add them using the OpenSUSE Build Service or OBS.

The best I can tell there is an existing group working on Haskell packaging for OpenSUSE. Search for Haskell on the OBS site and you'll likely run across the repository devel:languages:haskell. The first thing I noticed about this project is that there aren't any builds for OpenSUSE 12.1. After some hunting I ran across the sub-projects and found the 2010.2 haskell-platform available for 12.1. Huzzzah!

A quick little recipe like the following allowed me to add this repository:

$ sudo zypper ar http://download.opensuse.org/repositories/devel:/languages:/haskell:/platform-2010.2/openSUSE_12.1/devel\:languages\:haskell\:platform-2010.2.repo
$ sudo zypper refresh

Make sure you accept the key from the new repository so you can install signed packages and check their signatures correctly.

Now to install the 2010.2 haskell-platform for OpenSUSE 12.1 you just need to install all the packages from the new repository in zypper.

sudo zypper install --from devel_languages_haskell_platform-2010.2 '*'


By using --from in the zypper command line it will only select packages from the specified repository, but will use all configured repositories to do dependency lookup.

After requesting the install via zypper you should get a screen like the following:

The following NEW packages are going to be installed:
alex alex-doc build-compare cabal2spec cabal-install ghc ghc-cgi ghc-cgi-devel ghc-cgi-prof ghc-dataenc
ghc-dataenc-devel ghc-dataenc-prof ghc-deepseq ghc-deepseq-devel ghc-deepseq-prof ghc-doc ghc-fgl
ghc-fgl-devel ghc-fgl-prof ghc-GLUT ghc-GLUT-devel ghc-GLUT-prof ghc-haskell-src ghc-haskell-src-devel
ghc-haskell-src-prof ghc-hscolour ghc-hscolour-devel ghc-hscolour-prof ghc-hslogger ghc-hslogger-devel
ghc-hslogger-prof ghc-html ghc-html-devel ghc-html-prof ghc-HTTP ghc-HTTP-devel ghc-HTTP-prof ghc-libs
ghc-mtl ghc-mtl-devel ghc-mtl-prof ghc-network ghc-network-devel ghc-network-prof ghc-OpenGL
ghc-OpenGL-devel ghc-OpenGL-prof ghc-parallel ghc-parallel-devel ghc-parallel-prof ghc-parsec
ghc-parsec-devel ghc-parsec-prof ghc-prof ghc-QuickCheck ghc-QuickCheck-devel ghc-QuickCheck-prof
ghc-regex-base ghc-regex-base-devel ghc-regex-base-prof ghc-regex-compat ghc-regex-compat-devel
ghc-regex-compat-prof ghc-regex-posix ghc-regex-posix-devel ghc-regex-posix-prof ghc-rpm-macros ghc-stm
ghc-stm-devel ghc-stm-prof ghc-utf8-string ghc-utf8-string-devel ghc-utf8-string-prof ghc-xhtml
ghc-xhtml-devel ghc-xhtml-prof ghc-zlib ghc-zlib-devel ghc-zlib-prof glibc-devel gmp-devel happy happy-doc
hscolour libmp3 linux-glibc-devel zlib-devel

87 new packages to install.
Overall download size: 84.4 MiB. After the operation, additional 858.9 MiB will be used.


Answer yes to the prompt and, depending on your internet speed, you should have a haskell platform to kick around in a few minutes.

Hope this helps someone... The packaging for haskell in OpenSUSE is pretty bad. Debian based distros do it a little bit better by providing a haskell-platform virtual package that has all the componenets a dependencies. Since the packaging in OpenSUSE is done via the OBS and not in the main repositories this isn't likely to get better.

Also as of this writing there are no haskell-platform releases newer than 2010.2 available on the OBS. Due to the quick development of ghc, this can be limiting on the Haskell developer who needs access to features like Data Parallel Haskell or Safe Haskell systems. For users on OpenSUSE that want these features, I encourage you to install the above platform and immediately go build ghc from source code, use the instructions here.

Happy Haskelling!

Saturday, December 31, 2011

FFI in Haskell, How to Call Impure C Functions Without Pointers

I started off writing this little parallel port toy program in the Haskell programming language. It didn't seem too ambitious and I knew how to implement this directly in C so it seemed like a good project to try.

The first thing I needed to do was wrap up a few C functions to get inputs and outputs from the parallel ports. These three functions in linux are inb(2), outb(2), iopl(2) and ioperms(2). I opted to wrap up only inb, outb and iopl.

These functions are defined by sys/io.h on Linux. They are defined as static functions so I need to wrap them up in a small C file to create an object file with symbols for haskell to use them easily. Here's the wrapper code that places these functions in the hs_ namespace.
/* Copyright 2011 Zac Slade and released under the GNU Public License version 2 or later */
#include <sys/io.h>

int hs_iopl(int perm)
{
return iopl(perm);
}

unsigned char hs_inb(unsigned short int port)
{
return inb(port);
}

void hs_outb(unsigned char value, unsigned short int port)
{
outb(value,port);
}


I found a lot of good Haskell Foreign Function Interface(FFI) intruductions, but they all showed something more complex than what I was using. Or they wrapped up functions like sin(3) that pretends to have no side effects like pure functions in Haskell.

I ended up making the functions map to c_inb, c_outb and c_iopl to make it easier on me to know when I was using a C function wrapped up by Haskell. Here's how I defined those three functions using the boiler plate code required by the Haskell FFI.

{-# LANGUAGE ForeignFunctionInterface -}
{- Copyright 2011 Zac Slade and licensed under the GNU Public License version 2 or later -}
module ParaPortLinuxIO where
import Foreign.C
import Data.Bits

-- This file implements a wrapper interface for inb/outb and iopl all found in sys/io.h on Linux
-- Due to the nature of the include file and the definition of these symbols a small C wrapper
-- was needed and the functions were placed into the hs_ namespace.

-- Type aliases for use with this module
type CByte = CUChar
type Port = CUShort
type SomeBits = [Int]
type IOPorts = [Port]

-- int iopl(int perm)
foreign import ccall unsafe "hs_iopl"
c_iopl :: CInt -> IO CInt

-- unsigned char inb(unsigned short int port)
foreign import ccall unsafe "hs_inb"
c_inb :: Port -> IO CByte

-- void outb(unsigned char value, unsigned short int port)
foreign import ccall "hs_outb"
c_outb :: CByte -> Port -> IO ()


These functions have no illusions about being pure. As you might have noticed if you are already a Haskeller the functions all operate in the IO Monad to inform the programmer that these should not under any circumstances be treated like pure functions. Also in the above definition we see that both c_iopl and c_inb are marked as unsafe as well. This conveys even more information to the programmer alerting them to the fact that these functions read values from the real world and require state to be carried along with the values.

As you can see above it really doesn't take much code to actually wrap up C library function (even functions defined as static functions). From the above two snippets you can begin using inb(2), outb(2) and iopl(2) in your own Haskell programs.

Happy Haskell Hacking!

Saturday, December 24, 2011

Haskell and Linux Parallel Port I/O

I've been working for a day or so on a Haskell program to perform generic I/O on parallel ports under Linux. As I'm still very new to Haskell I needed a real world problem to solve. This problem was one that is very straightforward in C so I took the plunge and started.

You can grab the code at gitorious.

I/O is not Haskell's strong suite from a newbie's perspective. It's not difficult however. All Haskell programs live in the IO monad. This has some good consequences. You then have access to the do notation which looks terribly imperative to me. That's okay as I know how to write this in C and the do notation makes it easy to follow that road until functional solutions appear.

Thoughts on Haskell So Far...
Using the language is a blast! It's syntax is very terse and the expressiveness is immense. You can write haskell programs on a sheet of paper with a marker and have your friends run them in the living room without a computer... Maybe that's just me(bonus he type checking too). Haskell is a HUGE language with a very extensive library. Part of the fun of Haskell is in the learning and you can stay pretty busy just learning the fundamentals. The good news is that as you learn the fundamentals you can quickly begin taking advantage of the libraries to make programs that do very complicated things with just a few type declarations and a handful of generic functions.

Just to show off the flexibility of Haskell, if you use GHC you can compile your programs to native byte code, llvm byte code, run them interactively or use them like shell scripts using the runhaskell tool.