Category Archives: NetBSD

Dell Server 2.4 Opteron 4GB 2×500 NetBSD



Dell Server 2.4 Opteron 4GB 2×500 NetBSD



Sun Ultra 5


My firts server, NetBSD on it.

NetBSD Wireless Network auto-detection scripts

NetBSD Wireless Network auto-detection scripts 

The configuration:

  1. /etc/rc.conf:
    wpa_supplicant_flags="-B -iath0 -c/root/wpa.conf"
    ifwatchd_flags="-c /root/ifwatch-up -n /root/ifwatch-down tlp0 ath0"


  2. WPA supplicant config: /root/wpa.confHere’s a sample config file for wpa_supplicant(8) that I use for University, home and another place. Note that the WPA in there is a bit more complex than in a home-setup with just a pre-shared key (PSK):
    % cat /root/wpa.conf
    # WPA-enabled network with identities 
    # (used at and
    # An unencrypted (open) network:
    # A WEP-encrypted network with pre-shared key:


  3. Watching interfaces: /root/ifwatch-updownifwatchd(8) can’t pass parameters, so I’m using two different scripts, and then look at $0 to see if we’re going up or down:


    % ls -la /root/ifwatch-*
    lrwxr-xr-x  1 root  wheel   14 Mar 10 12:27 /root/ifwatch-down -> ifwatch-updown
    lrwxr-xr-x  1 root  wheel   14 Mar 10 12:27 /root/ifwatch-up -> ifwatch-updown
    -rwxr-xr-x  1 root  wheel  760 Aug 16 11:45 /root/ifwatch-updown

    Here is the script that handles ethernet and wifi networks going up and down: 

    % cat /root/ifwatch-updown
    # See if network is going up or down, to be called via ifwatchd(8)
    # Copyright (c) 2007 Hubert Feyrer <>
    # All rights reserved.
    case $0 in
            case $1 in
                    # Disable wireless bouncing up and down if we're on wire
                    logger stopping wpa_supplicant
                    sh /etc/rc.d/wpa_supplicant stop
            pkill dhclient
            sh /etc/rc.d/network restart
            dhclient $1
            sh /etc/rc.d/ntpd restart
            case $1 in
                    # Re-enable wireless if we go off-wire
                    logger starting wpa_supplicant
                    sh /etc/rc.d/wpa_supplicant start
            pkill -x ssh
            sh /etc/rc.d/ntpd stop
            pkill dhclient
            sh /etc/rc.d/network stop
            route delete
            logger "$0 $@": unknown 
    logger "$0 $@" done.
    echo ^G >/dev/console

    A few comments:

    • As the comment says, if the ethernet interface (tlp) is found to be connected, wpa_supplicant(8) is stopped to prevent it from bouncing up and down and possibly disrupt things.
    • I stop the network at every time, to flush routes and everything. This mostly works, but not completely, thus I remove one route manually. Someone please fix “route flush”…
    • I use NTP, and to prevent ntpd(8) from spamming the logs when offline, I disable it when offline.
    • When network goes away, I kill my ssh sessions. I prefer this over dead sessions that I have to kill with ~.
    • The echo-command in the last line sends a beep with ^G to give a signal that network’s up/down now.


  4. APM setup:During my experiments, wpa_supplicant(8) died during suspend/resume, I thus stop it before suspending, and start after resuming. This may also have positive effects on power consumption (if not it should probably be hooked in here). My machine uses APM, and I mostly use /usr/share/examples/apm/script, see that file for install instructions.

    Here’s the diff that I use to handle wpa_supplicant – dhclient is restarted via ifwatchd:


    % diff -u /usr/share/examples/apm/script /etc/apm/battery
    --- /usr/share/examples/apm/script      2003-03-11 15:56:54.000000000 +0100
    +++ /etc/apm/battery    2007-03-10 12:57:21.000000000 +0100
    @@ -25,7 +25,7 @@
     # What my network card's recognized as:
     LOGGER='logger -t apm'
    @@ -43,8 +43,11 @@
            # In case some NFS mounts still exist - we don't want them to hang:
            umount -a    -t nfs
            umount -a -f -t nfs
    -       ifconfig $if down
    -       sh /etc/rc.d/dhclient stop
    +       sh /etc/rc.d/wpa_supplicant stop
    +       cd /usr/tmp ; make off
            $LOGGER 'Suspending done.'
    @@ -62,7 +65,9 @@
            $LOGGER 'Resuming...'
            noise $S/KDE_Startup.wav
    -       sh /etc/rc.d/dhclient start
    +       sh /etc/rc.d/wpa_supplicant start
            # mount /home
            # mount /data
            $LOGGER 'Resuming done.'

    The “make off” when shutting down the machine unmounts the cgf-encrypted data partition that I’m using for SSH and PGP keys. I manually mount it when I need it again.


With these four steps — rc.conf, wpa.conf, ifwatch-script, and APM script — things should be in place to auto-detect cable and wifi networks, and get things online.

The future — more work on this would include adding ACPI/powerd(8) scripts, and putting all of this either into the default NetBSD install, or at least into NetBSD’s /usr/share/examples.

Compilar un nuevo kernel en NetBSD

Siempre es mejor compilar nuestro propio kernel (en Linux o *BSD) porque obtendremos uno más esbelto y rápido que el genérico que viene en la instalación. Bien, de manera rápida y sucia esta es la receta:

# cd /

# wget

# tar -zxvf syssrc.tgz

Nos movemos al directorio según la arquitectura, en este caso powerpc porque estoy en un equipo G4, pero si está usando Intel o AMD use i386:

# cd /usr/src/sys/arch/powerpc/conf/


Ahora debemos editar las opciones del kernel. NetBSD no cuenta con algo como “make xconfig”, sino que debemos editar directamente el archivo de texto.

# mcedit MYKERNEL

Si usted ha compilado el kernel de Linux, encontrará familiares muchas de las opciones. (Si desea activar el ACPI, este es el momento de hacerlo ya que no viene por default).

# config MYKERNEL

# cd ../compile/MYKERNEL

# make depend

# make

Renombramos el viejo kernel que está en raíz:

# mv /netbsd /netbsd.ruco

Movemos el nuevo kernel a raíz:

# mv netbsd /

Y ya podemos bootear con nuestro nuevo kernel:

# reboot


thats all thanks to aarkerio











Apache PHP Mysql NetBSD

NAPM Server NetBSD

#cd /usr/pkgsrc/www/apache2

#make install clean

we need for the apache to work to add a hostname>:

#hostname netbsdsparc

and then add Servername into httpd.conf


wherever your ip address is.

then add you ip and host into /etc/hosts/

#echo “ netbsdsparc” >> /etc/hosts

then we can start apache

#apachectl start

#cd /usr/pkgsrc/www/php4/

#make install clean

Now we gonna install the module for php on apache

#cd /usr/pkgsrc/www/ap-php/

#make install clean

now we need to add some lines to the httpd.conf

LoadModule php4_module lib/httpd/
AddHandler application/x-httpd-php .php

You may also add following if you still use .php3 files:

AddHandler application/x-httpd-php .php3

now we gonna install mysql

#cd /usr/pkgsrc/databases/php-mysql

#make install clean

we need to add the extention on to php.ini

#vi /usr/pkg/etc/php.ini

then we add where “Dynamic Extensions” is

#cd /usr/pkgsrc/databases/mysql4-server

#make install clean

mysql will install the mysql-client too at the end you just need
to do:

#cp /usr/pkg/share/examples/rc.d/mysqld /etc/rc.d/

if the file goes as rc.d into /etc/rc.d just rename it to mysqld

then add

#echo “mysqld=YES” >> /etc/rc.conf

and then

/etc/rc.d/mysqld start

Starting MySQL ….

After the tables are set up and the MySQL server is running,
please remember to set a password for the MySQL root user!
This is done by running both:

#/usr/pkg/bin/mysqladmin -u root -p password ‘new-password’
#/usr/pkg/bin/mysqladmin -h `hostname` -u root -p password ‘new-password’

The “Enter password:” prompt is asking for the existing password.
As there is no existing password, just press the Return key.

thats it enjoy it )