Hack95.Build a SoftPBX with No Hard Drive

Hack 95. Build a SoftPBX with No Hard Drive

You don't really need a hard disk to run a phone system; even an IP-based softPBX doesn't need a hard drive. A CompactFlash-based PC will do the trick.

Sometime around September of 2004, I was looking at one of PC Engines' WRAP boards and wondering how well it could run Asterisk. Knowing that I would not want to run a full-size distribution, I started pulling apart a Gentoo install, removing components that are not critical to the functionality of Asterisk. After a fairly significant amount of work, I was left with a slimmed down Gentoo that fit on a 256MB CompactFlash card (which was the smallest that I had at the time) and would run mounted, read-only. After working on the init system and writing some extra scripts, I decided to put it up on my web site just in case someone else found it interesting or useful. I decided to call it AstLinux, version 0.1.0. After about 4,000 downloads, I think that I had my answer, and AstLinux was born!

By 2005, I realized that to make AstLinux truly spectacular, I was going to have to make it smaller and more flexible. Work on AstLinux 0.2.x began. After messing around quite a bit with different build systems and methodologies, I found and stuck with a wonderful combination of crosstool and PTXdist. After some serious time and effort, AstLinux was reborn, and this time it came in at just under 27 MBsmall enough to fit on a 32MB CF card.

This hack will show you how to use AstLinux to create a softPBX system that doesn't require a hard drive. Read the next section to find out the kinds of features you can fit into such a tiny system.

7.9.1. Current Features of AstLinux

As of this writing, AstLinux has the following features:

  • DHCP server/client

  • File transfer protocol (FTP) server

  • TFTP server

  • Asterisk (with zaptel and libpri)

  • Sangoma WANRouter with voice time division multiplexing (TDM) support

  • Web server with HTTPS

  • Administration via console, serial console, SSH, or web graphical user interface (GUI)

  • Network time protocol (NTP) client/server

  • VPN support (IPSEC IKE and OpenVPN)

  • SPI firewall (iptables with my astfw script)

  • Quality of Service (QoS; my AstShape script)

  • NFS client/server

  • Linux 2.6 kernel

  • Caching DNS proxy/server (dnsmasq)

Additionally, AstLinux now runs on everything from the Soekris net4801/ PC Engines WRAP series of Single Board Computers (SBCs) to Dell rack mount gear. Pretty much any modern machine using PC hardware is now supported by the AstLinux i586 image.

7.9.2. AstLinux's Keydisk

One of the more interesting concepts of AstLinux is the use of a single configuration file and the concept of a keydisk. In AstLinux, you can configure almost all of the system (with the exception of Asterisk itself) in one configuration file, /etc/rc.conf./etc/rc.conf is a very simple text file with VARIABLE NAME = VALUE pairs. So, for instance, to set the IP address on the external interface, you would uncomment EXTIP and change it to the desired network address. You will also want to change EXTNM, etc., but I will cover that in more detail later.

Now for the keydisk. This is a perplexing concept to some people, and it can be difficult to explain. Think of it as a personality, similar to a SIM card in a Global System for Mobile (GSM) phone. The partition that AstLinux resides in is purely for AstLinux. No user files or configuration is stored there; this is how it can stay mounted read-only and how the system can still function. Also, it provides a ton of flexibility and allows for some very interesting uses of AstLinux.

When the system first boots, you will see several entries in the GRUB bootloader. They all boot AstLinux; they just pass different arguments to the kernel that the startup scripts then look at to determine what to do. One of these arguments is astkd=. So, for the USB keydisk, astkd should equal /dev/sda1. To use another partition on the system, just fill in the path to that partition.

7.9.3. Hardware Requirements

To use AstLinux, you will need at least the following:

  • A Soekris net4801/PC Engines WRAP board (net4801 image) or any modern PC hardware with a Pentium or better processor

  • A CompactFlash IDE adapter (i586 image)

  • A USB CF adapter (or an IDE adapter)

  • A computer already running Linux or Windows

  • A CompactFlash card of 32 MB or larger (a 256 MB SanDisk is recommended)

  • A PC with two Ethernet devices (one is acceptable, as discussed shortly)

7.9.4. Install from Windows

I have tried very hard to make AstLinux as easy to install and configure as possible. The simplest way to get started is to go to the AstLinux web site at http://www.astlinux.org/ and look for the Downloads section. Once there, you should find the Windows install package, which you will want to download and save to a local disk. Once you run the install package, follow the prompts until it notifies you of a successful installation. Under the Programs group in the Start menu, you should see a new entry called AstLinux, with shortcuts to creating CFs and some documentation.

Attach your USB CF adapter (with CF inserted) and click on the shortcut for the image that you would like to create. A screen will appear, prompting you to select a target disk. This is the harder part of the install, because many people don't know one disk from the other. What I can tell you is that it is usually the last disk listed, but I cannot be sure because all machines are different. One thing to note is that by default, the CF writing utility will refuse to write to disks larger than 800 MB. This will prevent you from accidentally overwriting your hard disk (which should be much larger than 800 MB).

Once you have selected your disk, follow the remaining prompts until you see the progress counter write the entire image and the words "Press any key to continue" appear. You can now safely remove the USB adapter.

Although your fresh, new CF is now ready to be used, I would like you to take a look through the AstLinux User Guide, which is also available from the AstLinux Programs group. Because AstLinux was created from scratch, it bears little resemblance to any existing distributions, and the User Guide attempts to familiarize the user with its features and configuration.

7.9.5. Install from Linux

As stated earlier, go to the Downloads section of http://www.astlinux.org/. Here you should find compressed (gzipped) versions of the AstLinux images. Download the image you would like and save it to a place on your hard drive. Connect your USB CF adapter (with CF inserted), and look in /var/log/messages to see what device it was assigned. If you don't have any other USB or SCSI disks attached to the system, it should be located in /dev/sda. That is what I will assume, but make sure to note whether your CompactFlash card is located in a different device. To verify the location of your CF card, type the following:

 # fdisk -l /dev/sda 

You should see the partition table and drive layout information for your CF card. Now it's time to burn the image. At the command prompt as root, type the following:

 # gunzip -c  /path/to/imagefile.img.gz > /dev/sda  

where /path/to/imagefile.img.gz is where you downloaded the image file to and /dev/sda is where your CF card is located. After the command completes and you are returned to the shell prompt, you can remove your USB CF writer. As with my Windows installs, I highly recommend that you read the AstLinux User Guide. Because you didn't download a package, you should go back to http://www.astlinux.org/ and download the User Guide to familiarize yourself with AstLinux.

7.9.6. Install from CD-ROM

The newest way to install AstLinux is via a more traditional means: an install from CD-ROM. As with the other versions of AstLinux, you can download the install CD-ROM image from the Downloads section of http://www.astlinux.org/. Once you have downloaded the ISO image, you can write it to a CD-ROM under Windows using such tools as Nero. Under Linux, cdrecord (or a graphical frontend such as K3b) works quite well.

Once you have written the ISO image, insert the CD in the drive of your soon-to-be-AstLinux machine. Make sure that the machine is set to boot from CD-ROM, and power on. Once the machine boots, you should see a very simple instruction screen. Typing install and pressing Enter will start the AstLinux installer. It will attempt to detect any hard drives in the system and prompt you as to which one you would like to install to. You should choose your selection carefully, as AstLinux will overwrite any data on that disk!

Actually, the install portion will also detect USB CF writers as hard disks (sda, sdb, sdc, etc.). This way, you can boot the machine from the CD and write to an AstLinux CompactFlash card without ever touching the machine's hard drive! Don't install at all!

While someone who is serious about setting up an AstLinux/Asterisk server would not use this method in production, the same AstLinux CD-ROM image used in the preceding section can also be used as a Live CD. This is actually the default! Once you have created the CD, you simply boot the machine and accept the defaults. Hopefully, in a matter of moments, you will be running AstLinux without having to overwrite your hard drive. And hopefully you will like what you see and decide to run the installer as mentioned earlier in this hack! More about the AstLinux CD-ROM.

The AstLinux CD-ROM also includes a nifty Windows Autorun portion that will give you access to the AstLinux User Guide, a link to the web site, and the tools and utilities provided by the Windows install package. Try it out!

7.9.7. Boot Time

After reading the User Guide, it's time to boot! Insert the CF, make sure that the machine will boot from the CF, and power on! After POST, you should see the GRUB menu with a few options available. For now, it's probably best to select the first entry. By default, AstLinux will attempt to obtain an IP address via DHCP on the first Ethernet interface that it finds, and it will statically configure the second interface with an RFC 1918 private address to do Network Address Translation (NAT). If this is not optimal for your situation, I will show you how to change this once the system boots.

After the usual kernel messages go by, you should finally get to a login prompt; log in with the username root and the password astlinux. Now that you are logged in, it's time to set up your system.

The first thing you are going to want to do is set up your keydisk. As mentioned before, a keydisk is a separate partition or device that AstLinux will use to store your configuration. I am going to assume that you are using a second Flash drive (such as a USB pen drive) for a keydisk and that the USB Flash drive is the Linux device /dev/sda. (When you boot with the CF disk, it is considered an IDE device and should appear on your system as /dev/hdaso, don't think I'm asking you to overwrite your CF disk.) Verify that Linux can see the keydisk by typing the following:

 # fdisk -l /dev/sda 

You should see the partition table for your device. Make sure to take a good, hard look at it, because now is the time to tell you that in a matter of moments, we will be erasing everything on that device! If this is not OK, remove the USB drive and chose another one. If it is OK to lose all of the data on this Flash drive, move on to the next paragraph.

Now that we have those warnings out of the way, let's finally create your keydisk by typing the following:

 # genkd 

The genkd script will take care of finding the device, partitioning it, formatting it, and copying some base configuration files to it. You should see some status information and messages go by, but it should be finished in no time, returning you to the command prompt. If you would like to verify it was successful, type the following:

 # ls /mnt/kd 

You should see a file there called rc.conf. If it's there, you should now type reboot to restart the system and begin using the keydisk. If it's not there, make sure that your device really is /dev/sda, and that it is connected, etc.

Once the system has booted back up, you can start making configuration changes. The /etc/rc.conf file is where you are going to want to begin to look. In an attempt to keep AstLinux small, I've included only the vi text editor, as it was part of the BusyBox collection of utilities I was already using (http://www.busybox.net/). If you're not comfortable editing text files with vi, you can use the web interface. To use the web interface, make sure that you are using a machine on the internal interface of the AstLinux machine (eth1) and that you have obtained a DHCP address from the AstLinux machine. Once you have done this, simply point your web browser to https://pbx (this resolves only if you got your DHCP information from the AstLinux machine, so be sure you are connected to the right interface). You will be prompted for a username (admin) and password (astlinux). Go to General, then Setup, and then "Edit rc.conf." The rc.conf file should open up in a small text edit window inside your browser. Make any necessary configuration changes, including setting the EXTIP family of variables. To apply these changes, simply save the file and reboot the system. In future versions of AstLinux, so many reboots won't be necessary, but for now it is always nice to know that the system will come back up after you have made your changes.

7.9.8. PBX-Only Mode (or Help! I Have Only One Ethernet Interface!)

As noted earlier, you don't really need two Ethernet interfaces. If you don't want to use AstLinux as a router, you need only one interface when you configure AstLinux for PBX-only mode. PBX-only mode will prevent AstLinux from attempting to configure your internal interface (eth1), and it will prevent the startup of certain services that are not necessary (iptables, routing, QoS, DHCP, etc.).

You can configure PBX-only mode by commenting out INTIF= in rc.conf and rebooting. Note that the configuration for EXTIF still applies as usual to your first Ethernet interface, eth0.

7.9.9. Wrap-Up

After the system boots, you should verify IP connectivity. You can do this by using the ping command to attempt to reach a remote system. So, try typing ping www.google.com. You should see ping replies. If you do not, you might be having Internet issues, or you might have to configure a static IP address.

If the ping is successful, you have correctly set up AstLinux! Feel free to log into the system through the console or SSH and take a look around. Explore the web interface, as a lot of neat things are happening there. If you have any questions, you can always go to the AstLinux-Users mailing list at http://lists.kriscompanies.com/. Enjoy!

Kristian Kielhofner

VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net