Adding additional ip addresses in FreeBSD – Alternate methods

Traditional way of adding additional ip address in FreeBSD has been to add entries in /etc/rc.conf:

ifconfig_em0_alias0="inet netmask"
ifconfig_em0_alias1="inet netmask"
ifconfig_em0_alias2="inet netmask"
ifconfig_em0_alias3="inet netmask"

This works nicely, but the problem lies in the fact that if you miss the numbering in alias, subsequent aliases will not be read by the system. So a listing like

ifconfig_em0_alias0="inet netmask"
ifconfig_em0_alias1="inet netmask"
ifconfig_em0_alias3="inet netmask"

will lead to the last alias ‘’ to be not read/set by the OS. There exists an alternate way to set up additional ip address which does not include numbering of aliases. All you need to do is create a file /etc/start_if.<interface>, where <interface> is the name of the network interface you want to bind the aliases to. So for example you have an interface em0, the file that needs to be created is /etc/start_if.em0. This file is a shell script (bourne shell) file where you can call the ifconfig command to add the aliases to your nic. An example file could be:

/sbin/ifconfig em0 alias netmask
/sbin/ifconfig em0 alias netmask
/sbin/ifconfig em0 alias netmask
/sbin/ifconfig em0 alias netmask

Since this is a standard shell script, you will be able to all sorts of scripting inside (Not tested though, apart from placing comments using # sign). This allows for better administration and scripting for aliases.

There exists another way to set aliases, though I haven’t tested them myself. This goes into /etc/rc.conf file and lets you easily add groups of ip address at a time:


Large file upload with PHP and NGINX

When trying to upload large files with PHP in an environment which also includes nginx, apart from the php.ini directives of ‘upload_max_filesize’ and ‘post_max_size’, you also need to increase the value of ‘client_max_body_size’ in nginx.conf . See this link for explanation:

If you are still facing problems, it might be related to max execution time variables which are present across php.ini, php-fpm.conf and nginx.conf. This page has couple of them listed out:


Partition automation in bsdinstall auto script in FreeBSD

[This post is part of the bsdinstall automation series. It should be read with the main article posted @]

These lines should go out in the bsdinstall auto file, after commenting out bsdinstall autopart and bsdinstall mount section. Remember, this would wipe out the entire disk contents without any warning, so use it at your own risk. I am also assuming that if you have multiple disks connected, the first disk is what you want to install your OS on. Otherwise, you might have to modify the script accordingly.

Get the disk layout, and the first disk connected to the system
# disk_layout=`sysctl -n kern.disks`
# first_disk=${disk_layout%% *}

Destroy any existing partition, and then create a gpt partition
# gpart destroy -F $first_disk
# gpart create -s gpt $first_disk

Create a boot partition to hold the loader, size of 512K. Give it a GPT label of gpboot, which will show up in /dev/gpt when the device is discovered:
# gpart add -t freebsd-boot -l gpboot -b 40 -s 512K $first_disk

Install the GPT bootcode into the boot partition:
# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 $first_disk

Create a swap parition
# gpart add -t freebsd-swap -l gpswap -s 4G $first_disk

Create a partition for /. It should start at the 1M boundary for proper sector alignment on 4K sector drives or SSDs. This is compatible with GPT drive layout for many other systems. Give it a GPT label of gprootfs.
# gpart add -t freebsd-ufs -l gprootfs -a 1M $first_disk

Format the root partition
# newfs -U /dev/gpt/gprootfs

Mount the partition at /mnt
# mount /dev/gpt/gprootfs /mnt

Add entry to fstab ($PATH_FSTAB)
# echo '# Device Mountpoint FStype Options Dump Pass#' > $PATH_FSTAB
# echo '/dev/gpt/gpswap none swap sw 0 0' >> $PATH_FSTAB
# echo '/dev/gpt/gprootfs / ufs rw 1 1' >> $PATH_FSTAB

(1) Although the post is meant as part of automating bsdinstall, the concept could be used to create partitions over a new disk with appropriate safeguards

Integrating Notepad++ with Sliksvn

I have recently started to use Notepad++ as my primary code editor. For source code management, I use SVN. There are lots of extensions available for integrating TortoiseSVN with Notepad++, but none available for SlikSVN. However, using NPPExec (install it through Plugins->Plugin Manager->Show Plugin Manager) extension, it’s pretty easy to integrate SlikSVN command line svn tool with Notepad++.

* Open Notepad++
* Press F6 to open the execute window
* Type the following commands:
o c:program filessliksvnbinsvn.exe -m ” commit
* Click on Save
* Type a name, ‘SVN Commit’, to save the script
* Go to Menu Plugins -> Nppexec -> Advanced Options -> Menu Item
* In the combobox select the script recently created, select a menu name, ‘SVN Commit’, and click ok
* Go to Menu Settings -> Shortcut mapper -> Plugins -> search for the script name
* Select the shortcut to use , Ctrl + Alt + 1 , click ok

For update command, use the same process, just replace the commit command with update while creating the script file, different menu name and a seperate kyeboard shortcut.


64 bit guests in Virtualbox on Ubuntu 11.10 host

If you are interested in installing 64 bit guests within virtualbox host running on Ubuntu (11.10), you will have to add the extension pack for the same version before Virtualbox enables the 64 bit guest versions.

To install virtualbox, use the files from virtualbox site itself, as they contain the latest upgrades and bug fixes. The code below installs the latest in 4.1 series, change for whatever is the current version.

sudo sh -c "echo 'deb '$(lsb_release -cs)' contrib non-free' > /etc/apt/sources.list.d/virtualbox.list" && wget -q -O- | sudo apt-key add - && sudo apt-get update && sudo apt-get install virtualbox-4.1 dkms

Now dowload the extpak for virtualbox. The exact file to be downloaded can be known from the download link.


Install the extpak

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.1.12-77245.vbox-extpack

This should do the trick.


Installing Asterisk with DAHDI in FreeBSD 9

If you are installing Asterisk(/usr/ports/net/asterisk) with DAHDI(/usr/ports/misc/dahdi) support in FreeBSD, make sure you have FreeBSD src installed in /usr/src, as that is required to compile DAHDI port . This is as of 06th April, 2012 .

[Update] Dahdi port now correctly refuses to build if source is not found in /usr/src

Adding new disk in FreeBSD

Check if the disks are being detected. There are multiple ways to do it, but the most simplest is to check a sysctl variable.
# sysctl kern.disks

Disk types are displayed in the following format: SAS & SCSI are designated “da” while IDE & SATA (including SSD) drives are “ada“. Disk types are followed by numbers, i.e. da0, ada0, ada1 etc. To check which disks are being used currently, use “df -h” command. It should list out all the currently used disks.

Once you have determined which disk you need to attach, use the following commands. The examples below assume the disk to be configured is at ada1. Change it as per your configuration.
Re-initialize the disk with all zero’s
# dd if=/dev/zero of=/dev/ada1 bs=1k count=2
Label the disk. If you use auto parameter, the disk would be labeled from a, i.e. ada1a
# bsdlabel -Bw ada1 auto
Format the new parition
# newfs /dev/ada1a
Create the directory where you would like to mount the new disk / partition
# mkdir -p /usr/local/disk2
To mount the disk temporarily
# mount /dev/ada1a /usr/local/disk2

For auto mounting the disk across reboot, make the following entries in your “/etc/fstab” file
/dev/ada1a /usr/local/disk2 ufs rw 2 2

Keep in mind that these disks will not be readable by any other os’s (Windows). To make the disks compatible with other os, you need to create a slice before labeling it. Also, the above code has been tested in FreeBSD 9.0, earlier versions might differ in commands or outputs.

Scripting bsdinstall in FreeBSD 9.0 for custom installation CD

Starting with FreeBSD 9.0, the default installer for FreeBSD has changed from sysinstall to bsdinstall. While there has been mixed reactions from old time users, the process of creating a custom install CD for FreeBSD has become a lot easier (although longer). bsdinstall uses a set of shell scripts which can be modified as per requirements.

First step is to install a fresh 9.0 RELEASE, and select the src to be installed along with the base system. Once the system with source is installed (by default /usr/src) execute the following commands

# cd /usr/src
# make buildworld buildkernel

Installation scripts are located at /usr/src/usr.sbin/bsdinstall/scripts/ . First file to run is ‘auto’, which then calls other files. Almost all of them are shell scripts. Remember, you do not need to repeat ‘make buildworld buildkernel’ if you are just making changes to the install script file.

# cd /usr/src/release
# make release

Once the release has been built we now copy the iso / usb image / ftp files to the desired directory

# make install DESTDIR=/usr/freebsd-snapshot clean

This creates the iso file, memory stick image and ftp folder for ftp install. In case you are wondering how to use the memory stick image, see this blog post: