Home arrow Latest Tutorials arrow Run a FreeBSD script at boot
Run a FreeBSD script at boot PDF
Wednesday, 18 March 2009

This tutorial shows you howto run a FreeBSD script at boot.
The usual method is to place a script in /usr/local/etc/rc.d, but you must follow some rules (see FreeBSD handbook).

Still, there is a more simple way to run a script when FreeBSD boots.

Let's supose you have root partition on a hard drive and you want to mount partitions from an external USB drive after you've booted. It is not possible to place your USB drive partitions in /etc/fstab, because USB drive is detected after the fstab is parsed and partitions are mounted (at boot time).

So in this case we will do the following:

Step 1. Add the script to /etc/devd.conf
-----------------------------------------
Add the following lines to /etc/devd.conf :

attach 10 {
    match "device-name" "umass0";
    action "/etc/scripts/mount.sh";
};


Step 2. Create the script file that will mount your partitions
------------------------------------------------------------

mkdir /etc/scripts
touch /etc/scripts/mount.sh
chmod +x /etc/scripts/mount.sh

edit /etc/scripts/mount.sh

And in mount.sh add the following lines:

#!/bin/sh
sleep 2
usr/bin/true > /dev/da0
/sbin/mount -t ufs /dev/da0s1d /tmp
/sbin/mount -t ufs /dev/da0s1e /var
/sbin/mount -t ufs /dev/da0s1f /usr
/sbin/swapon /dev/da0s1b

In this example the script will mount partitions /tmp, /var and /usr from USB hard drive and will also add the swap partition from USB drive to your system.
You can place in this script any commands you want to be run after FreeBSD boots.


 
< Prev   Next >

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?