Tuesday, July 26, 2011

todo

[] backup & restore entire freebsd system
- Acronis TrueImage
- Imaging
- Clonezilla
- snapshot
- ZFS

http://www.wonkity.com/~wblock/docs/html/backup.html
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/backup-basics.html

[] Upgrading FreeBSD Ports
- portmaster
- portupgrade
- portmanager

[] List of build automation software

- CMake
- autoconf
- automake

http://en.wikipedia.org/wiki/Build_automation
http://en.wikipedia.org/wiki/List_of_build_automation_software
http://gala4th.blogspot.com/2010/11/autoconf-automake-unix-programming.html

[] Portmaster Vs. Portupgrade vs. portmanager

http://freebsd-forums.liquidneon.com/showthread.php?t=6078

http://lists.freebsd.org/pipermail/freebsd-questions/2007-March/145386.html

http://forums.freebsd.org/showthread.php?t=220

Sunday, July 24, 2011

How to determine filesystem type on Mac OS X

# mount

/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
/dev/disk1s2 on /Volumes/Backup_Mobile (hfs, local, nodev, nosuid, journaled)

how to export photos images pictures from iPhone to Mac

Method 1 - use Image Capture:

on Mac > Applications > Image Capture.

Method 2 - use iPhoto:

on Mac > Applications > iPhoto > select photos > click "import selected".

Files will be stored in the iPhoto library. Now, you can copy and paste files from iPhoto library to your hard drive.

Mount ISO image on Mac

Method 1:
# hdiutil mount sample.iso

Method 2:
You can mount ISO images in Mac OS X by using Disk Utility, located in the /Applications/Utilities/ directory. After you have launched Disk Utility, navigate from the Disk Utility menu down to “Open Image File” and select your ISO file. The ISO should now appear mounted on the Mac OS desktop. Yes, this works for other disk image files too (dmg, img, etc).

Reference:
http://osxdaily.com/2008/04/22/easily-mount-an-iso-in-mac-os-x/

Thursday, July 21, 2011

Backup Options For FreeBSD

Backup Options For FreeBSD

Warren Block
<wblock@wonkity.com>
2011-05-24
Table of Contents
Introduction
Archives
dump(8)/restore(8)
 Useful dump Options
 restore(8)
 Simple dump
 dump With Compression
 dump Via SSH
 Copying Filesystems
 restore(8) Over A Live System
Clonezilla
dd
Simple dd Usage
dd With Compression
Other Programs
Conclusion
© 2011 Warren Block

Last updated 2011-05-24

Available in HTML or PDF. Links to all my articles here. Created with AsciiDoc.

Introduction

There are many ways of backing up a FreeBSD system. Which method to choose depends on your needs. Here we’ll describe the most common methods, and their benefits and disadvantages. The FreeBSD Handbook Backup Basics chapter is another source you should examine.

Be very careful about backups. Test the data from them. The more copies, the better. Consider the information here advisory and untested. No guarantee is expressed or implied that any of this works or will protect your data or will elicit anything more than loudly apologetic noises if data loss occurs.

Archives

Beware of backup methods that only keep one copy of data; there’s no way to retrace your steps. Deleted a file last month? It’s gone, because we only have a backup from last night. The backup methods below save to files, and it’s easy to put those files into a new yyyy-mm-dd directory each time. Keep backups as far back as possible.

dump(8)/restore(8)

dump(8) and restore(8) have been the standard FreeBSD backup utilities since vacuum tubes roamed the earth. They work at the filesystem level, and so only back up used space. restore can provide access to individual files in a backup, useful when your system is fine but you just need that one file out of a backup.

dump is not particularly fast, but because it only backs up actual data (filesystem blocks in use), can be faster than whole-disk backup methods.

Each filesystem must be dumped individually; this is sometimes expressed as "dump does not cross filesystems". On a normal FreeBSD system, a full backup includes dumps of /, /var, and /usr. /tmp is a separate filesystem, too, but you’re not supposed to be storing valuable data there.

/ and /var are usually small and trivial to dump, with /usr being much larger. If you’re dumping to files on a FAT filesystem, the 2G/4G file size limit can be an unwelcome surprise.

dump can take either mountpoints like /var, or the device node of an unmounted filesystem, like /dev/ada0s1d. If a filesystem is mounted, the -L snapshot option should be used.

Useful dump Options
One of the nice usability features of FreeBSD is that ctrl-T sends a SIGINFO to the controlling process. With dump, this means you can press ctrl-T and get a "percent completed" report. That report will also be printed automatically every five minutes, if you’re the patient sort.

Giving dump a larger cache with the -C option can help speed things up. Be a little cautious: since dump forks multiple processes, the cache size will be used multiple times. If you overcommit memory and the computer starts to swap, the dump will change from "annoyingly slow" to "glacially agonizing". The dump(8) man page recommends 8 to 32 megabytes. It also recommends always using -C when the -L snapshot option is used.

Directories to be skipped in a dump can be marked with the nodump flag:

# chflags nodump /usr/ports
Because the Ports Collection is easy to recreate and often contains large distfiles, it’s a prime candidate to skip in backups. (On computers with poor net access where those distfiles are hard to download, you might want to back it up; as always, it depends on your situation.)

Other large directories with easy-to-recreate or unnecessary data could include /usr/src and various types of cache, like web browser cache or the files created by devel/ccache.

restore(8)
restore has many useful options, including the ability to interactively choose individual files for restoration. Here, we’ll only show restoring a whole filesystem, but please see the restore(8) man page.

restore puts restored files in the current directory. Don’t forget to cd to the right directory before running restore.
Simple dump
Back up a single system to an external hard drive. The external hard drive is UFS-formatted, so file size limits are not a problem.

# mount /dev/da0s1 /mnt
# dump -C16 -0uanL -h0 -f /mnt/root.dump /
# dump -C16 -0uanL -h0 -f /mnt/var.dump /var
# dump -C16 -0uanL -h0 -f /mnt/usr.dump /usr
# umount /mnt
The external drive is mounted at /mnt, then the /, /var, and /usr filesystems are dumped to files on it.

Restoring this backup is also pretty simple. This example restores the /var filesystem into a temporary directory. This is the type of restore used when you’re looking for some files that were accidentally deleted. If you were restoring a whole system, you’d restore the data over the filesystem where it originated.

# mount /dev/da0s1 /mnt
# mkdir /tmp/oldvar
# cd /tmp/oldvar
# restore -ruf /mnt/var.dump
# umount /mnt
See the restore(8) man page for the -i option, which provides a shell-like interactive session for selecting files and directories to restore.

dump With Compression
# mount /dev/da0s1 /mnt
# dump -C16 -0uanL -h0 -f - / | gzip -2 > /mnt/root.dump.gz
# dump -C16 -0uanL -h0 -f - /var | gzip -2 > /mnt/var.dump.gz
# dump -C16 -0uanL -h0 -f - /usr | gzip -2 > /mnt/usr.dump.gz
# umount /mnt
Like the previous example, but dump output is piped through gzip, creating compressed dump files.

gzcat is used to decompress these files for restoration. This example restores to a temporary directory so the backed-up directories and files are available but don’t overwrite the current files.

# mount /dev/da0s1 /mnt
# mkdir /tmp/usr
# gzcat /mnt/usr.dump.gz | (cd /tmp/usr && restore -ruf -)
# umount /mnt
dump Via SSH
ssh allows dump to send files to another system on the network, which is very handy, at least if you have more than one system.

# dump -C16 -0uanL -h0 -f - / | gzip -2 | ssh -c blowfish user@otherhost dd of=root.dump.gz
# dump -C16 -0uanL -h0 -f - /var | gzip -2 | ssh -c blowfish user@otherhost dd of=var.dump.gz
# dump -C16 -0uanL -h0 -f - /usr | gzip -2 | ssh -c blowfish user@otherhost dd of=usr.dump.gz
otherhost is the system receiving the backup files, and user is the username on that other system. As before, gzip compresses the files, but then ssh logs in to the other system and copies the input into a file in the user’s home directory with dd.

Backup speeds may be slower than to a directly-connected disk. dump and ssh prompts are mixed together, which can be confusing when ssh is waiting for a password. But the convenience of this method sometimes makes a FreeBSD notebook or netbook a better "backup device" than a simple external hard disk.

Restoring these files is a reversal of the dump command line:

# mkdir /tmp/root /tmp/var /tmp/usr
# ssh -c blowfish usr@otherhost gzcat root.dump.gz | (cd /tmp/root && restore -ruf -)
# ssh -c blowfish usr@otherhost gzcat var.dump.gz | (cd /tmp/var && restore -ruf -)
# ssh -c blowfish usr@otherhost gzcat usr.dump.gz | (cd /tmp/usr && restore -ruf -)
Depending on the speed of the computers and the network, it may be faster to run the dump or restore on one computer and the compression on the other. For example, a restore that sends the compressed dump file over the network and decompresses it on the destination computer:

# ssh -c blowfish usr@otherhost dd bs=64k if=usr.dump.gz | (cd /tmp/usr && gzcat | restore -ruf -)
There are many possible variations. Networks and computers vary so widely that only testing will show what is effective on a particular system.

Copying Filesystems
Filesystems can be copied directly from one disk to another by piping the output of dump right into restore. Source and target filesystems don’t have to be the same size, the target just needs to be large enough to hold all the data in the source.

This example copies a running FreeBSD system onto a new drive. Slices and partitions have already been set up on the new disk, da0. The target is the first slice, with a traditional FreeBSD partition layout: a is /, d is /var, e is /tmp, and f is /usr. See Disk Setup On FreeBSD for background.

/var and / are copied last. They are smaller and may have changed during the copy of the much-larger /usr filesystem.

# mount /dev/da0s1f /mnt
# dump -C16 -0uanL -h0 -f - /usr | (cd /mnt && restore -ruf -)
# umount /mnt
# mount /dev/da0s1e /mnt
# dump -C16 -0uanL -h0 -f - /tmp | (cd /mnt && restore -ruf -)
# umount /mnt
# mount /dev/da0s1d /mnt
# dump -C16 -0uanL -h0 -f - /var | (cd /mnt && restore -ruf -)
# umount /mnt
# mount /dev/da0s1a /mnt
# dump -C16 -0uanL -h0 -f - / | (cd /mnt && restore -ruf -)
# umount /mnt
restore(8) Over A Live System
It is possible to restore over a live system. For example, if a hard drive dies, do a minimal FreeBSD install on a new hard drive, then boot that system and restore the /usr, /var, and then / filesystems. I suggest that order because continuing to run after overwriting important data in / is probably something to avoid. After the restore and a reboot, doing a full buildworld/kernel/installworld cycle is a good idea, to make sure the whole system is consistent.

The New Huge Disk section of the FreeBSD FAQ shows a different technique for a similar operation.

Clonezilla

Clonezilla is an open source live CD/USB image that has some of the functionality of Ghost. It’s not as easy to use; you need to know a few Linuxisms like that external hard drive you just connected is /dev/sda or sdb, or maybe hda. But once you get past that, it has lots of useful features. Several open-source backup programs are used to make sure that only occupied space is copied. Data is compresses and split into 2G files so it can use FAT filesystems for backup. It can use external drives, or SSH, Samba, or NFS network drives. It’s menu-driven, so it’s not terribly difficult to use. And the latest versions even support FreeBSD’s UFS filesystems.

Individual files aren’t accessible in the backups, and there’s no way to skip directories that don’t need to be backed up. But for whole-disk, mostly-automated backup of FreeBSD systems, you could do worse.

dd

dd is not a good way to back up a system. It has many disadvantages, including copying every block on the drive or slice, whether used or not.

The advantages are that dd is very easy to use. Just copy one drive to another—what could go wrong?

Well… the target drive must be at least as large as the source drive. It can be larger, although any extra space will be wasted.

Be very careful about source and destination drives. Get them mixed up on the command line, and the source drive will be overwritten. Allow me to repeat that: getting source and target mixed up will destroy your data.

Some notable utilities are based on using dd like this. g4u (Ghost For Unix) is one of the better-known versions.

Simple dd Usage
Copy drive ad0 to ad4. ad0 is your source drive, right? And you’re positive about that, right? The drive numbers didn’t change after adding the second drive? Okay…

# dd if=/dev/ad0 of=/dev/ad4 bs=64k
Setting the bs (block size) parameter to 64k will buffer the reads and writes and speed up the copy. Why not an even larger buffer? Because a larger buffer won’t speed up a typical drive. If you have a RAID setup or something faster than typical SATA or IDE, a larger buffer might be useful.

dd With Compression
A lot of space on the average disk is empty, but the blocks still have old data in them. That random old data doesn’t compress well if you dd that drive into an image file. You can improve the situation by filling all unused space with zeros. The brute-force method—and dd is nothing if not brute force—is to just build a file full of zeros until you completely fill the disk. Then delete the file.

# dd if=/dev/zero of=zerofile bs=1M
...(wait for an out-of-space error)
# rm zerofile
Unused space on the drive is now mostly compressible zeros.

# mount /dev/da0s1 /mnt
# dd if=/dev/ad0 bs=1M | gzip -2 > /mnt/diskimg.gz
# umount /mnt
While the image file is smaller, restoring it will still require a drive at least as large as the original.

Other Programs

There are advocates of all sorts of programs for backup. cpio(1), pax(1), and tar(1) are mentioned frequently in this context. For some things, they work fine. But only dump backs up at the filesystem block level and can be trusted for any of the weird situations a UFS filesystem may contain.

There are other situations, of course. For making an archive of a directory tree, tar(1) with a compression option like -z or -j is a widespread standard.

For copying files or directories, net/rsync is very useful. It only copies the differences between source and target, and supports compression, so updates are very quick. Built-in support for ssh(1) means those directories can be on separate computers on the network. If you wanted to make a backup of selected directories of data files, rsync works extremely well for that, and it’s versatile enough to be used in lots of ways.

Conclusion

There are many ways to go about keeping data that was expensive and difficult to create, some that go far beyond the ones listed above. There’s Bacula, and Amanda, and all sorts of commercial and homebuilt schemes.

Whatever you pick, remember that backups are the kind of thing you only need when you don’t have them.

Reference:
http://www.wonkity.com/~wblock/docs/html/backup.html

Sunday, July 10, 2011

mount NTFS FAT32 on mac OS X

Rename the original /sbin/mount_ntfs tool:

sudo mv /sbin/mount_ntfs /sbin/mount_ntfs.orig

Create a script like this:

#!/bin/sh
/sbin/mount_ntfs.orig -o rw "$@“

save the script to /sbin/mount_ntfs

sudo chown root:wheel /sbin/mount_ntfs
sudo chmod 755 /sbin/mount_ntfs

Enjoy R/W access to NTFS volumes...

In case you don't like it

sudo mv /sbin/mount_ntfs.orig /sbin/mount_ntfs

and everything is back to R/O.

Make sure to check that mount_ntfs is listed as -rwxr-xr-x and root wheel when you type ls -al /sbin/mount_ntfs and you're good to go.

P.S.
If it isn't working for you, it may be that the NTFS partition wasn't cleanly unmounted previously (e.g. not using safe eject in Windows). To check if this is the case, open Console in Utilities, and go to 'All Messages' instead of 'Console Messages'. Search for 'ntfs' and you may come across an error that displays like this:
NTFS-fs error (device /dev/disk3s1, pid 435): ntfs_system_inodes_get(): $LogFile is not clean. Mounting read-only. Mount in Windows.
You need to plug the disk into Windows-running system, and do a safe eject. Then the NTFS partition will mount in read/write mode.

Good luck!
Again thanks iBlacky

Reference:
http://forums.macrumors.com/showthread.php?t=785376&page=2

Thursday, July 7, 2011

Changing the redirect value of a Drupal node form in D6

How to redirect to a page after node form submission

Method 1:

Add a destination to the query string of a URL:

?q=node/add/page?destination=admin

Method 2:
<?php
function test_my_form($form_state) {
  $form['#action'] = url('comment/reply/'. $edit['nid']);
}

Method 3:
<?php
function test_my_form_submit($form, &$form_state) {
  drupal_goto("my_page", "sex=1&country=BE");
}

Method 4:

Create a custom module custom.module and place this code in it:
<?php
function custom_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'contact_mail_page':
      $form['#redirect'] = 'thank-you-page';
      break;
  }
}

Method 5:
Reference: http://www.brianvuyk.com/story-type/changing-redirect-value-drupal-node-form-d6

Changing the 'redirect' value of a Drupal node form in D6
Posted Tue, 07/28/2009 - 13:21 by Brian

Generally, when you want to change the location that a for redirects to after submission, you usually should set $form_state['#redirect'] within a call to hook_form_alter().

<?php
/**
* Implementation of hook_form_alter
*/
function custom_module_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_type_form') {
    // Set form redirect
    $form['#redirect'] = some/other/path;
  }
}


Unfortunately, that doesn't work for the node form. The node form has three submission buttons ('Submit', 'Preview', and 'Delete'), and each of these has it's own submission handler which sets the redirect value. Furthermore, the redirect values set in the submission handlers associated with the buttons overwrite $form['#redirect'] as set in the code example above.

In order to redirect the node form, you need to add your own submission handler to be executed after the default handler:

<?php
/**
* Implementation of hook_form_alter
*/
function custom_module_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_type_form') {
    // Overwrite the default node submission handler with our own.
    $form['buttons']['submit']['#submit'][] = 'my_module_example_form_submit'
  }
}


Since our submit handler is added to the submit array after the original node-form-submit handler and therefore executed later, we can overwrite $form_state['redirect'] variable:

<?php
/**
* Custom submit handler. Overwrites the form redirection variable.
*/
function my_module_example_form_submit($form, &$form_state) {
  $form_state['redirect'] = 'some/other/path';
}


That should do it - the node form should now redirect to whatever path your set in the submit handler.

Tuesday, July 5, 2011

FreeBSD find out RAM size including total amount of free and used memory size

FreeBSD find out RAM size including total amount of free and used memory size

by Vivek Gite · 11 comments

Method 1:
# dmesg | grep memory

Method 2:
# sysctl -a | grep mem

Method 3:
Q. How do I find out RAM size / memory size in FreeBSD? How do I display amount of free and used memory in the system?

A. To displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel you need to install special script Most user use sysctal command to get all data. There is a perl script that automates everything and display back result on screen.

This script query the system through the generic sysctl interface. The sysctl utility retrieves kernel state and allows processes with appropriate privilege to set kernel state. You must have perl installed on FreeBSD.
FreeBSD command about RAM size and information

Download perl script which is written by Ralf S. Engelschall:

freebsd-memory.pl.txt
#!/usr/bin/perl
##
##  freebsd-memory -- List Total System Memory Usage
##  Copyright (c) 2003-2004 Ralf S. Engelschall 
##  
##  Redistribution and use in source and binary forms, with or without
##  modification, are permitted provided that the following conditions
##  are met:
##  1. Redistributions of source code must retain the above copyright
##     notice, this list of conditions and the following disclaimer.
##  2. Redistributions in binary form must reproduce the above copyright
##     notice, this list of conditions and the following disclaimer in the
##     documentation and/or other materials provided with the distribution.
##  
##  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
##  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
##  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
##  ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
##  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
##  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
##  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
##  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
##  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
##  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   query the system through the generic sysctl(8) interface
#   (this does not require special priviledges)
my $sysctl = {};
my $sysctl_output = `/sbin/sysctl -a`;
foreach my $line (split(/\n/, $sysctl_output)) {
    if ($line =~ m/^([^:]+):\s+(.+)\s*$/s) {
        $sysctl->{$1} = $2;
    }
}

#   round the physical memory size to the next power of two which is
#   reasonable for memory cards. We do this by first determining the
#   guessed memory card size under the assumption that usual computer
#   hardware has an average of a maximally eight memory cards installed
#   and those are usually of equal size.
sub mem_rounded {
    my ($mem_size) = @_;
    my $chip_size  = 1;
    my $chip_guess = ($mem_size / 8) - 1;
    while ($chip_guess != 0) {
        $chip_guess >>= 1;
        $chip_size  <<= 1;
    }
    my $mem_round = (int($mem_size / $chip_size) + 1) * $chip_size;
    return $mem_round;
}

#   determine the individual known information
#   NOTICE: forget hw.usermem, it is just (hw.physmem - vm.stats.vm.v_wire_count).
#   NOTICE: forget vm.stats.misc.zero_page_count, it is just the subset of
#           vm.stats.vm.v_free_count which is already pre-zeroed.
my $mem_hw        = &mem_rounded($sysctl->{"hw.physmem"});
my $mem_phys      = $sysctl->{"hw.physmem"};
my $mem_all       = $sysctl->{"vm.stats.vm.v_page_count"}      * $sysctl->{"hw.pagesize"};
my $mem_wire      = $sysctl->{"vm.stats.vm.v_wire_count"}      * $sysctl->{"hw.pagesize"};
my $mem_active    = $sysctl->{"vm.stats.vm.v_active_count"}    * $sysctl->{"hw.pagesize"};
my $mem_inactive  = $sysctl->{"vm.stats.vm.v_inactive_count"}  * $sysctl->{"hw.pagesize"};
my $mem_cache     = $sysctl->{"vm.stats.vm.v_cache_count"}     * $sysctl->{"hw.pagesize"};
my $mem_free      = $sysctl->{"vm.stats.vm.v_free_count"}      * $sysctl->{"hw.pagesize"};

#   determine the individual unknown information
my $mem_gap_vm    = $mem_all - ($mem_wire + $mem_active + $mem_inactive + $mem_cache + $mem_free);
my $mem_gap_sys   = $mem_phys - $mem_all;
my $mem_gap_hw    = $mem_hw   - $mem_phys;

#   determine logical summary information
my $mem_total = $mem_hw;
my $mem_avail = $mem_inactive + $mem_cache + $mem_free;
my $mem_used  = $mem_total - $mem_avail;

#   information annotations
my $info = {
    "mem_wire"     => 'Wired: disabled for paging out',
    "mem_active"   => 'Active: recently referenced',
    "mem_inactive" => 'Inactive: recently not referenced',
    "mem_cache"    => 'Cached: almost avail. for allocation',
    "mem_free"     => 'Free: fully available for allocation',
    "mem_gap_vm"   => 'Memory gap: UNKNOWN',
    "mem_all"      => 'Total real memory managed',
    "mem_gap_sys"  => 'Memory gap: Kernel?!',
    "mem_phys"     => 'Total real memory available',
    "mem_gap_hw"   => 'Memory gap: Segment Mappings?!',
    "mem_hw"       => 'Total real memory installed',
    "mem_used"     => 'Logically used memory',
    "mem_avail"    => 'Logically available memory',
    "mem_total"    => 'Logically total memory',
};

#   print system results
printf("SYSTEM MEMORY INFORMATION:\n");
printf("mem_wire:      %12d (%7dMB) [%3d%%] %s\n", $mem_wire,     $mem_wire     / (1024*1024), ($mem_wire     / $mem_all) * 100, $info->{"mem_wire"});
printf("mem_active:  + %12d (%7dMB) [%3d%%] %s\n", $mem_active,   $mem_active   / (1024*1024), ($mem_active   / $mem_all) * 100, $info->{"mem_active"});
printf("mem_inactive:+ %12d (%7dMB) [%3d%%] %s\n", $mem_inactive, $mem_inactive / (1024*1024), ($mem_inactive / $mem_all) * 100, $info->{"mem_inactive"});
printf("mem_cache:   + %12d (%7dMB) [%3d%%] %s\n", $mem_cache,    $mem_cache    / (1024*1024), ($mem_cache    / $mem_all) * 100, $info->{"mem_cache"});
printf("mem_free:    + %12d (%7dMB) [%3d%%] %s\n", $mem_free,     $mem_free     / (1024*1024), ($mem_free     / $mem_all) * 100, $info->{"mem_free"});
printf("mem_gap_vm:  + %12d (%7dMB) [%3d%%] %s\n", $mem_gap_vm,   $mem_gap_vm   / (1024*1024), ($mem_gap_vm   / $mem_all) * 100, $info->{"mem_gap_vm"});
printf("-------------- ------------ ----------- ------\n");
printf("mem_all:     = %12d (%7dMB) [100%%] %s\n", $mem_all,      $mem_all      / (1024*1024), $info->{"mem_all"});
printf("mem_gap_sys: + %12d (%7dMB)        %s\n",  $mem_gap_sys,  $mem_gap_sys  / (1024*1024), $info->{"mem_gap_sys"});
printf("-------------- ------------ -----------\n");
printf("mem_phys:    = %12d (%7dMB)        %s\n",  $mem_phys,     $mem_phys     / (1024*1024), $info->{"mem_phys"});
printf("mem_gap_hw:  + %12d (%7dMB)        %s\n",  $mem_gap_hw,   $mem_gap_hw   / (1024*1024), $info->{"mem_gap_hw"});     
printf("-------------- ------------ -----------\n");
printf("mem_hw:      = %12d (%7dMB)        %s\n",  $mem_hw,       $mem_hw       / (1024*1024), $info->{"mem_hw"});     

#   print logical results
printf("\n");
printf("SYSTEM MEMORY SUMMARY:\n");
printf("mem_used:      %12d (%7dMB) [%3d%%] %s\n", $mem_used,  $mem_used  / (1024*1024), ($mem_used  / $mem_total) * 100, $info->{"mem_used"});
printf("mem_avail:   + %12d (%7dMB) [%3d%%] %s\n", $mem_avail, $mem_avail / (1024*1024), ($mem_avail / $mem_total) * 100, $info->{"mem_avail"});
printf("-------------- ------------ ----------- ------\n");
printf("mem_total:   = %12d (%7dMB) [100%%] %s\n", $mem_total, $mem_total / (1024*1024), $info->{"mem_total"});

# fetch http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
# mv freebsd-memory.pl.txt /usr/local/bin/free
# chmod +x /usr/local/bin/free

Make sure perl is installed. Now to display or list total system memory usage type
$ free
Output:

SYSTEM MEMORY INFORMATION:
mem_wire: 25341952 ( 24MB) [ 9%] Wired: disabled for paging out
mem_active: + 47529984 ( 45MB) [ 18%] Active: recently referenced
mem_inactive:+ 15605760 ( 14MB) [ 6%] Inactive: recently not referenced
mem_cache: + 16384 ( 0MB) [ 0%] Cached: almost avail. for allocation
mem_free: + 165556224 ( 157MB) [ 65%] Free: fully available for allocation
mem_gap_vm: + 389120 ( 0MB) [ 0%] Memory gap: UNKNOWN
-------------- ------------ ----------- ------
mem_all: = 254439424 ( 242MB) [100%] Total real memory managed
mem_gap_sys: + 4988928 ( 4MB) Memory gap: Kernel?!
-------------- ------------ -----------
mem_phys: = 259428352 ( 247MB) Total real memory available
mem_gap_hw: + 9007104 ( 8MB) Memory gap: Segment Mappings?!
-------------- ------------ -----------
mem_hw: = 268435456 ( 256MB) Total real memory installed

SYSTEM MEMORY SUMMARY:
mem_used: 87257088 ( 83MB) [ 32%] Logically used memory
mem_avail: + 181178368 ( 172MB) [ 67%] Logically available memory
-------------- ------------ ----------- ------
mem_total: = 268435456 ( 256MB) [100%] Logically total memory

Linux like free command for FreeBSD

Freecolor is a free replacement that displays free memory graphically as a bargraph. It supports the same options as free. Install freecolor, enter:
# cd /usr/ports/sysutils/freecolor
# make install clean
To see memory details, enter:
$ freecolor -m -o
Sample output:

total used free shared buffers cached
Mem: 4082 825 3256 0 0 117
Swap: 2048 0 2047

$ freecolor -t -m -o
Sample output:

total used free shared buffers cached
Mem: 4082 825 3256 0 0 117
Swap: 2048 0 2047
Total: 6130 = ( 826 (used) + 5421 (free))


Reference: http://www.cyberciti.biz/faq/freebsd-command-to-get-ram-information/