Sunday, December 04, 2011

Install HTOP on FreeBSD

Working with command line I really miss some of the nice graphics you find with Windows based tools. The current Windows Resource Monitor included in Windows 7 and Windows Server 2008 is really my favorite. It's great to use for monitoring as it's a real time graph of the system performance. I know that Linux/UNIX tools like TOP can do the same but it's just visually easier to view a graph than numbers.

I recently started to use HTOP which is a more graphical version of TOP but is not as popular. The downside is that while it's more handy, you may need to have it installed manually, it's typically not included by default. Below is a screenshot of HTOP running.


Installing HTOP in CentOS is extremely simple.

#yum install htop

Done! For Debian based systems, use the following command.

$sudo apt-get install htop

Simple and easy, now run htop. But what if you want to install htop for FreeBSD? That's going to take a little bit more work.

Good news is that HTOP is available from the FreeBSD ports collection. This will make the process much easier that installing from source.

http://www.freebsd.org/cgi/cvsweb.cgi/ports/sysutils/htop/

For the actual installing, I following a few blogs and forum postings. One from The Technical Crib pointed me how to install the Linux emulators for FreeBSD. But after following the steps I received another error during the install process, which was covered in this FreeBSD forum posting. Finally, as suggested in the previous link, the fix was to install the source, found how to do that in this Cyberciti blog posting.

Below I will write out the full steps that worked for me, didn't discover this but it's complied between all the articles I found.

Installing the requirements 

1) Su or login as root

2) Run the command to enable Linux binarary compatibility for FreeBSD.

#kldload linux

3) Add to the startup

Edit /etc/rc.conf

Add following line

linux_enable="YES"

4) Install Linux base port f10.

#cd /usr/ports/emulators/linux_base-f10


#make install clean

5) Add linproc to fstab

Edit /etc/fstab

Add following line

linproc /compat/linux/proc   linprocfs   rw   0  0

6) Install Htop from the port

#cd /usr/ports/sysutils/htop

#make install clean

7) Htop should run!

$htop

Possible extra step

*note - htop should complete the install with no problems. If you see an error as the following, you may need to install the source files to your computer.

Error result ***


===>  Configuring for lsof-4.84A,5
Creating ./lockf_owner.h from /usr/src/sys/kern/kern_lockf.c
FATAL ERROR: can't read /usr/src/sys/kern/kern_lockf.c
FATAL ERROR: ./lockf_owner.h creation failed (see 00FAQ)
===>  Script "Configure" failed unexpectedly.
Please report the problem to ler@lerctr.org [maintainer] and attach the
"/usr/ports/sysutils/lsof/work/lsof_4.84A.freebsd/config.log" including the
output of the failure of your make command. Also, it might be a good idea to
provide an overview of all packages installed on your system (e.g. an `ls
/var/db/pkg`).
*** Error code 1


Stop in /usr/ports/sysutils/lsof.
*** Error code 1


Stop in /usr/ports/sysutils/htop.
*** Error code 1


Stop in /usr/ports/sysutils/htop.


Error result ***

I am using FreeBSD version 8.2 stable and saw this error, so I followed one of the links posted and installed the kernel source code. We're going to run through some settings with FreeBSD's sysinstaller, it's kinda of confusing but take your time and carefully tab around.

1) Su as root

2) Run the sysinstaller

#sysinstall

3) Select "Options", then tab to the "Select" button, press enter



4) Under the Options Editor, use the arrow keys to scroll down to "Release Name" value, we are going to change this by removing the "-p3" after "RELEASE". Press the space bar to open an edit window.


5) In the edit window, remove the "-P3" value. This is done because when we download the source files, it does not know where to find this source. Tab to "Ok" when done. Then press "q" to quit to the main screen.


6) Back at the main sysinstaller screen we are going to select "Configure", then tab to "Select" and press enter.


7) Use the arrow keys to select "Distributions" then then use the space bar to select to continue.


8) On the next page, scroll down again using the arrow keys and select "SRC - Sources for everything". Press the space bar to select.


9) Under the sub-components, you will need to select two source trees, Base and Sys. Scroll down again using the arrow keys and select the following with the space bar.

"Base - top-level files in /usr /src"
"Sys - /usr/src/sys (FreeBSD kernel)"

Tab to the "Ok" button again.


10) After this you will be prompted where to install the files from (CD/DVD/FTP, etc.). Since this is a smaller download, I would suggest FTP, and first starting with the main FTP site. Now if the FTP fails with the following error message

Warning: Can't find the '8.2-RELEASE-P3' distribution on this FTP server

Go back to step 5 and make sure you edited the name. 

Htop should finally run as normal! Yes, this was a pain but considering it's running a Linux based tool, wasn't that bad!

Rob