How to add PC-BSD partition into grub in Ubuntu 10.04 LTS

I just installed Ubuntu 10.04 in my Compaq Presario laptop triple-booted with Windows 7 and PC-BSD 8.0.
The Windows 7 partition was automatically detected by Grub and able to boot to the Windows system. But the PC-BSD was not automatically detected by the Grub.
I need to manually add the PC-BSD partition into Grub so I can boot to the PC-BSD system.

Here are the steps I did:

1. Boot to the Ubuntu 10.04 LTS.
2. Open the Terminal application and run fdisk to know the partition table on the disk.

$ sudo fdisk -l

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe9efb4e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        6527    52428096    7  HPFS/NTFS
/dev/sda2            6528       10734    33792727+   7  HPFS/NTFS
/dev/sda3           10735       15068    34812855   83  Linux
/dev/sda4           15069       19457    35254170   a5  FreeBSD
Partition 4 does not end on cylinder boundary.

You can see above that the PC-BSD partition is on /dev/sda4. Note that PC-BSD is based-on FreeBSD so the file system type is known as FreeBSD.

3. Edit the “/etc/grub.d/40_custom” file.
I will manually add menu entry of PC_BSD partition into the grub.
Add this lines below to the /etc/grub.d/40_custom file:

menuentry "PC-BSD (on /dev/sda4)" {
        insmod ufs
        set root='(hd0,4)'
	search --no-floppy --fs-uuid
        chainloader +1

4. Run update-grub:

$ sudo update-grub
[sudo] password for fuad: 
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-21-generic
Found initrd image: /boot/initrd.img-2.6.32-21-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda1

Though the update-grub did not find PC-BSD partition as you can see above, but if you reboot the Ubuntu you can find the PC-BSD in the list choice of boot menu of Grub and it can successfully boot to the PC-BSD OS.

Grub Ubuntu Windows 7 and PC-BSD (click to enlarge)