http://blogs.sun.com/paulie/date/20091125 Wednesday November 25, 2009

Latex for OpenSolaris

Ever wanted to experiment with latex to write a paper or redesign your resume, but unsure how to install a latex package or compose a latex document? I'll try to explain it simply using OpenSolaris.

Install Latex

d its dependencies from our friends at sunfreeware.com
cd /tmp
wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/libgcc-3.3-sol10-intel-local.gz
wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/libiconv-1.11-sol10-x86-local.gz
wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/ncurses-5.6-sol10-x86-local.gz
wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/tetex-3.0-sol10-x86-local.gz
gzip -d *.gz
  • Install the packages
  • pfexec pkgadd -d libgcc-3.3-sol10-intel-local
    pfexec pkgadd -d ncurses-5.6-sol10-x86-local
    pfexec pkgadd -d libiconv-1.11-sol10-x86-local
    pfexec pkgadd -d tetex-3.0-sol10-x86-local
    

    Play with Latex
    For my simple uses of latex, I use two binaries to compose my documents: latex and dvipdf. Latex requires a tex file to generate a document. For this example, I will use my favorite resume template created by David Grant.
    cd /tmp
    wget http://www.davidgrant.ca/sites/www.davidgrant.ca/files/resume.tex.txt
    wget http://www.davidgrant.ca/sites/www.davidgrant.ca/files/shading.sty.txt
    mv resume.tex.txt resume.tex
    mv shading.sty.txt shading.sty
    
    Now, let's use the binaries I mentioned earlier to create a pdf file.
    /usr/local/teTeX/bin/i386-pc-solaris2.10/latex resume.tex
    /usr/local/teTeX/bin/i386-pc-solaris2.10/dvipdft resume.dvi
    
    You should find a pdf file in /tmp called resume.pdf. View it with acroread or evince to get an idea of how awesome latex is. I won't go into too much detail on how to create the resume.tex file, but viewing and editing it will you give you a good understanding on its syntax. This is David's resume that is generated: http://www.davidgrant.ca/sites/www.davidgrant.ca/files/resume.pdf.

    Posted by Paul Johnson [Sun] ( November 25, 2009 09:54 AM ) Permalink | Comments[1]
    http://blogs.sun.com/paulie/date/20090929 Tuesday September 29, 2009

    Compiling Alpine on OpenSolaris 2009.06

    For Alpine 2.00, the configure file looks around in the wrong directories for the OpenSSL header files.
    ...
        *-*-solaris*)
          if test -d /usr/sfw/include/openssl ; then
            alpine_SSLDIR="/usr/sfw"
          elif test -d /opt/csw/include/openssl ; then
            alpine_SSLDIR="/opt/csw"
            if test -d /opt/csw/ssl/certs ; then
              alpine_SSLCERTS="/opt/csw/ssl/certs"
            fi
          fi
    ...
    
    Unfortunately, configure never looks for the new location: /usr/include/openssl. Thankfully, there is an easy fix:
    ./configure --with-ssl-include-dir=/usr/include/openssl
    


    Posted by Paul Johnson [Sun] ( September 29, 2009 09:23 AM ) Permalink | Comments[0]
    http://blogs.sun.com/paulie/date/20090520 Wednesday May 20, 2009

    Cannot remove directory: File exists

    If you try to delete a directory over NFS and get an error such as...
    rm: cannot remove directory `asdf/': File exists
    
    ... you will notice that conventional methods won't be good enough to remove it.
    $ chmod -R 777 asdf/
    $ rm -rf asdf/
    $ rm: cannot remove directory `asdf/': File exists
    
    Usually there is a file like .nfs234B inside the directory than can be displayed with ls -la
    $ ls -la
    total 146
    drwxr-xr-x 2 user group    512 2009-05-20 08:51 .
    drwxr-xr-x 3 user group    512 2009-05-19 08:59 ..
    -rwxr-xr-x 1 user group 134888 2009-05-18 12:45 .nfs234B
    
    Removing this file only replaces it with another. There are two solutions: manually delete the file on the NFS server, or (if you don't have that type of access) kill its process.
    $fuser -u asdf/.*
    asdf/.:     9070c(user)
    asdf/..:    28690c(user)   24845c(user)
    asdf/.nfs934B:     9070tm(user)
    
    9070 is the offending process. Kill it with fire.
    $ kill -9 9070
    
    Should be able to remove that directory now.

    Posted by Paul Johnson [Sun] ( May 20, 2009 09:12 AM ) Permalink | Comments[0]
    http://blogs.sun.com/paulie/date/20090105 Monday January 05, 2009

    Testing Network Performance in Solaris

    So you think your wireless link is slow, or your gigabit ethernet card is under performing. How can you tell? Here are two tools I use to test network throughput.

    netio


    Created by Kai Uwe Rommel, it tests by sending and receiving packets of varying sizes and reports throughput in kilobytes per second.

    Installation
  • x86
  • # wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/netio-1.26-sol10-x86-local.gz
    # gzip -d netio-1.26-sol10-x86-local.gz
    # pkgadd -d netio-1.26-sol10-x86-local
    
  • SPARC
  • # wget ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/netio-1.26-sol10-sparc-local.gz
    # gzip -d netio-1.26-sol10-sparc-local.gz
    # pkgadd -d netio-1.26-sol10-sparc-local
    
    Usage
  • Server-side
  • # netio -u -s
    
  • Client-side
  • # netio -u SERVER_IP_ADDRESS
    

    Here are results on a 100Mbps link:
    UDP connection established.
    Packet size  1k bytes:  11913 KByte/s (0%) Tx,  11468 KByte/s (0%) Rx.
    Packet size  2k bytes:  11954 KByte/s (0%) Tx,  11509 KByte/s (0%) Rx.
    Packet size  4k bytes:  12274 KByte/s (0%) Tx,  11687 KByte/s (0%) Rx.
    Packet size  8k bytes:  12284 KByte/s (0%) Tx,  11697 KByte/s (0%) Rx.
    Packet size 16k bytes:  12292 KByte/s (0%) Tx,  11702 KByte/s (0%) Rx.
    Packet size 32k bytes:  12348 KByte/s (0%) Tx,  11714 KByte/s (0%) Rx.
    Done.
    
    Sending and receiving hovered around 11-12MB/s which is on par with 100Mbps.

    netperf


    Created by Rick Jones and discovers the maximum throughput of a link, reporting in megabits per second.

    Installation
    # wget ftp://ftp.netperf.org/netperf/netperf-2.4.4.tar.gz
    # tar zxvf netperf-2.4.4.tar.gz
    # cd netperf-2.4.4
    # export CFLAGS="-lsocket -lnsl -lkstat"
    # ./configure
    # make
    # make install
    
    Usage
  • Server-side
  • # netserver
    
  • Client-side
  • # netperf -H SERVER_IP_ADDRESS
    

    Here are results on a 100Mbps link:
    Recv   Send    Send                          
    Socket Socket  Message  Elapsed              
    Size   Size    Size     Time     Throughput  
    bytes  bytes   bytes    secs.    10^6bits/sec  
    
     49152  49152  49152    10.00      94.88
    

    94.88 Mbps is the final result, not bad.

    Posted by Paul Johnson [Sun] ( January 05, 2009 01:35 PM ) Permalink | Comments[2]
    http://blogs.sun.com/paulie/date/20081218 Thursday December 18, 2008

    OpenSolaris Installation Checklist

    When I reinstall OpenSolaris, I have a small checklist of things I execute to create a familiar environment between my systems. This might be helpful to others.


  • Allow NIS user (really any user) access to the root role (lets them access packagemanager)
  • # vi /etc/user_attr
    Append to end of file:
    USERNAME::::profiles=Primary Administrator;roles=root
    

  • Enable NTP
  • # vi /etc/inet/ntp.conf
    
    server 0.pool.ntp.org
    server 1.pool.ntp.org
    server 2.pool.ntp.org
    
    # svcadm enable ntp
    # svcadm restart ntp
    

  • Install OpenOffice
  • # pkg install openoffice
    

  • Install gconf-editor
  • # pkg install SUNWgnome-config-editor
    

  • Disable Audible Alert Sound
  • I hate the audible alert sound. If you wear headphones while you're computin' and use tab-completion excessively on your shell or have a mail client that beeps on every new message, you know what I'm talking about.
    However, when I click on System->Preferences->Sound, the Play Alert Sound option is grayed out. Here is the solution:
    $ gconf-editor
    /apps/metacity/general/ and decheck audible bell
    

  • Allow root user to login directly
  • Don't do this.
    # rolemod -K type=normal root
    


    Posted by Paul Johnson [Sun] ( December 18, 2008 01:13 PM ) Permalink | Comments[0]
    http://blogs.sun.com/paulie/date/20081211 Thursday December 11, 2008

    2008.11 on the Asus EEE 701

    Things that have been fixed/work out of the box since 2008.05

  • Keyboard/mouse now fully functional throughout the install
  • Sound works by default
  • Webcam *should* work by default (my model doesn't have one so I can't test)
  • Atheros wi-fi still requires an additional download
    $ wget http://opensolaris.org/os/community/laptop/downloads/ath-x86-ar5007eg-pkg.tar.gz
    $ tar zxvf ath-x86-ar5007eg-pkg.tar.gz
    # pkgadd -d SUNWatheros
    # init 6
    
  • Attansic L1/L2 ethernet is now functional thanks to our good friend Masayuki Murayama
    $ wget http://homepage2.nifty.com/mrym3/taiyodo/atge-2.6.2.tar.gz
    $ tar zxvf atge-2.6.2.tar.gz
    $ cd atge-2.6.2
    # make install
    # ./adddrv.sh
    # devfsadm -i atge0
    # ifconfig atge0 plumb
    

    Asus EEE 701 vs. 30 inch Dell Monitor
    800x480 vs. 2560x1600 resolution
    Longs Peak in the background


    Posted by Paul Johnson [Sun] ( December 11, 2008 12:52 PM ) Permalink | Comments[0]
  • http://blogs.sun.com/paulie/date/20080822 Friday August 22, 2008

    Odd Perl Hacks

    For my senior project in my last two semesters at the University of Colorado myself and two others were tasked to create a web-based scheduling system for the Conference on World Affairs. This seemed like a trivial task, except we were lacking some serious tools. For one, we had no access to a database (no MySQL, Oracle, etc.) and the only language we could could use was Perl 5.6 with no modules. This was due to the fact that the system had to reside on the main university server, an old Solaris 8 V880, which is shared by most of the departments across the campus. Consequently, we had to build a database from scratch using text files while maintaining relational database concepts such as primary/foreign key constraints, atomic writes, and encryption. It also needed to support multiple years for each new conference, up to 200 panels a year, up to 100 panelists, along with coordinators and moderators for each panel. A conflict detection mechanism was necessary to discover problems with the schedule (one person in two places at the same time sort of thing). Additionally, a user account system was needed to allow only authorized people to use the scheduler.

    It was an immensly complicated project that took about 10k lines of Perl to accomplish, which in the mind of ESR was probably way too much. It did, however, give me great insight onto why existing tools are so important along with a deep appreciation of modern relational databases. And our team even won an award for the project. Along the way, I also learned and created some neat Perl hacks to solve the problems with writing (and rewriting) a development library. Let me show you some tricks.


    Round Up A Number

    With the large amount of panels and panelists (exceeding 100), it was a good idea to create a paging scheme when searching through all of them to prevent really long web pages. So let's say you have 193 panels and you want 10 panels displayed per page. The obvious answer is to divide the ten, but you end up with a decimal of 19.3 pages when you actually need 20 pages to display everything. This function will round it up for you.
    sub roundUp()
    {
        # Calculates number of pages needed when a decimal place screws things up
    
        ($n)=@_;
        return(($n == int($n)) ? $n : int($n + 1))
    }
    

    Isolate Calendar Week

    The Conference on World Affairs is always held the second week of April. Anytime a user wants to create a new conference, the system should be able to calculate the exact date when supplied a day of the week (M-F). This function takes care of it with UNIX cal.
    sub convertDaytoDate()
    {
        # Used to determine conference day of week without need
        # of unnecessary db storage.
    
        ($day,$year)=@_;
    
        # Isolate April using UNIX cal
        $cal=`cal 4 $year`;
        @cal = split("\n",$cal);
    
        # Grab the 2nd week of April
        $interest = $cal[3];
        $interest =~ s/(^....)//;
        $interest =~ s/\ \ /\ /g;
        @days = split("\ ",$interest);
    
        if ($day =~ /Monday/) { $DD = $days[0]; }
        if ($day =~ /Tuesday/) { $DD = $days[1]; }
        if ($day =~ /Wednesday/) { $DD = $days[2]; }
        if ($day =~ /Thursday/) { $DD = $days[3]; }
        if ($day =~ /Friday/) { $DD = $days[4]; }
    
        return("April $DD, $year");
    }
    

    Convert Non-ASCII Characters

    Some panelists were foreign and had characters in their name that were outside of ASCII, such as the umlaut ö or accent á. When inputted into the text database, things went well. However, when read back into a web browser, a question mark or exclamation point was displayed instead. The trick is to convert these characters into XML form by isolating its ASCII value with ord() and playing with those greater than 127.
    foreach $entry (@cwaparttable)
    {
        chomp($entry);
        $entry =~ s/(.)/checkForNonASCII($1)/eg;
    }
    
    sub checkForNonASCII()
    {
        # Eliminates foreign letters, character by character
    
        if (ord($_[0]) < 128){
            # ASCII
            return $_[0];
        } else {
            # Non-ASCII
            return sprintf('&#x%04X;', ord($_[0]));
        }
    }
    


    Posted by Paul Johnson [Sun] ( August 22, 2008 09:48 AM ) Permalink | Comments[2]
    http://blogs.sun.com/paulie/date/20080728 Monday July 28, 2008

    APC UPS on OpenSolaris (apcupsd)

    One of the best consumer UPS manufacturer on the market is APC. They make great products that can interface nicely with any UNIX-based system, whether it be Linux, BSD, or Solaris. Using their daemon (apcupsd), you can download the source and create a nice link-up with your UPS so you can be notified anytime your power goes out (or if you accidentally unplug it)

    My home model is the APC ES550 which is USB-based and has a weird USB->RJ45 cable to link a computer with the UPS. Let me explain how to get this running with OpenSolaris with at least this model.

    First you will need the latest apcupsd tarball located on Source Forge. Then, follow some standard compiling directions:

        $ tar zxvf apcupsd-3.14.4.tar.gz && cd apcupsd-3.14.4
        $ ./configure --enable-usb
        $ make
        # make install
    
    If your model is USB-based, you need the enable-usb flag with the configure script. Now when you make, however, it will most likely fail with the following error.
    libusb.h:9:34: /usr/sfw/include/usb.h: No such file or directory
    ... lots of errors ...
    

    'make' fails on OpenSolaris because by default it is missing a usb.h header file located in /usr/sfw/include. This can be retrieved by running this command inside that directory as root.

        # wget http://src.opensolaris.org/source/raw/sfw/usr/src/lib/libusb/inc/usb.h
    
    Binaries are stored inside /etc/opt/apcupsd/sbin.

    The file apcupsd.conf is needed to configure this USB device. Two lines that say the following must be included in this file.

    UPSCABLE usb
    UPSTYPE usb
    
    Delete any other UPSCABLE/UPSTYPE lines. The apcupsd.conf file documents other types of APC UPS devices as well, usually those that rely on serial as opposed to usb.

    Now, you should be able to run the daemon and you can verify that it will notify you by simply pulling the plug on the UPS. If you modify your root alias in /etc/mail/aliases the UPS will send you an e-mail when the power goes out. This sounds handy if I'm campus and I lose the electricity in my apartment, so I'll have plenty of time to power off my machine remotely.

    Posted by Paul Johnson [Sun] ( July 28, 2008 11:44 AM ) Permalink | Comments[12]

    http://blogs.sun.com/paulie/date/20080725 Friday July 25, 2008

    ZFS NAS with the Intel Atom

    I've been looking to build a network attached storage (NAS) device for some time to store all my music, photos, films, etc. in one global location. I had a few specific requirements that were as follows:

  • Supports two disks (2TB RAID mirroring preferable)
  • Supports UPnP server (media sharing)
  • Low power (always on)
  • Bonus points: ZFS, SSH, Samba, etc.

    There are a few ready-to-go NAS solutions available on the market that are compatible with my demands. The Linksys NAS200, at $130, supports two disks with Twonky Media server for UPnP and is low power. The downside is that reviews indicate it being very slow and it comes with no gigabit ethernet. On the high-end side, however, the QNAP TS-209 Pro also comes with the two disk slots, UPnP support, is fast, along with a bunch of extra goodies like samba and an Itunes server. The price tag at $400 makes it a bit too much for a diskless system, so I decided on a different solution... why not build it myself?

    I had a Thermaltake LANBOX Lite Mini-ITX/ATX case lying around along with a 200W power supply, so all I needed to do was find some cheap, low power hardware to support it. Intel recently released a new type of processor called the Atom, which is aimed at bringing x86 into the embedded market. I'm not so sure how successful they will be at this venture, but it fits my needs perfectly. According to their specs, it draws 2W TDP for the 1.6ghz version which is pretty amazing. The power output turns out to be a bit of marketing hype, but considering it is now being used in the ASUS Eee desktop and laptops, it should prove to be a viable candidate. To encourage the hobbyist market, Intel created a combo of motherboard + Atom (BOXD945GCLF) that is available on Newegg for $75. After getting it along with a pair of 1TB drives at $170, I had a workable system shipped to me for under $500.

    My first reaction when I got all the parts is that the Intel board is TINY. I can fit my hand around entire thing. Even in the media center case that I use, it has quite a bit of extra room.

    The LANBOX Lite is fully modular which makes installation much easier. If you have ever built a computer from scratch, then you probably understand how tedious it can be to screw in motherboards, install drives, etc. This case allows you to pull every section out to make installation a breeze. It also comes with a nice silo to install both the terabyte drives.

    The next step is to turn this into a fully functional NAS. After installing FreeBSD 7.0, I wanted to setup both my disks to mirror. Since the BSD family has such a friendly license, ZFS is included in the distribution. And ZFS mirroring makes things incredibly simple to setup.
    [root@bojangles ~]# zpool attach tank ad4s1d ad6s1d
    
    And that's it! Now to ensure that things went as expected.
    [root@bojangles ~]# zpool list
    NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
    tank                    928G   72.9G    855G     7%  ONLINE     -
    [root@bojangles ~]# zpool status
      pool: tank
     state: ONLINE
     scrub: none requested
    config:
    
    	NAME        STATE     READ WRITE CKSUM
    	tank        ONLINE       0     0     0
    	  mirror    ONLINE       0     0     0
    	    ad4s1d  ONLINE       0     0     0
    	    ad6s1d  ONLINE       0     0     0
    
    errors: No known data errors
    
    Now with ports, I can get Samba and Ushare up and running in no time.
    [root@bojangles ~]# cd /usr/ports/net/samba3 && make install clean
    [root@bojangles ~]# cd /usr/ports/net/ushare && make install clean
    
    The final product in my closet in a makeshift cabinet.



    Posted by Paul Johnson [Sun] ( July 25, 2008 08:29 AM ) Permalink | Comments[13]
  • http://blogs.sun.com/paulie/date/20080718 Friday July 18, 2008

    What?

    Hiya, my name is Paul Johnson and I am a software engineer with the Solaris Ready group here at Sun in Broomfield, Colorado. I might start putting entries here about things I do. Maybe.

    Posted by Paul Johnson [Sun] ( July 18, 2008 08:19 AM ) Permalink | Comments[0]