skip to Main Content

How To: Building an Embedded Asterisk PBX

Booting From Compact Flash

Unlike hard drives, there are very real limits to how many read/write cycles a compact flash (CF) card can survive. If the system was to treat the CF card just like a hard drive, then the CF card would fail in an unacceptably short period of time. On the Asterisk Users Mailing List, I found users whose experience was that the point of failure can be as low as 300,000 writes, even when using high quality, brand name CF cards.

Astlinux has been designed to get around this issue through use of a RAM disk and by limiting write access to the CF card. At boot time the contents of the CF card are copied to a RAM disk, which is then used to boot the OS, services and applications. The CF is still mounted by the OS, but in read-only mode. Symbolic links are used to provide pointers on the RAM disk to critical config files on the CF card, and all disk writes happen to/from the RAM disk. This approach extends the service life of the CFcard by several orders of magnitude.

Here’s my experience. My initial Astlinux test system used an old generic 128 MB CF card once used in a long dead digital camera. That card was in service for more than a year without any problems at all. For my new Soekris based production Astlinux system I purchased a new 32 MB Sandisk CF card for a mere $8 on eBay. Kristian recommends Sandisk cards, as he has found them to be the most reliable.

Figure 3: Windows installer writing the Astlinux boot image to a CF card

Figure 3: Windows installer writing the Astlinux boot image to a CF card

Since I’m no Linux wizard I needed to load the CF card with the boot image using my Windows XP desktop. The Windows installer for Astlinux includes a utility called “physdiskwrite” for loading the CF card on any PC with a suitable media reader. Writing Astlinux to the CF card was easy (Figure 3) and took less than 2 minutes.

Asterisk User Configuration

Upon initial boot up there is a generic, fully functional Asterisk configuration loaded. This is sufficient for simple testing of Asterisk, but you will very quickly feel the need to amend the configuration to suit your own purposes. This is accomplished through loading your own Asterisk configs, which are not part of the CF boot image. Since the Soekris board provides a USB port, the easiest approach is to use a small USB key drive to hold the user-defined config files. Astlinux provides a simple command line utility for setting this up.

Typing genkd at the console invokes a shell script that formats the USB key and places default config files in the correct locations on it. After a quick reboot, the system uses symbolic links to read the Asterisk config files from the USB key instead of the CF card. The USB key also becomes the storage location for any incoming voicemail messages.

Since the USB key is easily swapped, this approach lends itself especially well to experimenting with various Asterisk configurations – moving between them is as simple as changing keys and rebooting. It’s easy to see how this could be valuable to a telecom consultant for example, who could program complex dial plan logic or interactive voice response systems, then simply move the USB key to a production server to deliver the working system.

In reality, the choice of a USB key is a matter of convenience; you could elect to use an internal or external hard drive or even an NFS share. If you are using the generic 586 boot image of Astlinux on CD you could have the server boot to CD and store configs and voice mail on essentially any form of local media.

Figure 4: SSH client logged into the Astlinux server

Figure 4: SSH client logged into the Astlinux server

Once the basic system was up and running with a USB key as local config storage, my next task was to get my existing configs moved from the old server to the Soekris system. As is my habit, I used an SSH client to log into the old system from my Windows desktop. My SSH program of choice (www.privateshell.com) includes SFTP capability, which I used to copy the contents of /etc/asterisk/ to a folder on my PC desktop. I then logged off the old system and logged into the new one, put all the configs into /etc/asterisk/, and rebooted the Soekris system from the command line.

While I use Private Shell, the freeware PUTTY suite of programs provides both SSH and SFTP clients that could also be used in this manner.

Figure 5: SFTP client logged into Astlinux, viewing a file list of /etc/asterisk/

Figure 5: SFTP client logged into Astlinux, viewing a file list of /etc/asterisk/

Many IP phones rely upon some form of central provisioning scheme. The Polycom & Aastra phones that I presently use can be configured to load their firmware and configuration from a local FTP or TFTP server. Happily, Astlinux provided both of these by default, so all I had to do was set the phones to use FTP and give them suitable login credentials. The root directories for these services are also symbolic links to a folder on the USB key drive.

Astlinux also provides an NTP client and server pair. Upon booting, it seeks an Internet NTP server from pool.ntp.org, then provides an NTP service to devices on the local LAN. This is a very convenient way to ensure that all of your phones and call records have matching time and date settings.

This Post Has 8 Comments
  1. […] read around here. The single most popular article is the one I wrote back in January 2006 about Building An Embedded Asterisk Server Using Astlinux On a Soekris Net4801. I would have thought that would have less appeal since it was published elsewhere over two years […]

  2. It’s very interesting for me, do you have any practical use for your home Asterisk server? Why you aren’t using any hosted PBX?

    1. Oh, yes. Between our home lines and my home office needs we put the little Asterisk system to good use. However, this article was originally written in late 2005. Since then I have migrated to using a hosted IP-PBX for most things. I still have a small Asterisk system on-hand as a testbed.

      It may come more into service if ever I complete my home automation project. I’d like to be able to remotely turn things off/on/open/close by way of DTMF as well as other methods, like the LCDs on my Polycom phones.

  3. Hi after days of searching web i found your site really helpful i am from India can you suggest any low cost IVRS solution for our small business i find digium analog cards very expensive is there anyway for analog card IVRS solution please give me a solution

Comments are closed.

Back To Top