“free” command to determine ram/memory usage in FreeBSD

People moving from Linux to FreeBSD get confused when they need to determine ram/memory usage. Although there is no equivalent command, there is a nice perl script located at http://people.freebsd.org/~rse/dist/freebsd-memory. Just download and run the perl script, and it gives a formatted output of your memory status. Something like:

# fetch http://people.freebsd.org/~rse/dist/freebsd-memory
# perl freebsd-memory

In case  you need to mimic the linux command, simply set the execution bit and move it to bin.

# fetch -o /usr/local/bin/free http://people.freebsd.org/~rse/dist/freebsd-memory
# chmod +x /usr/local/bin/free

You should now be able to use “free” command without any problems from anywhere within your system.

Amitabh Kant

Advertisements

Upgrading FreeBSD 7.2 to 8.0

Recently updated one of my production boxes to FreeBSD 7.2 Release machine to 8.0 Release. Thanks to freebsd-update and portsnap (both in base system now) from Colin Percival (part or security team for FreeBSD) , I was able to get the upgrade done with two downtime of just a minute each.

While updating the os and software, I relied heavily on a post by Colin at  http://www.daemonology.net/blog/2009-07-11-freebsd-update-to-8.0-beta1.html . I modified the instructions a little bit, as I needed to upgrade to 8.0 Release .  Also, instead of using portupgrade, I prefer using portmaster for upgrading my ports. It has no extra dependencies, and works pretty nicely. You can read more about portmaster here. I almost alwys use the ports to install any software on FreeBSD, so the methods and tools work fine for me. If you are using any custom ports or software, you will have to watch out for any nuances involved with those ports/software.  I will list out the steps that I followed while upgrading my system. If you follow Colins page, you will find this post closely following his advice, apart from the few changes in the tools being used:

Step 1: Update your ports to the latest

# portsnap fetch update
# portmaster -aD

If there are any config options available during port upgrade, you will be asked for the same at the start itself.

Step 2: Download the 8.0 Release binary diff/patches

# freebsd-update -r 8.0-RELEASE upgrade

You will start receving messages about your installed system. Once you have confirmed  the list presented, press y.

Looking up update.FreeBSD.org mirrors... 3 mirrors found.
...
The following components of FreeBSD seem to be installed:
...
The following components of FreeBSD do not seem to be installed:
...
Does this look reasonable (y/n)? y

If you have made any changes to the default config files of the OS, it will ask you to merge the changes by opening up your default editor with the changes

Fetching metadata signature for 8.0-RELEASE from update4.FreeBSD.org... done.
...
Inspecting system... done.
Preparing to download files... done.
...
Attempting to automatically merge changes in files... done.

If there any changes that are to be done, you would be notified of the same.

The following changes, which occurred between FreeBSD 7.2-RELEASE and
FreeBSD 8.0-RELEASE have been merged into /etc/hosts:
...

Now you will be shown three lists of files which it wants to remove, add or modify. Press q for each list if you are not too much concerned with the file listings.

The following files will be removed as part of updating to 8.0-RELEASE:
...
The following files will be added as part of updating to 8.0-RELEASE:
...
The following files will be updated as part of updating to 8.0-RELEASE:
...

Step 3: Install the 8.0-RELEASE kernel and make sure you reboot for the new kernel to be used:

# freebsd-update install
Installing updates...
Kernel updates have been installed. Please reboot and run
"freebsd-update install" again to finish installing updates.
# shutdown -r now

Step 4: Install the rest of the 8.0-RELEASE:

# freebsd-update install
Installing updates... done.
Completing this upgrade requires removing old shared object files.
Please rebuild all installed 3rd party software (e.g., programs
installed from the ports tree) and then run "freebsd-update install"
again to finish installing updates.

At this point, you will have the new os installed (kernel and userland), but  some ports  might still be linking to old libraries.  You need to force rebuild all ports to make sure that os and ports are at the same level.

Step 5: Rebuild all installed ports

# portmaster -aDf

Once this is completed, run freebsd-update once again to remove stale libraries and reboot your system to complete the process.

Step 9: Remove old shared libraries and reboot

# freebsd-update install
Installing updates... done.
# shutdown -r now

That’s it. You should have a working 8.0 RELEASE by now. I haven’t tested it out myself yet, but I believe that you can use the same procedure starting from 6.3 RELEASE.

As usual, before starting of the process, make sure you have safe backup of your system. Though the process is pretty safe and tested, you still have no guarantee of not hosing your entire system to the point of no recovery ;).

Amitabh Kant