Building a compact Asterisk server with AstLinux

Introduction

"AstLinux has been designed with running from Compact Flash memory in mind. However, it can also be installed to a regular hard drive like other distributions. AstLinux currently occupies around 40mb of disk space, so any Compact Flash card (or hard drive) of 64mb or larger will work perfectly. AstLinux is also the premier Asterisk Live CD. The AstLinux ISO image is very small, yet it includes two AstLinux versions (net4801 and i586), Windows AutoRun support, and of course, el-torrito booting."

Whereabouts

Setup using a pre-compiled image

  1. If using a USB card read, insert the CF card in the reader before connecting it to the USB port
  2. wget
  3. flash the CF card with it: gunzip -c AstLinux-0.4.8-i586.img.gz  > /dev/sdd . This will create a 128MB ext2fs partition /dev/sdd1

    How to install image in existing partition?
     
  4. Boot with the CF card
  5. If using DHCP, make sure the PC got an address. If not, you can log on as root/astlinux, and assign an address manually.
  6. From a remote host, https://astlinux_ip_address, and log on as admin/astlinux (Note: You MUST use HTTPS, not HTTP)
  7. You can also connect to the server with SSH
  8. To check the options used to compile PHP, aim at https://astlinux_ip_address/admin/phpinfo.php

Post-install customizing

For changes to survive a reboot, you must be using AstLinux with UnionFS, or remount the root partition in read-write mode.

Changing mini_httpd's admin password

htpasswd /var/www/admin/.htpasswd admin (CHECK: same as through the web interface General > Setup?)

Changing the root password

Even with UnionFS overlaid on the read-only root partition, I had to make the root partition read-write for passwd to work:

# mount -o remount rw /
# passwd
# mount -o ro,remount /

/etc/ssh/sshd_config

/etc/rc.conf

TIMEZONE=Europe/Paris

TZ_TIMEZONE=CET-1

ZAPMODS

/etc/zaptel.conf

/etc/asterisk/zapata.conf

/etc/asterisk/sip.conf

/etc/asterisk/extension.conf

/etc/profile

alias ll='ls -laF --color=auto'

stty erase ^H

/etc/mini_httpd.conf

#port=443

#ssl

Running cron jobs

Crontab files live in /var/spool/cron/crontabs/ . To edit eg. root's contrab, type "crontab -e root". To list all the cron jobs for this user, type "crontab -l root". /usr/bin/crontab is actually a symlink to /bin/busybox.

Since /var lives in RAM, if you want cron jobs to survive a reboot, create a symlink to the CF card:

  1. /etc/init.d/cron stop
  2. rm -F /var/spool/cron/crontabs
  3. ln -s /stat/var/spool/cron/crontabs /var/spool/cron/crontabs
  4. /etc/init.d/cron start
  5. ps | grep cron
  6. crontab -e root
  7. 0,30 * * * * /tmp/myscript.phpcli
  8. crontab -l root

Setting the NIC to 10BT

# cat /etc/rc.conf
ifconfig_de0="inet 192.168.1.1 netmask 255.255.255.0 media 10baseT/UTP"
 
# /etc/rc.d/netif restart
 
# ifconfig
de0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet 192.168.1.1 netmask 0xffffff00 broadcast 192.168.1.255
        ether 00:80:c8:47:32:a1
        media: Ethernet 10baseT/UTP

To compile one's own version of AstLinux

(source)

Important! When plugged into a USB CF reader, partitions appear as /dev/ssdX, but could be seen as eg. /dev/hdaX in the AstLinux host. Keep this in mind when referencing partitions in configuration files.

You might want to first try to compile using the default options, before adding/removing packages.

  1. Get a fast host, as compiling Astlinux can take a while
  2. yum groupinstall 'Development Tools'
  3. (some might already be installed by the above step) yum install ncurses-devel wget bzip2 zlib-devel rsync unzip subversion flex texinfo nasm bison byacc sox dosfstools
  4. useradd compile
  5. su - compile
  6. svn co https://astlinux.svn.sourceforge.net/svnroot/astlinux/trunk astlinux-trunk
  7. cd astlinux-trunk
  8. cp astlinux.config .config
  9. make oldconfig
  10. make menuconfig: You could do like me, and go into "Package Selection for the target" to remove the following packages: Arno's Firewall Support, Asterisk PRI Support, Asterisk chan_misdn Support, Asterisk Application Bundle - mISDN, mISDN, iftop, ipsec-tools, iptables, madwifi, netsnmp, openvpn, rhino, tcpdump, wanpipe, wireless tools, oslec. Add SQLite!

    If you remove all ISDN-related packages, you must also remove one line in package/asterisk/asterisk.mk: "--with-pri=$(STAGING_DIR)/usr \"

    If you add sqlite, you'll have to edit package/sqlite/sqlite.mk so it matches the version of the source code available on the site

    If you want to enable SQLite for PHP, edit
    less package/php5/php5.mk, and change the adhoc line to say "--with-sqlite". If you already have the latest and greatest version compiled, you can tell PHP to use that external library with "--with-sqlite=/usr/lib/libsqlite3.so.0"

    Samba
     
  11. make

Note:

If you need to start again

  1. cd astlinux-trunk
  2. make clean
  3. rm -Rf toolchain_build_i586
  4. rm -Rf build_i586
  5. (Up to you: If you modified some of the .mk files) rm -Rf package
  6. rm astlinux-trunk-*
  7. rm -Rf astlinux-trunk-*
  8. svn update
  9. cp astlinux.config .config
  10. make oldconfig
  11. make menuconfig
  12. make

Installing the new build on a CF card

  1. Use fdisk /dev/sdd to delete any existing partition
  2. Create a new, 128MB FAT16 filesystem. This new boot partition will contain the runnix bootloader and the Astlinux image(s)
  3. fdisk -l : Verify that your filesystem Id is 6 and the System is FAT16 and that the first partition is bootable.
  4. Format the partition with mkdosfs -F 16 /dev/sdd1 (yes, it only takes a split second)
  5. Download Runnix. Extract the files into a temporary location on your development system's hard drive
  6. cd runnix-<version> ; ./syslinux /dev/sdd1 ; cat mbr.bin > /dev/sdd
  7. Mount the CF card: mkdir /mnt/cf ; mount /dev/sdd1 /mnt/cf
  8. Copy the runnix files to the CF drive: cp -R rootfs_vfat/* /mnt/cf
  9. You might need to edit /os/default.conf and /syslinux.cf
  10. At a minimum you'll need an <image>.run file and the associated <image>.run.sha1 file which will be used to validate the image: cd astlinux-trunk/astlinux-trunk-XXX ; cp * /mnt/cf/os.

    For now, edit KCMD line in the .run.conf to remove references to astkd and asturw (see later)
     
  11. Take a look : ls -alh /mnt/cf . runnix is the kernel, runnix.img is the initrd file, syslinux.cfg defines how runnix starts, and /os is the directory where your target operating system images go
  12. Boot with the CF card, and aim at https://astlinux_ip/

Important: Change the default password to root, and to the web server's admin as well!

Updating AstLinux on the CF card

  1. mount /dev/sdd1 /mnt/cf
  2. (optional, to save space) rm /mnt/cf/os/astlinux-trunk-XXX* (previous version)
  3. cd astlinux-trunk/astlinux-trunk-XXX
  4. vi astlinux-trunk-1566.run.conf (remove astkd, add asturw)
  5. cp * /mnt/cf/os
  6. umount /mnt/cf
  7. Boot with the CF card, and aim at https://astlinux_ip/

Making configuration sticky

By default, AstLinux is read-only, with some parts of it read-write because they're pointing to a filesystem in RAM. This is organized through /etc/fstab.

It's fine to have /tmp and /var pointing to RAM, but you probably want to edit files in /etc/, and have those changes survive a reboot. Incidently, /etc/rc.conf has the Zaptel interface commentend out by default, which means that it doesn't get loaded at boot time.

To achieve this, you can tell AstLinux to use UnionFS, so that you have read-write access to the whole root filesystem:

  1. Boot AstLinux
  2. If not already done, use fdisk to create a second partition on the Compact Flash on eg. /dev/hda2. To be safe, reboot.
  3. mkfs.ext2 /dev/hda2
  4. e2fsck /dev/hda2
  5. mount -o,remount rw /oldroot/cdrom
  6. vi /oldroot/cdrom/os/astlinux-trunk-XXX.run.conf:

    KCMD="root=/dev/ram0 rw init=/linuxrc astlinux=geni586 astimg=astlinux-trunk-1540.run astkd=/dev/sda1 asturw=/dev/hda2 astlive ide=nodma"
  7. rm /etc/rc.conf ; cp /tmp/etc/rc.conf /etc ; vi /etc/rc.conf
  8. rm /etc/zaptel.conf ; cp /tmp/etc/zaptel.conf /etc ; vi /etc/zaptel.conf
  9. rm /etc/asterisk; mkdir /etc/asterisk; (why?) cp /tmp/etc/asterisk/* /etc/asterisk/
  10. Reboot

Now, changes made to /etc/ should be sticky because they're actually made to /dev/hda2. Generally speaking, in case you modified a file, the version in the AstUrw (/oldroot/mnt/asturw/) will take precedence. If you want to delete this file and have AstLinux use the read-only version, remove the file from /oldroot/mnt/asturw/.

Creating a new partition on the CF card

  1. mount -o rw,remount /
  2. fdisk /dev/hda : Type n, p, <partition number, eg. 2>, <size of partition>, p, w
  3. fdisk -l /dev/hda
  4. mkfs.ext2 /dev/hda2
  5. reboot
  6. mkdir /mnt/new_part
  7. mount -o noatime /dev/hda2 /mnt/new_part/

Adding your own PHP pages to mini_httpd

If you chose mini_httpd instead of lighttpd, to add your very own PHP scripts, make the root partition read-write if it isn't already by using UnionFS, add the pages, make them executable, and make sure the file is owned by ??.??:

  1. cd /var/www
  2. vi test.php
  3. chmod a+x test.php
  4. https://astlinux/test.php

Compiling the Python APSW thin SQLite3 wrapper

On a CentOS host:

  1. run yum install python python-devel
  2. wget http://initd.org/pub/software/pysqlite/apsw/3.3.13-r1/apsw-3.3.13-r1.zip
  3. unzip apsw-3.3.13-r1.zip  ; cd apsw-3.3.13-r1
  4. wget http://www.sqlite.org/sqlite-3.5.4.tar.gz
  5. tar xzvf sqlite-3.5.4.tar.gz
  6. mv sqlite-3.5.4 sqlite3
  7. cd sqlite3
  8. env CC="gcc -fPIC" CFLAGS="-DHAVE_DLOPEN" ./configure --enable-threadsafe --disable-tcl
  9. make
  10. cp .libs/*.a .
  11. cd ..
  12. python setup.py install
  13. cp /usr/lib/python2.4/site-packages/apsw.so /srv/www/lighttpd/

From the AstLinux host:

  1. cd /usr/lib/python2.4/site-packages
  2. wget http://www.acme.com/apsw.so
  3. # python
  4. Python 2.4.2 (#1, Jan 26 2008, 17:41:42)
  5. [GCC 4.1.2] on linux2
  6. Type "help", "copyright", "credits" or "license" for more information.
  7. >>> import apsw
  8. libc.so.6: aborted attempt to load python!

Questions

  1. When starting Asterisk myself through either safe_asterisk or asterisk&, why does ps show several Asterisk processes listed as "asterisk -p -I"?
  2. Web server says "This server's current IP address is 192.168.0.1" : 0.1 was the PC from which I SSHed, but AstLinux is 192.168.0.4!
  3. How to use the FR keyboard? Does AstLinux support other keyboard layouts besides US English? How would I change it, and make it sticky so I don't have to rerun the command with every reboot?
  4. Even after editing /os/astlinux-trunk-1540.run.conf, I still get "Something else is wrong with /dev/sdd2. Run e2fsck" when booting up:

    KCMD="root=/dev/ram0 rw init=/linuxrc astlinux=geni586 astimg=astlinux-trunk-1540.run astkd=/dev/sdd2 astlive ide=nodma"
  5. Test alternatives Lighttpd and appweb
  6. When booting up, AstLinux says "Something else is wrong with /dev/sdd2. Run e2fsch", although running it makes no difference at the next reboot.
  7. Why doesn't "CTRL-C" work in sqlite3, either from Putty or SecureCRT? Why do arrows show eg. "^[[A"?

    # stty intr '^C' erase '^H'

    CTRL-C doesn't work to cancel the current command
    CTRL-D exits
    BACKSPACE works
  8. In "less", up/down arrows don't work. "/" to search for a word doesn't work either (check that it's the right way to search for words, like in vi)
  9. How to correct the way SH mishandles BACKSPACE, DEL, and direction arrows?
  10. Why two configuration files for mini_httpd? /etc/mini_httpd-http.conf and /etc/mini_httpd.conf

Resources