Tuesday, November 10, 2009

Rescuing OpenSolaris after installing Windows 7

I recently did a clean install of Windows 7 on my laptop - and lost my OpenSolaris installs on the second partition of the same disk. Having the same problem?

Here's how to make it work again.

Intro
Prior to installing I had two partitons - one with Vista, the other with a bunch of OpenSolaris builds on zfs. W7 will during a clean install repartition its provided space into two partitions - a 100MB boot partition, and the big chunk of "all-the-rest" partition. It will also install its own stuff in the MBR, so any existing grub installs you have will disappear.

Installing Windows 7
Installed W7, connected to wifi, updated - everything in working order there.

Rescuing OpenSolaris
Rescuing the OpenSolaris install(s) requires a series of steps:

1) Make the OpenSolaris partition
active
The easiest way to do this is with a OpenSolaris live-cd. Boot from it, then in a terminal do

pfexec format

This starts format, so be careful. Select the disk containing your missing OpenSolaris install(s). In my case there was only one disk, c4t0d0. Make a note of the disk name, you'll need it later.

Inside format, start fdisk. Select '2' and mark the solaris partition as active. In my case it was the 3rd partition.

Save ('5'), then exit fdisk (quit) and format (quit).

2) Reinstall grub

We also need to reinstall grub in the Master Boot Record (MBR):

pfexec installgrub -m /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c4t0d0s0

The last operand is your root slice - your diskname, prefixed by /dev/rdsk/ and suffixed by s0. Answer 'yes' to overwrite the MBR.

If you reboot now, you should see your old grub menu again. Yippee :)
But you'll only be able to boot the partitions in the grub menu that retained their indexes during the W7 install.

3) Update the grub menu

Since W7 added a new partition - normally at the start of your disk, the revived grub menu will still point to the old partition index. These are now wrong. I had to update my grub menu.lst as all OpenSolaris installs were now on partitions with index+1, due to the added W7 boot partition.

bootadm menu-list

will show you where your current grub menu.lst is located. Mine was at /rpool/boot/grub/menu.lst. Edit the grub menu:

pfexec gedit /rpool/boot/grub/menu.lst

Update the necessary findroot() entries to point to their new partition numbers. I had to update all OpenSolaris partitions from the 2nd to the 3rd partition as follows:

findroot(pool_rpool, 1, a)

to

findroot(pool_rpool, 2, a)

While editing, you can also change the default entry and timeout too if you please. When done rerun 'bootadm menu-list' to see that everything is as desired.

4) Reboot ...
and enjoy your old grub menu with all OpenSolaris installs and W7 :)

That's all there really is to it...

Thursday, July 16, 2009

EMC2 on a modern laptop?

My HobbyCNC router has been running fine with an old Pentium brick for hardware, FreeDOS and TurboCNC for a while. However its kinda slow booting the brick, and the TurboCNC user interface is as far from sexy as you get. Given its free its... well... OK.

There are other commercial alternatives that look a lot better, and works under windows if you please. Then there's EMC2 :)

EMC2 is a GPL machine controller, running on linux with a graphical user interface called Axis. More specificly its a real-time patched Ubuntu 8.04 distro, with EMC2.3.1. Yes, there's even a live-CD if you just want to try it out withput committing hardware. Not wanting to put a new brick on the desk for running my HobbyCNC router, as well as having a spare laptop lying around, I figured I'd have a go with the laptop even though the manuals tell you not to.

The main problem with modern laptops is there's no parallel port. But there's oodles of USB ports. First thought, use a USB-to-LPT cable. Sadly EMC2 does not support that (yet at least), it needs a true LPT port. This has to do with the inner workings of EMC2, using hardware in the parallel port as a "reliable" way of making fast enough clock ticks.

But wait, there's a PCMCIA slot here as well. Time to grab a PCMCIA parallel port expansion card. I got my self a NetMos Technology chipset based one, as it's supposed to work with Ubuntu. And it works indeed - even with EMC2. I won't do this as a step by step instructions for now - but outline the process.

First enable the LPT port in the BIOS, even though there's no physical port. The card is then immediately recognized in Ubuntu as seen by the output of lspci -v. This also show my LPT port located at 0x1000, yours may differ. I do not load either the parport_cs, nor parport drivers, as it cause EMC2 to fail at startup.

Next run the EMC2 configuration wizard, selecting my HobbyCNC controller card, with the LPT port at 0x1000, configuring the pins per HobbyCNC instructions, as well as the router and stepper properties.

EMC2 now starts without complaints. Jogging the router work fine, and Axis shows a nice 3D rendering of the work being done. Success :D

Even though I'm still in the testing and adjusting phase with EMC2, its looking very good IMHO. Should the laptop route give me problems later, I'll simply get myself a newer brick instead, because it looks like EMC2 is here to stay on my desktop!

Monday, June 29, 2009

SDCC on OpenSolaris

SDCC?

Yes, SDCC, the free small device c-compiler. I just gave it a try, wanting to do some programming for a MicroChip PIC, and it seems to work fine on OpenSolaris 2009.06. You do however need to compile it yourself, as there seems to be no packages available yet (that I'm aware of). But, do not fear.

Since I'm a complete noob when it comes to PIC programming, I aided myself with Micah Carricks tutorial on c-programming for PICs using SDCC on linux, and some OpenSolaris development knowledge, and was able to get sdcc working on OpenSolaris. So, thanks Micah!
http://www.micahcarrick.com/04-25-2005/pic-c-programming-linux.html

Step 1: Getting the packages
  • Get the SDCC source (currently 2.9.0)
  • Get the gputils source (currently 0.3.17)
  • Install gcc 4.3.x from your favorite location
  • Install g++ 4.3.x from your favorite location
You might also want to get gpsim and gpicd for simulation and In-circuit debugging respectively, too. But I didn't get to those yet.

Step 2: Environment
Set you PATH to point to gcc4/g++ if it doesn't already. In case you used opencsw or similar, do:
export PATH=$PATH:/opt/csw/gcc4/bin

Set your LD_LIBRARY_PATH to point to libstdc++
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/csw/gcc4/lib

Step 3: Build and install gputils
GNU tools normally build right out of the box :)
pfexec make install takes care of installation.

Step 4: Build and install SDCC
You'll need to make a couple of adjustments to all Makefile.in in the sdcc code. OpenSolaris' ar doesn't accept the -S option, but that can be removed safely. Do that for any Makefile.in in your project.

Step 5: ./configure
A simple
./configure
should configure the build for you.

If it doesn't, it's likely because you either didn't fix all Makefile.ins as described above, or configure/gcc/g++ can't find all libs due to an missing or incorrectly set LD_LIBRARY_PATH.

With gputils and gcc available in $PATH, sdcc configured nicely AFAICT.

Step 6: ./make
With gputils and gcc available in $PATH, sdcc also built nicely AFAICT.

Step 7: Testing sdcc
Using the first two, very small, examples in Micah Carricks tutorial, I put sdcc through its paces and it produced the expected output.

Now, out of the box, configure will make your install go to /usr/local/bin, which is kinda non-opensolaris-ishy, but playing around with the options to configure will put it where you (might) want it to go.

That's all there is (was) to it :)

Plotting on OpenSolaris

If you, like me, want to do large-format PDF plots from OpenSolaris with that old, unsupported, driver-nowhere-to-be-found HPGL plotter, then you might fancy having a look at Alfreds Klomps blog on pushing HPGL data to the plotter linux/(open)solaris/osx style

http://www.alfredklomp.com/technology/plotter/

To covert your PDFs to HGPL, go grab ps2edit

http://www.pstoedit.net/

and you'll be pumping PDFs off that old plotter in no time!

Your CTRLs?

"Your controls" is the term a flight instructor use when the student pilot is handed the controls. Being somewhat of a computer geek and flight instructor, the observant reader will hopefully be able to connect the dots on that play of words...

No matter the result of that mental exercise, I hope my blogging will be of help to someone, somewhere.